[Rt-commit] rt branch, 4.4/extend-execmodule-support, created. rt-4.2.3-203-gebb3c91

Wallace Reis wreis at bestpractical.com
Wed Jul 2 13:32:40 EDT 2014


The branch, 4.4/extend-execmodule-support has been created
        at  ebb3c9143cfbdcd51c26a5544c863f8feebd9e17 (commit)

- Log -----------------------------------------------------------------
commit ebb3c9143cfbdcd51c26a5544c863f8feebd9e17
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Wed May 21 17:23:31 2014 -0300

    Allow deep namespaces for ScripActions and Conditions
    
    When naming a ScripAction or ScripCondition package, we could just
    use simple string names as ExecModule. This aims to provide support
    for being more flexible about the package names.

diff --git a/lib/RT/ScripAction.pm b/lib/RT/ScripAction.pm
index feb1b2c..063ddd6 100644
--- a/lib/RT/ScripAction.pm
+++ b/lib/RT/ScripAction.pm
@@ -63,6 +63,7 @@ package RT::ScripAction;
 
 use strict;
 use warnings;
+use UNIVERSAL::require;
 
 use base 'RT::Record';
 
@@ -166,11 +167,9 @@ sub LoadAction  {
         $self->{'TemplateObj'} = $args{'TemplateObj'};
     }
 
-    $self->ExecModule =~ /^(\w+)$/;
-    my $module = $1;
-    my $type = "RT::Action::". $module;
-
-    eval "require $type" || die "Require of $type failed.\n$@\n";
+    my $module = $self->ExecModule;
+    my $type = 'RT::Action::' . $module;
+    $type->require or die "Could not find Action class: $@";
 
     return $self->{'Action'} = $type->new(
         %args,
diff --git a/lib/RT/ScripCondition.pm b/lib/RT/ScripCondition.pm
index 8a59c1f..5bb6173 100644
--- a/lib/RT/ScripCondition.pm
+++ b/lib/RT/ScripCondition.pm
@@ -71,13 +71,12 @@ package RT::ScripCondition;
 
 use strict;
 use warnings;
-
+use UNIVERSAL::require;
 
 use base 'RT::Record';
 
 sub Table {'ScripConditions'}
 
-
 sub _Accessible  {
     my $self = shift;
     my %Cols = ( Name  => 'read',
@@ -156,21 +155,19 @@ sub LoadCondition  {
                  TicketObj => undef,
                  @_ );
 
-    #TODO: Put this in an eval
-    $self->ExecModule =~ /^(\w+)$/;
-    my $module = $1;
-    my $type = "RT::Condition::". $module;
-
-    eval "require $type" || die "Require of $type failed.\n$@\n";
-
-    $self->{'Condition'}  = $type->new ( 'ScripConditionObj' => $self,
-                                         'TicketObj' => $args{'TicketObj'},
-                                         'ScripObj' => $args{'ScripObj'},
-                                         'TransactionObj' => $args{'TransactionObj'},
-                                         'Argument' => $self->Argument,
-                                         'ApplicableTransTypes' => $self->ApplicableTransTypes,
-                                         CurrentUser => $self->CurrentUser
-                                       );
+    my $module = $self->ExecModule;
+    my $type = 'RT::Condition::' . $module;
+    $type->require or die "Could not find Condition class: $@";
+
+    return $self->{'Condition'} = $type->new(
+        ScripConditionObj => $self,
+        TicketObj => $args{'TicketObj'},
+        ScripObj => $args{'ScripObj'},
+        TransactionObj => $args{'TransactionObj'},
+        Argument => $self->Argument,
+        ApplicableTransTypes => $self->ApplicableTransTypes,
+        CurrentUser => $self->CurrentUser
+    );
 }
 
 
diff --git a/t/api/scrip_execmodule.t b/t/api/scrip_execmodule.t
new file mode 100644
index 0000000..37b10d4
--- /dev/null
+++ b/t/api/scrip_execmodule.t
@@ -0,0 +1,44 @@
+use strict;
+use warnings;
+use RT::Test plugins => [qw(RT::Extension::ScripExecModule)];
+
+my $system_user = RT->SystemUser;
+
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    my $action = RT::ScripAction->new($system_user);
+    my ( $val, $msg) = $action->Create(
+        Name => 'TestExecModuleAction',
+        Description => '',
+        ExecModule => 'Foo::Bar',
+    );
+    ok($val, $msg);
+
+    my $condition = RT::ScripCondition->new($system_user);
+    ( $val, $msg ) = $condition->Create(
+        Name => 'TestExecModuleCondition',
+        Description => '',
+        ApplicableTransTypes => 'Create',
+        ExecModule => 'Foo::Bar',
+    );
+    ok($val, $msg);
+ 
+    my $scrip = RT::Scrip->new($system_user);
+    ($val, $msg) = $scrip->Create(
+        Queue => $queue->Id,
+        ScripAction => 'TestExecModuleAction',
+        ScripCondition => 'TestExecModuleCondition',
+        Template => 'Blank'
+    );
+    ok($val,$msg);
+
+    my $ticket = RT::Ticket->new($system_user);
+    my ( $tid, $trans_id, $tmsg ) = $ticket->Create(
+        Subject => 'Sample workflow test',
+        Owner => 'root',
+        Queue => $queue->Id
+    );
+    ok($tid, $tmsg);
+}
diff --git a/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Action/Foo/Bar.pm b/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Action/Foo/Bar.pm
new file mode 100644
index 0000000..10349a8
--- /dev/null
+++ b/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Action/Foo/Bar.pm
@@ -0,0 +1,11 @@
+package RT::Action::Foo::Bar;
+
+use strict;
+use warnings;
+use base 'RT::Action';
+
+sub Prepare { return 1 }
+
+sub Commit { return 1 }
+
+1;
diff --git a/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Condition/Foo/Bar.pm b/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Condition/Foo/Bar.pm
new file mode 100644
index 0000000..eadcf92
--- /dev/null
+++ b/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Condition/Foo/Bar.pm
@@ -0,0 +1,9 @@
+package RT::Condition::Foo::Bar;
+
+use strict;
+use warnings;
+use base 'RT::Condition';
+
+sub IsApplicable { return 1 }
+
+1;
diff --git a/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Extension/ScripExecModule.pm b/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Extension/ScripExecModule.pm
new file mode 100644
index 0000000..4ccfbec
--- /dev/null
+++ b/t/data/plugins/RT-Extension-ScripExecModule/lib/RT/Extension/ScripExecModule.pm
@@ -0,0 +1,3 @@
+package RT::Extension::ScripExecModule;
+
+1;

-----------------------------------------------------------------------


More information about the rt-commit mailing list