[Rt-commit] r18450 - rt/3.999/branches/lorzy/lib/RT
clkao at bestpractical.com
clkao at bestpractical.com
Wed Feb 18 12:01:30 EST 2009
Author: clkao
Date: Wed Feb 18 12:01:30 2009
New Revision: 18450
Modified:
rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm
rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
Log:
helper for create scripish lorzy rule.
Modified: rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Bootstrap.pm Wed Feb 18 12:01:30 2009
@@ -460,36 +460,14 @@
# XXX: put into RT::Model::Rules
require RT::Lorzy;
require Lorzy::Builder;
- my $sigs = { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
- transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) };
- my $builder = Lorzy::Builder->new();
- for my $item (@Scrips) {
- my $condition = $builder->defun(
- ops => [{ name => 'RT.Condition.Applicable',
- args => {
- name => $item->{scrip_condition},
- ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
- transaction => { name => 'Symbol', args => { symbol => 'transaction' } }
- } }
- ],
- signature => $sigs,
-
+ for my $item (sort { $a->{description} cmp $b->{description} } @Scrips) {
+ my $rule = RT::Lorzy->create_scripish(
+ $item->{scrip_condition},
+ $item->{scrip_action},
+ $item->{template},
);
- my $action = $builder->defun(
- ops => [ { name => 'RT.ScripAction.Run',
- args => {
- name => $item->{scrip_action},
- template => $item->{template},
- ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
- transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
- } } ],
- signature => $sigs);
-
- RT::Lorzy::Dispatcher->add_rule(
- RT::Lorzy::Rule->new( { condition => $condition,
- action => $action } )
- );
+ RT::Lorzy::Dispatcher->add_rule( $rule );
}
}
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy.pm Wed Feb 18 12:01:30 2009
@@ -16,6 +16,59 @@
return $ret;
}
+sub create_scripish {
+ my ( $class, $scrip_condition, $scrip_action, $template, $queue ) = @_;
+ my $sigs = { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+ transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) };
+ my $builder = Lorzy::Builder->new();
+
+ my $tree = {
+ name => 'RT.Condition.Applicable',
+ args => {
+ name => $scrip_condition,
+ ticket => { name => 'Symbol', args => { symbol => 'ticket' } },
+ transaction => { name => 'Symbol', args => { symbol => 'transaction' } }
+ } };
+
+ if ($queue) {
+
+ $tree = { name => 'And',
+ args => { nodes =>
+ [ { name => 'Str.Eq',
+ args => {
+ arg1 => $queue,
+ arg2 => { name => 'Native.Invoke',
+ args => { obj => { name => 'Native.Invoke',
+ args => { obj => { name => 'Symbol', args => { symbol => 'ticket' }},
+ method => 'queue',
+ args => { name => 'List', nodes => []} } },
+ method => 'id',
+ args => { name => 'List', nodes => []} },
+ },
+ }},
+ $tree ] } };
+ }
+
+ my $condition = $builder->defun(
+ ops => [ $tree ],
+ signature => $sigs,
+ );
+
+ my $action = $builder->defun(
+ ops => [ { name => 'RT.ScripAction.Run',
+ args => {
+ name => $scrip_action,
+ template => $template,
+ ticket => { name => 'Symbol', args => { symbol => 'ticket' } },
+ transaction => { name => 'Symbol', args => { symbol => 'transaction' } },
+ } } ],
+ signature => $sigs );
+
+ RT::Lorzy::Rule->new(
+ { condition => $condition,
+ action => $action } )
+}
+
package RT::Lorzy::Rule;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(qw(condition action));
More information about the Rt-commit
mailing list