[Rt-commit] rt branch, lcore, updated. c3d60783fa30f1076bd27ae0229201f5e0190e6d

clkao at bestpractical.com clkao at bestpractical.com
Sun Jul 26 01:54:55 EDT 2009


The branch, lcore has been updated
       via  c3d60783fa30f1076bd27ae0229201f5e0190e6d (commit)
       via  3987c1df13dac349a4083ada79828ff3dcec9cc2 (commit)
       via  508318021d58ce267daab773e4ad576c48d7d319 (commit)
       via  68c26343a315c812cc914936ff70f6343adfcb1a (commit)
       via  7662105da86e944eddca417004a79cee1ea93c4b (commit)
       via  d6b7036d92c720852814622e982c7fad34174035 (commit)
       via  caa41122748e45ed97009558e05a2627462c1c5b (commit)
      from  840f105b2227defc9a2eca7109bc63e6ba4cdd7d (commit)

Summary of changes:
 lib/RT/Bootstrap.pm          |    2 -
 lib/RT/Lorzy.pm              |   46 ++++++++-----------
 lib/RT/Lorzy/Package/RT.pm   |  103 ++++++++++++------------------------------
 lib/RT/Model/Rule.pm         |    8 ---
 t/api/action-createtickets.t |    7 +--
 t/approval/basic.t           |    9 +---
 t/lorzy/action.t             |    7 ---
 t/lorzy/basic.t              |   77 -------------------------------
 t/lorzy/condition-lambda.t   |   32 ++-----------
 t/lorzy/condition.t          |   57 -----------------------
 t/lorzy/error.t              |   43 ++++++++++++-----
 11 files changed, 89 insertions(+), 302 deletions(-)
 delete mode 100644 t/lorzy/basic.t
 delete mode 100644 t/lorzy/condition.t

- Log -----------------------------------------------------------------
commit caa41122748e45ed97009558e05a2627462c1c5b
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 07:03:31 2009 +0800

    make error.t pass again.

diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index a183bce..6797bcd 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -162,23 +162,29 @@ sub _init {
     $self->factory($args{factory});
 }
 
+sub handle_exception {
+    my $self = shift;
+    my $e;
+    if ( $e = LCore::Exception->caught() ) {
+        Jifty->log->error("Rule '@{[ $self->description]}' condition error, ignoring: $e");
+    }
+    elsif ( $e = Exception::Class->caught() ) {
+        warn $e;
+        ref $e ? $e->rethrow : die "$e";
+    }
+}
+
 sub prepare {
     my ( $self, %args ) = @_;
-    warn "===> hi this is prepare for $self ";
-    my $ret = $self->factory->condition->apply($self->ticket_obj, $self->transaction);
-    warn $ret;
-#    if (my $e = Lorzy::Exception->caught()) {
-#        Jifty->log->error("Rule '@{[ $self->description]}' condition error, ignoring: $e");
-#    }
+    my $ret = eval { $self->factory->condition->apply($self->ticket_obj, $self->transaction) };
+    return if $self->handle_exception();
     return unless $ret;
 
     return 1 unless $self->factory->prepare;
-    warn "==> hi this is to preprae";
-    $ret = $self->factory->prepare->apply($self->ticket_obj, $self->transaction, $self->context);
 
-#    if (my $e = Lorzy::Exception->caught()) {
-#        Jifty->log->error("Rule '@{[ $self->description]}' prepare error, ignoring: $e");
-#    }
+    $ret = eval { $self->factory->prepare->apply($self->ticket_obj, $self->transaction, $self->context) };
+    return if $self->handle_exception();
+
     return $ret;
 }
 
@@ -191,12 +197,9 @@ sub hints {
 
 sub commit {
     my ($self, %args) = @_;
-    warn "==> trying to commit ".$self->factory->description;
-    my $ret = $self->factory->action->apply($self->ticket_obj, $self->transaction, $self->context);
+    my $ret = eval { $self->factory->action->apply($self->ticket_obj, $self->transaction, $self->context) };
+    return if $self->handle_exception();
 
-#    if (my $e = Lorzy::Exception->caught()) {
-#        Jifty->log->error("Rule '@{[ $self->description]}' commit error: $e");
-#    }
     return $ret;
 }
 
diff --git a/t/lorzy/error.t b/t/lorzy/error.t
index ef38051..079485a 100644
--- a/t/lorzy/error.t
+++ b/t/lorzy/error.t
@@ -1,4 +1,4 @@
-use Test::More tests => 3;
+use Test::More tests => 6;
 use RT::Test;
 
 use strict;
@@ -12,10 +12,25 @@ use RT::Model::ACE;
 use RT::CurrentUser;
 use Test::Exception;
 
-use_ok('Lorzy');
-
-my $eval = Lorzy::Evaluator->new();
-$eval->load_package($_) for qw(Str Native);
+use_ok('RT::Lorzy');
+use_ok('LCore');
+use_ok('LCore::Level2');
+
+my $l = $RT::Lorzy::LCORE;
+$l->env->set_symbol('cause-error' => LCore::Primitive->new
+                        ( body => sub {
+                              die "fail";
+                          },
+                          lazy => 0,
+                      ));
+
+$l->env->set_symbol('inc-hint-run' => LCore::Primitive->new
+                        ( body => sub {
+                              my ($context) = @_;
+                              $context->{hints}{run}++;
+                          },
+                          lazy => 0,
+                      ));
 
 my $queue = RT::Model::Queue->new(current_user => RT->system_user);
 my ($queue_id) = $queue->create( name =>  'lorzy');
@@ -26,19 +41,21 @@ my ($rv, $msg) = $ticket->create( subject => 'watcher tests', queue => $queue->n
 
 use RT::Lorzy;
 
-$YAML::Syck::UseCode = $YAML::UseCode = 1;
 my $rule = RT::Model::Rule->new( current_user => RT->system_user );
-$rule->create_from_factory(
-    RT::Lorzy::RuleFactory->make_factory
-            ( { condition => sub { die 'condition fail' },
-                description => 'test fail action',
-                _stage => 'transaction_create',
-                action => sub { $_[0]->{context}{hints}{run}++ } } )
-);
+$rule->create( description => 'test fail action',
+               condition_code => '(lambda (ticket transaction) (cause-error))',
+               action_code    => '(lambda (ticket transaction context) (inc-hint-run context))' );
+
+$rule->create( description => 'test worky action',
+               condition_code => '(lambda (ticket transaction) 1)',
+               action_code    => '(lambda (ticket transaction context) (inc-hint-run context))' );
 
 my ($txn_id, $tmsg, $txn) = $ticket->comment(content => 'lorzy lorzy in the code');
 my ($this_rule) = grep { $_->description eq 'test fail action'} @{$txn->rules};
 
 ok(!$this_rule, 'not running failing condition rules');
 
+($this_rule) = grep { $_->description eq 'test worky action'} @{$txn->rules};
+ok($this_rule, 'running worky condition rules');
+
 

commit d6b7036d92c720852814622e982c7fad34174035
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 07:09:57 2009 +0800

    cleanup lorzy reference

diff --git a/lib/RT/Bootstrap.pm b/lib/RT/Bootstrap.pm
index 605a5e5..a755ed9 100644
--- a/lib/RT/Bootstrap.pm
+++ b/lib/RT/Bootstrap.pm
@@ -445,9 +445,7 @@ sub insert_data {
         #print "done.\n";
     }
     if (@Scrips) {
-        # XXX: put into RT::Model::Rules
         require RT::Lorzy;
-        require Lorzy::Builder;
         for my $item (sort { $a->{description} cmp $b->{description} } @Scrips) {
             RT::Lorzy->create_scripish(
                 $item->{scrip_condition},
diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index 6797bcd..127ac9a 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -3,13 +3,9 @@ use strict;
 use warnings;
 
 use RT::Ruleset;
-use Lorzy::Evaluator;
 use RT::Lorzy::Dispatcher;
 
 RT::Ruleset->register( 'RT::Lorzy::Dispatcher' );
-our $EVAL = Lorzy::Evaluator->new();
-#$EVAL->load_package($_) for qw(Str Native);
-#$EVAL->load_package('RT', 'RT::Lorzy::Package::RT');
 use LCore;
 use LCore::Level2;
 
@@ -72,11 +68,6 @@ $LCORE->env->set_symbol('RT.RuleAction.Run' => LCore::Primitive->new
                       ));
 
 
-sub evaluate {
-    my ($self, $code, %args) = @_;
-    eval { $EVAL->apply_script( $code, \%args ) };
-}
-
 my %cond_compat_map = ( 'On Create' => 'OnCreate',
                         'On Transaction' => 'OnTransaction',
                         'On Correspond' => 'OnCorrespond',
diff --git a/lib/RT/Lorzy/Package/RT.pm b/lib/RT/Lorzy/Package/RT.pm
index 88745cd..3461163 100644
--- a/lib/RT/Lorzy/Package/RT.pm
+++ b/lib/RT/Lorzy/Package/RT.pm
@@ -1,6 +1,5 @@
 package RT::Lorzy::Package::RT;
 use strict;
-use base 'Lorzy::Package';
 
 sub lcore_defun {
     my ($env, $name, %args) = @_;

commit 7662105da86e944eddca417004a79cee1ea93c4b
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 07:23:20 2009 +0800

    make condition-lambda pass.

diff --git a/lib/RT/Lorzy/Package/RT.pm b/lib/RT/Lorzy/Package/RT.pm
index 3461163..ed282fc 100644
--- a/lib/RT/Lorzy/Package/RT.pm
+++ b/lib/RT/Lorzy/Package/RT.pm
@@ -86,48 +86,51 @@ __PACKAGE__->lcore_defun( 'Condition.OnReopen',
     },
 );
 
-=begin comment
-
-__PACKAGE__->defun( 'Condition.BeforeDue',
+$RT::Lorzy::LCORE->env->set_symbol('RT.MkCondition.BeforeDue' => LCore::Primitive->new(
     # format is "1d2h3m4s" for 1 day and 2 hours and 3 minutes and 4 seconds.
-    signature => { 'datestring' => Lorzy::FunctionArgument->new( name => 'datestring', type => 'Str' ) },
-
-    native => sub {
-        my $xargs = shift;
+    parameters => [LCore::Parameter->new( name => 'datestring', type => 'Str' )],
+    lazy => 0,
+    body => sub {
+        my $datestring = shift;
         my %e;
         foreach (qw(d h m s)) {
-            my @vals = $xargs->{datestring} =~ m/(\d+)$_/;
+            my @vals = $datestring =~ m/(\d+)$_/;
             $e{$_} = pop @vals || 0;
         }
         my $elapse = $e{'d'} * 24 * 60 * 60 + $e{'h'} * 60 * 60 + $e{'m'} * 60 + $e{'s'};
 
-        return Lorzy::Lambda::Native->new
+        return LCore::Primitive->new
             ( body => sub {
-                  my $args = shift;
+                  my ($ticket, $transaction) = @_;
                   my $cur = RT::DateTime->now;
-                  my $due = $args->{ticket}->due;
+                  my $due = $ticket->due;
                   return (undef) if $due->epoch <= 0;
 
                   my $diff = $due->diff($cur);
                   return ($diff >= 0 and $diff <= $elapse);
               },
-              signature => $sig_ticket_txn );
-    },
-);
-
-__PACKAGE__->defun( 'Condition.PriorityExceeds',
-    signature => { 'priority' => Lorzy::FunctionArgument->new( name => 'priority', type => 'Int' ),
-               },
-    native => sub {
-        my $xargs = shift;
-        return Lorzy::Lambda::Native->new
+              parameters => [ LCore::Parameter->new({ name => 'ticket', type => 'RT::Model::Ticket' }),
+                              LCore::Parameter->new({ name => 'transaction', type => 'RT::Model::Transaction' }) ]
+          ),
+      }
+));
+
+$RT::Lorzy::LCORE->env->set_symbol('RT.MkCondition.PriorityExceeds' => LCore::Primitive->new(
+    parameters => [ LCore::Parameter->new( name => 'priority', type => 'Num' ) ],
+    body => sub {
+        my $priority = shift;
+        return LCore::Primitive->new
             ( body => sub {
-                  my $args = shift;
-                  $args->{ticket}->priority > $xargs->{priority};
+                  my $ticket = shift;
+                  $ticket->priority > $priority;
               },
-              signature => $sig_ticket_txn );
-    },
-);
+              parameters => [ LCore::Parameter->new({ name => 'ticket', type => 'RT::Model::Ticket' }),
+                              LCore::Parameter->new({ name => 'transaction', type => 'RT::Model::Transaction' }) ]
+          );
+      },
+));
+
+=begin comment
 
 __PACKAGE__->defun( 'Condition.Overdue',
     signature => $sig_ticket_txn,
@@ -156,50 +159,4 @@ return 0;
     );
 }
 
-=begin comment
-
-__PACKAGE__->defun( 'ScripAction.Prepare',
-    signature => {
-        'name'     => Lorzy::FunctionArgument->new( name => 'name' ),
-        'context'  => Lorzy::FunctionArgument->new( name => 'context' ),
-        'template' => Lorzy::FunctionArgument->new( name => 'template' ),
-        %$sig_ticket_txn,
-    },
-    native => sub {
-        my $args   = shift;
-        my $rule = RT::Rule->new( current_user => $args->{ticket}->current_user,
-                                  ticket_obj => $args->{ticket},
-                                  transaction_obj => $args->{transaction}
-                              );
-        my $action = $rule->get_scrip_action(@{$args}{qw(name template)});
-        $action->prepare or return;
-        $args->{context}{hints} = $action->hints;
-        $args->{context}{action} = $action;
-    },
-);
-
-__PACKAGE__->defun( 'ScripAction.Run',
-    signature => {
-        'name'     => Lorzy::FunctionArgument->new( name => 'name' ),
-        'context'  => Lorzy::FunctionArgument->new( name => 'context' ),
-        'template' => Lorzy::FunctionArgument->new( name => 'template' ),
-        %$sig_ticket_txn,
-    },
-    native => sub {
-        my $args   = shift;
-        my $action = $args->{context}{action};
-        unless ($action) {
-            my $rule = RT::Rule->new( current_user => $args->{ticket}->current_user,
-                                                ticket_obj => $args->{ticket},
-                                                transaction_obj => $args->{transaction}
-                                            );
-            $action = $rule->get_scrip_action(@{$args}{qw(name template)});
-            $action->prepare or return;
-        }
-        $action->commit;
-    },
-);
-
-=cut
-
 1;
diff --git a/t/lorzy/condition-lambda.t b/t/lorzy/condition-lambda.t
index 784feac..7ccc132 100644
--- a/t/lorzy/condition-lambda.t
+++ b/t/lorzy/condition-lambda.t
@@ -12,34 +12,12 @@ use RT::Model::ACE;
 use RT::CurrentUser;
 use Test::Exception;
 
-use_ok('Lorzy');
+use_ok('RT::Lorzy');
 
-my $eval = Lorzy::Evaluator->new();
-$eval->load_package($_) for qw(Str Native);
-$eval->load_package('RT', 'RT::Lorzy::Package::RT');
+my $l = $RT::Lorzy::LCORE;
 
-my $priority10 = { name => 'RT.Condition.PriorityExceeds',
-                   args => {
-                       priority => 10
-                   }
-               };
 
-my $tree    = [ { name => 'Apply',
-                  args => {
-                      lambda => $priority10,
-                      apply_args =>
-                      { ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
-                        transaction => { name => 'Symbol', args => { symbol => 'transaction' }} },
-                  }
-              } ];
-
-my $builder = Lorzy::Builder->new();
-my $important  = $builder->defun(
-    ops => $tree,
-    signature =>
-        { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
-          transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) }
-);
+my $priority10 = $l->analyze_it(q{(RT.MkCondition.PriorityExceeds 10)})->($l->env);
 
 my $queue = RT::Model::Queue->new(current_user => RT->system_user);
 my ($queue_id) = $queue->create( name =>  'lorzy');
@@ -52,14 +30,14 @@ my $txn = $ticket->transactions->first;
 
 my $ret;
 lives_ok {
-    $ret = $eval->apply_script( $important, { 'ticket' => $ticket, transaction => $txn } );
+    $ret = $priority10->apply($ticket, $txn);
 };
 ok(!$ret);
 
 $ticket->set_priority('11');
 
 lives_ok {
-    $ret = $eval->apply_script( $important, { 'ticket' => $ticket, transaction => $ticket->transactions->last } );
+    $ret = $priority10->apply($ticket, $txn);
 };
 ok($ret);
 

commit 68c26343a315c812cc914936ff70f6343adfcb1a
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 07:24:48 2009 +0800

    remove old tests.

diff --git a/t/lorzy/basic.t b/t/lorzy/basic.t
deleted file mode 100644
index 26e1ec8..0000000
--- a/t/lorzy/basic.t
+++ /dev/null
@@ -1,77 +0,0 @@
-use Test::More tests => 8;
-use RT::Test;
-
-use strict;
-use warnings;
-
-use RT::Model::Queue;
-use RT::Model::User;
-use RT::Model::Group;
-use RT::Model::Ticket;
-use RT::Model::ACE;
-use RT::CurrentUser;
-use Test::Exception;
-
-use_ok('Lorzy');
-
-my $eval = Lorzy::Evaluator->new();
-$eval->load_package($_) for qw(Str Native);
-
-my $tree    = [ { name => 'IfThen',
-                  args => { if_true => { name => 'True' },
-                            if_false => { name => 'False' },
-                            condition => { name => 'Str.Eq',
-                                args => {
-                                    arg1 => "open",
-                                    arg2 => { name => 'Native.Invoke',
-                                              args => { obj => { name => 'Symbol', args => { symbol => 'ticket' }},
-                                                        method => 'status',
-                                                        args => { name => 'List',  nodes => []} },
-                                          },
-                                }
-                  } }} ];
-my $builder = Lorzy::Builder->new();
-my $is_open  = $builder->defun(
-    ops => $tree,
-    signature =>
-        { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
-          transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) }
-);
-
-my $queue = RT::Model::Queue->new(current_user => RT->system_user);
-my ($queue_id) = $queue->create( name =>  'lorzy');
-ok( $queue_id, 'queue created' );
-
-my $ticket = RT::Model::Ticket->new(current_user => RT->system_user );
-my ($rv, $msg) = $ticket->create( subject => 'watcher tests', queue => $queue->name );
-
-my $ret;
-lives_ok {
-    $ret = $eval->apply_script( $is_open, { 'ticket' => $ticket, transaction => $ticket->transactions->first } );
-};
-ok(!$ret);
-
-$ticket->set_status('open');
-
-lives_ok {
-    $ret = $eval->apply_script( $is_open, { 'ticket' => $ticket, transaction => $ticket->transactions->first } );
-};
-ok($ret);
-
-use RT::Lorzy;
-
-$YAML::Syck::UseCode = $YAML::UseCode = 1;
-my $rule = RT::Model::Rule->new( current_user => RT->system_user );
-$rule->create_from_factory(
-    RT::Lorzy::RuleFactory->make_factory
-            ( { condition => $is_open,
-                description => 'test action',
-                _stage => 'transaction_create',
-                action => sub { $_[0]->{context}{hints}{run}++ } } )
-);
-my ($txn_id, $tmsg, $txn) = $ticket->comment(content => 'lorzy lorzy in the code');
-my ($this_rule) = grep { $_->description eq 'test action'} @{$txn->rules};
-
-ok($this_rule);
-is_deeply($this_rule->hints, { run => 1 });
-
diff --git a/t/lorzy/condition.t b/t/lorzy/condition.t
deleted file mode 100644
index dbc9b24..0000000
--- a/t/lorzy/condition.t
+++ /dev/null
@@ -1,57 +0,0 @@
-use Test::More tests => 6;
-use RT::Test;
-
-use strict;
-use warnings;
-
-use RT::Model::Queue;
-use RT::Model::User;
-use RT::Model::Group;
-use RT::Model::Ticket;
-use RT::Model::ACE;
-use RT::CurrentUser;
-use Test::Exception;
-
-use_ok('Lorzy');
-
-my $eval = Lorzy::Evaluator->new();
-$eval->load_package($_) for qw(Str Native);
-$eval->load_package('RT', 'RT::Lorzy::Package::RT');
-
-my $tree    = [ { name => 'RT.Condition.OnCreate',
-                  args => {
-                      ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
-                      transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
-                  }
-              } ];
-
-my $builder = Lorzy::Builder->new();
-my $on_created  = $builder->defun(
-    ops => $tree,
-    signature =>
-        { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
-          transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) }
-);
-
-my $queue = RT::Model::Queue->new(current_user => RT->system_user);
-my ($queue_id) = $queue->create( name =>  'lorzy');
-ok( $queue_id, 'queue created' );
-
-my $ticket = RT::Model::Ticket->new(current_user => RT->system_user );
-my ($rv, $msg) = $ticket->create( subject => 'watcher tests', queue => $queue->name );
-
-my $txn = $ticket->transactions->first;
-
-my $ret;
-lives_ok {
-    $ret = $eval->apply_script( $on_created, { 'ticket' => $ticket, transaction => $txn } );
-};
-ok($ret);
-
-$ticket->set_status('open');
-
-lives_ok {
-    $ret = $eval->apply_script( $on_created, { 'ticket' => $ticket, transaction => $ticket->transactions->last } );
-};
-ok(!$ret);
-

commit 508318021d58ce267daab773e4ad576c48d7d319
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 08:01:15 2009 +0800

    make action-createtickets pass.

diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index 127ac9a..f350bdc 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -92,7 +92,7 @@ sub create_scripish {
 
     my $lcore_cond = "(RT.Condition.$lorzy_cond ticket transaction)";
     if ($queue) {
-        $lcore_cond = qq{(and $lcore_cond (Str.Eq "$queue" (Native.Invoke ticket "queue")))};
+        $lcore_cond = qq{(and $lcore_cond (Str.Eq "$queue" (Native.Invoke ticket "queue_id")))};
     }
     $lcore_cond = qq{(lambda (ticket transaction) $lcore_cond)};
 
@@ -122,6 +122,7 @@ sub create_scripish {
                    action_code    => $lcore_action,
                    description    => $description,
                );
+    return $rule;
 }
 
 package RT::Lorzy::RuleFactory;
@@ -160,7 +161,6 @@ sub handle_exception {
         Jifty->log->error("Rule '@{[ $self->description]}' condition error, ignoring: $e");
     }
     elsif ( $e = Exception::Class->caught() ) {
-        warn $e;
         ref $e ? $e->rethrow : die "$e";
     }
 }
diff --git a/t/api/action-createtickets.t b/t/api/action-createtickets.t
index 801dc7e..07fee94 100644
--- a/t/api/action-createtickets.t
+++ b/t/api/action-createtickets.t
@@ -54,16 +54,13 @@ my $q = RT::Model::Queue->new(current_user => RT->system_user);
 $q->create(name => 'WorkflowTest');
 ok ($q->id, "Created workflow test queue");
 
-my $rule_factory = RT::Lorzy->create_scripish(
+my $rule = RT::Lorzy->create_scripish(
     'On Transaction',
     'Create Tickets',
     'Approvals',
     'Create approval tickets',
      $q->id);
-
-my $rule = RT::Model::Rule->new( current_user => RT->system_user );
-$rule->create_from_factory( $rule_factory );
-
+diag $rule->condition_code;
 my $t = RT::Model::Ticket->new(current_user => RT->system_user);
 my($tid, $ttrans, $tmsg) = $t->create(subject => "Sample workflow test",
            Owner => "root",

commit 3987c1df13dac349a4083ada79828ff3dcec9cc2
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 08:09:33 2009 +0800

    restore simple txn condition helpers.

diff --git a/lib/RT/Lorzy/Package/RT.pm b/lib/RT/Lorzy/Package/RT.pm
index ed282fc..bc63eeb 100644
--- a/lib/RT/Lorzy/Package/RT.pm
+++ b/lib/RT/Lorzy/Package/RT.pm
@@ -152,7 +152,6 @@ my %simple_txn_cond = ( 'OnCreate' => 'create',
 for my $name ( keys %simple_txn_cond ) {
     __PACKAGE__->lcore_defun( "Condition.$name",
         native => sub {
-return 0;
             my $args = shift;
             return $args->{transaction}->type eq $simple_txn_cond{$name};
         },

commit c3d60783fa30f1076bd27ae0229201f5e0190e6d
Author: Chia-liang Kao <clkao at clkao.org>
Date:   Sun Jul 26 08:35:02 2009 +0800

    retire create_from_factory

diff --git a/lib/RT/Model/Rule.pm b/lib/RT/Model/Rule.pm
index 4700166..f0fab9b 100644
--- a/lib/RT/Model/Rule.pm
+++ b/lib/RT/Model/Rule.pm
@@ -77,13 +77,5 @@ use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata map => {
     updated_on => 'last_updated'
 };
 
-sub create_from_factory {
-    my ($self, $factory) = @_;
-    my %args = map { $_.'_code' => Jifty::YAML::Dump( $factory->$_ ) }
-        qw(action condition prepare );
-    $self->SUPER::create( %args,
-                          description => $factory->description );
-}
-
 1;
 
diff --git a/t/approval/basic.t b/t/approval/basic.t
index 860965d..0867cae 100644
--- a/t/approval/basic.t
+++ b/t/approval/basic.t
@@ -67,17 +67,14 @@ $q = RT::Model::Queue->new(current_user => RT->system_user);
 $q->create(name => 'PO');
 ok ($q->id, "Created PO queue");
 
-# XXX: limit to one queue
-my $rule_factory = RT::Lorzy->create_scripish(
+my $rule = RT::Lorzy->create_scripish(
     'On Create',
     'Create Tickets',
     'PO Approvals',
+    'Create approval tickets',
     $q->id,
 );
-
-my $rule = RT::Model::Rule->new( current_user => RT->system_user );
-$rule->create_from_factory( $rule_factory );
-
+diag $rule->condition_code;
 my $t = RT::Model::Ticket->new(current_user => RT->system_user);
 my ($tid, $ttrans, $tmsg);
 
diff --git a/t/lorzy/action.t b/t/lorzy/action.t
index 8878cc3..634f134 100644
--- a/t/lorzy/action.t
+++ b/t/lorzy/action.t
@@ -44,13 +44,6 @@ my $rule = RT::Model::Rule->new( current_user => RT->system_user );
 $rule->create( condition_code => $on_created_lcore,
                action_code    => $auto_reply_lcore );
 
-#$rule->create_from_factory( 
-#    RT::Lorzy::RuleFactory->make_factory
-#    ( { condition => $on_created,
-#        _stage => 'transaction_create',
-#        action => $auto_reply } )
-#);
-
 my $queue = RT::Model::Queue->new(current_user => RT->system_user);
 my ($queue_id) = $queue->create( name =>  'lorzy');
 ok( $queue_id, 'queue created' );

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


More information about the Rt-commit mailing list