Convert PassiveAnalytics over to Moose.

This commit is contained in:
Colin Kuskie 2010-11-10 10:05:07 -08:00
parent 882317c2c9
commit 9832f38a93
4 changed files with 27 additions and 60 deletions

View file

@ -269,7 +269,7 @@ sub www_editRule {
else {
##We need a temporary rule so that we can call dynamicForm, below
$ruleId = 'new';
$rule = WebGUI::PassiveAnalytics::Rule->create($session, {});
$rule = WebGUI::PassiveAnalytics::Rule->new($session, {});
}
##Build the form
@ -315,7 +315,7 @@ sub www_editRuleSave {
my $ruleId = $form->get('ruleId');
my $rule;
if ($ruleId eq 'new') {
$rule = WebGUI::PassiveAnalytics::Rule->create($session, {});
$rule = WebGUI::PassiveAnalytics::Rule->new($session, {});
}
else {
$rule = WebGUI::PassiveAnalytics::Rule->new($session, $ruleId);

View file

@ -1,6 +1,26 @@
package WebGUI::PassiveAnalytics::Rule;
use base qw/WebGUI::Crud/;
use Moose;
use WebGUI::Definition::Crud;
extends qw/WebGUI::Crud/;
define tableName => 'analyticRule';
define tableKey => 'ruleId';
has ruleId => (
required => 1,
is => 'ro',
);
property bucketName => (
fieldType => 'text',
label => ['Bucket Name','PassiveAnalytics'],
hoverHelp => ['Bucket Name help','PassiveAnalytics'],
default => '',
);
property regexp => (
fieldType => 'text',
label => ['regexp','PassiveAnalytics'],
hoverHelp => ['regexp help','PassiveAnalytics'],
default => '.+',
);
use WebGUI::International;
=head1 NAME
@ -19,59 +39,6 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 crud_definition ( )
WebGUI::Crud definition for this class.
=head3 tableName
analyticRule.
=head3 tableKey
ruleId
=head3 sequenceKey
None. There is only 1 sequence of rules for a site.
=head3 properties
=head4 bucketName
The name of a bucket to hold results for this rule.
=head4 regular expression.
A regular expression to match against log entries.
=cut
sub crud_definition {
my ($class, $session) = @_;
my $definition = $class->SUPER::crud_definition($session);
$definition->{tableName} = 'analyticRule';
$definition->{tableKey} = 'ruleId';
$definition->{sequenceKey} = '';
my $properties = $definition->{properties};
my $i18n = WebGUI::International->new($session);
$properties->{bucketName} = {
fieldType => 'text',
label => $i18n->get('Bucket Name','PassiveAnalytics'),
hoverHelp => $i18n->get('Bucket Name help','PassiveAnalytics'),
defaultValue => '',
};
$properties->{regexp} = {
fieldType => 'text',
label => $i18n->get('regexp','PassiveAnalytics'),
hoverHelp => $i18n->get('regexp help','PassiveAnalytics'),
defaultValue => '.+',
};
return $definition;
}
#-------------------------------------------------------------------
=head2 matchesBucket ( $logLine )
Executes the rule to determine if a log file entry matches the rule.
@ -84,7 +51,7 @@ A hashref of information from 1 line of the logs.
sub matchesBucket {
my ($self, $logLine) = @_;
my $regexp = $self->get('regexp');
my $regexp = $self->regexp;
return $logLine->{url} =~ m/$regexp/;
}

View file

@ -72,8 +72,8 @@ sub execute {
my @rules = ();
my $getARule = WebGUI::PassiveAnalytics::Rule->getAllIterator($session);
while (my $rule = $getARule->()) {
my $regexp = $rule->get('regexp');
push @rules, [ $rule->get('bucketName'), qr/$regexp/];
my $regexp = $rule->regexp;
push @rules, [ $rule->bucketName, qr/$regexp/];
}
##Get the index stored from the last invocation of the Activity. If this is

View file

@ -59,7 +59,7 @@ my @ruleSets = (
my @url2 = @ruleSets;
while (my $spec = shift @url2) {
my ($bucket, undef, $regexp) = @{ $spec };
WebGUI::PassiveAnalytics::Rule->create($session, { bucketName => $bucket, regexp => $regexp });
WebGUI::PassiveAnalytics::Rule->new($session, { bucketName => $bucket, regexp => $regexp });
}
my @urls = map {$_->[1]} @ruleSets;