[Rt-commit] rt branch, 4.4/extend-execmodule-support, created. rt-4.2.3-203-g4151d8d
Wallace Reis
wreis at bestpractical.com
Wed May 28 11:51:11 EDT 2014
The branch, 4.4/extend-execmodule-support has been created
at 4151d8da76bdc6bee37c907cbca132dd375bb26f (commit)
- Log -----------------------------------------------------------------
commit 4151d8da76bdc6bee37c907cbca132dd375bb26f
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..1111edc 100644
--- a/lib/RT/ScripAction.pm
+++ b/lib/RT/ScripAction.pm
@@ -63,6 +63,7 @@ package RT::ScripAction;
use strict;
use warnings;
+use Module::Runtime 'use_module';
use base 'RT::Record';
@@ -166,13 +167,10 @@ sub LoadAction {
$self->{'TemplateObj'} = $args{'TemplateObj'};
}
- $self->ExecModule =~ /^(\w+)$/;
- my $module = $1;
- my $type = "RT::Action::". $module;
+ my $module = $self->ExecModule;
+ my $type = 'RT::Action::' . $module;
- eval "require $type" || die "Require of $type failed.\n$@\n";
-
- return $self->{'Action'} = $type->new(
+ return $self->{'Action'} = use_module($type)->new(
%args,
Argument => $self->Argument,
CurrentUser => $self->CurrentUser,
diff --git a/lib/RT/ScripCondition.pm b/lib/RT/ScripCondition.pm
index 8a59c1f..6096613 100644
--- a/lib/RT/ScripCondition.pm
+++ b/lib/RT/ScripCondition.pm
@@ -71,13 +71,12 @@ package RT::ScripCondition;
use strict;
use warnings;
-
+use Module::Runtime 'use_module';
use base 'RT::Record';
sub Table {'ScripConditions'}
-
sub _Accessible {
my $self = shift;
my %Cols = ( Name => 'read',
@@ -156,21 +155,18 @@ 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;
+
+ return $self->{'Condition'} = use_module($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/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 6b4fd23..5331254 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -236,6 +236,7 @@ Mail::Header 2.12
Mail::Mailer 1.57
MIME::Entity 5.504
Module::Refresh 0.03
+Module::Runtime
Module::Versions::Report 1.05
Net::CIDR
Plack 1.0002
diff --git a/t/api/scrip_execmodule.t b/t/api/scrip_execmodule.t
new file mode 100644
index 0000000..ed51c2d
--- /dev/null
+++ b/t/api/scrip_execmodule.t
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+use RT::Test;
+use lib 't/data/plugins/RT-Extension-ScripExecModule/lib';
+
+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