From 9832f38a936abe57439b52a52f1b4d793d082956 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 10 Nov 2010 10:05:07 -0800 Subject: [PATCH] Convert PassiveAnalytics over to Moose. --- lib/WebGUI/PassiveAnalytics/Flow.pm | 4 +- lib/WebGUI/PassiveAnalytics/Rule.pm | 77 ++++++------------- .../Activity/BucketPassiveAnalytics.pm | 4 +- t/Workflow/Activity/BucketPassiveAnalytics.t | 2 +- 4 files changed, 27 insertions(+), 60 deletions(-) diff --git a/lib/WebGUI/PassiveAnalytics/Flow.pm b/lib/WebGUI/PassiveAnalytics/Flow.pm index 8662de29f..5821c285e 100644 --- a/lib/WebGUI/PassiveAnalytics/Flow.pm +++ b/lib/WebGUI/PassiveAnalytics/Flow.pm @@ -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); diff --git a/lib/WebGUI/PassiveAnalytics/Rule.pm b/lib/WebGUI/PassiveAnalytics/Rule.pm index d359b34ba..3145ff873 100644 --- a/lib/WebGUI/PassiveAnalytics/Rule.pm +++ b/lib/WebGUI/PassiveAnalytics/Rule.pm @@ -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/; } diff --git a/lib/WebGUI/Workflow/Activity/BucketPassiveAnalytics.pm b/lib/WebGUI/Workflow/Activity/BucketPassiveAnalytics.pm index 0bea4a932..afedb6a13 100644 --- a/lib/WebGUI/Workflow/Activity/BucketPassiveAnalytics.pm +++ b/lib/WebGUI/Workflow/Activity/BucketPassiveAnalytics.pm @@ -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 diff --git a/t/Workflow/Activity/BucketPassiveAnalytics.t b/t/Workflow/Activity/BucketPassiveAnalytics.t index d33151304..c2d32b20c 100644 --- a/t/Workflow/Activity/BucketPassiveAnalytics.t +++ b/t/Workflow/Activity/BucketPassiveAnalytics.t @@ -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;