[Rt-commit] r19014 - in rt/3.999/trunk: . bin etc lib/RT lib/RT/Condition lib/RT/Interface lib/RT/Interface/Web lib/RT/Lorzy lib/RT/Lorzy/Package lib/RT/Model lib/RT/ScripAction lib/RT/Shredder sbin share/html/Admin/Elements share/html/Ticket/Elements t t/approval t/lorzy t/mail t/shredder t/ticket

clkao at bestpractical.com clkao at bestpractical.com
Wed Apr 1 11:28:45 EDT 2009


Author: clkao
Date: Wed Apr  1 11:28:45 2009
New Revision: 19014

Added:
   rt/3.999/trunk/TODO.lorzy
   rt/3.999/trunk/lib/RT/Lorzy/
   rt/3.999/trunk/lib/RT/Lorzy.pm
   rt/3.999/trunk/lib/RT/Lorzy/Dispatcher.pm
   rt/3.999/trunk/lib/RT/Lorzy/Package/
   rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm
   rt/3.999/trunk/lib/RT/Model/Rule.pm
   rt/3.999/trunk/sbin/shipwright-package
   rt/3.999/trunk/t/api/rules-preview.t
   rt/3.999/trunk/t/lorzy/
   rt/3.999/trunk/t/lorzy/action.t
   rt/3.999/trunk/t/lorzy/basic.t
   rt/3.999/trunk/t/lorzy/condition.t
Removed:
   rt/3.999/trunk/lib/RT/Condition/UserDefined.pm
   rt/3.999/trunk/lib/RT/Model/Scrip.pm
   rt/3.999/trunk/lib/RT/Model/ScripCollection.pm
   rt/3.999/trunk/lib/RT/ScripAction/UserDefined.pm
   rt/3.999/trunk/lib/RT/Shredder/Scrip.pm
   rt/3.999/trunk/t/api/condition-ownerchange.t
   rt/3.999/trunk/t/api/scrip.t
   rt/3.999/trunk/t/ticket/linking.t
   rt/3.999/trunk/t/ticket/scrips_batch.t
Modified:
   rt/3.999/trunk/   (props changed)
   rt/3.999/trunk/Makefile.PL
   rt/3.999/trunk/bin/rt-crontool
   rt/3.999/trunk/etc/RT_Config.pm
   rt/3.999/trunk/etc/initialdata
   rt/3.999/trunk/lib/RT/Bootstrap.pm
   rt/3.999/trunk/lib/RT/Condition.pm
   rt/3.999/trunk/lib/RT/Interface/Email.pm
   rt/3.999/trunk/lib/RT/Interface/Web/Handler.pm
   rt/3.999/trunk/lib/RT/Model/ScripAction.pm
   rt/3.999/trunk/lib/RT/Model/ScripCondition.pm
   rt/3.999/trunk/lib/RT/Model/Ticket.pm
   rt/3.999/trunk/lib/RT/Model/Transaction.pm
   rt/3.999/trunk/lib/RT/Rule.pm
   rt/3.999/trunk/lib/RT/Ruleset.pm
   rt/3.999/trunk/lib/RT/ScripAction.pm
   rt/3.999/trunk/lib/RT/ScripAction/SendEmail.pm
   rt/3.999/trunk/lib/RT/Shredder.pm
   rt/3.999/trunk/lib/RT/Shredder/Queue.pm
   rt/3.999/trunk/lib/RT/Shredder/ScripAction.pm
   rt/3.999/trunk/lib/RT/Shredder/ScripCondition.pm
   rt/3.999/trunk/lib/RT/Shredder/Template.pm
   rt/3.999/trunk/lib/RT/Shredder/User.pm
   rt/3.999/trunk/share/html/Admin/Elements/ListGlobalScrips
   rt/3.999/trunk/share/html/Ticket/Elements/PreviewScrips
   rt/3.999/trunk/t/00-compile.t
   rt/3.999/trunk/t/api/action-createtickets.t
   rt/3.999/trunk/t/api/scrip_order.t
   rt/3.999/trunk/t/approval/basic.t
   rt/3.999/trunk/t/mail/sendmail.t
   rt/3.999/trunk/t/shredder/02queue.t
   rt/3.999/trunk/t/shredder/02template.t

Log:
merge lorzy branch to trunk

Modified: rt/3.999/trunk/Makefile.PL
==============================================================================
--- rt/3.999/trunk/Makefile.PL	(original)
+++ rt/3.999/trunk/Makefile.PL	Wed Apr  1 11:28:45 2009
@@ -1,8 +1,8 @@
 use inc::Module::Install;
 
 name        'RT';
-version     '3.99_01';
-license 'GPLv2';
+version     '3.999_01';
+license     'GPLv2';
 requires    'Jifty' => '0.80913';
 
 requires(
@@ -16,10 +16,9 @@
     'File::Spec'                 => '0.8',
     'HTML::Entities'             => 0,
     'HTML::Scrubber'             => '0.08',
-    'Log::Dispatch'              => '2.0',
-    'Locale::Maketext'           => '1.06',
     'Locale::Maketext::Lexicon'  => '0.32',
     'Locale::Maketext::Fuzzy'    => '0',
+    'Lorzy'                      => '0',
     'MIME::Entity'               => '5.425',
     'Email::Address'             => 0,
     'Mail::Mailer'               => '1.57',
@@ -49,26 +48,13 @@
     'Mason' => [
         -default            => 1,
         'HTML::Mason'       => 1.40,
-        'Errno'             => 0,
         'Digest::MD5'       => 2.27,
-        'CGI::Cookie'       => 1.20,
         'Storable'          => 2.08,
         'XML::RSS'          => 1.05,
         'Text::WikiFormat'  => 0.76,
         'CSS::Squish'       => 0.06,
         'Devel::StackTrace' => 1.19,
     ],
-
-    'Standalone Server' => [
-        -default => 1,
-
-        'HTTP::Server::Simple' => 0.34,
-        'HTTP::Server::Simple::Mason', 0.09,
-        'Net::Server'          => 0,
-        'Net::Server::PreFork' => 0
-    ],
-
-    ,
     MAILGATE => [
         -default => 1,
         'HTML::TreeBuilder',
@@ -102,8 +88,6 @@
         'File::Find',
         'Test::Deep', => 0,
         'String::ShellQuote'         => '0',
-        'Test::HTTP::Server::Simple' => '0.09',
-        'Log::Dispatch::Perl',
         'Test::Warn',
         'Test::Builder' => '0.77',
         'IPC::Run3',
@@ -118,29 +102,6 @@
         ]
 
     ,
-    SPEEDYCGI => [
-        -default => 0,
-        'CGI'    => '3.38',
-        'CGI::SpeedyCGI'
-        ]
-
-    ,
-    MODPERL1 => [
-        -default => 0,
-        'CGI'    => '3.38',
-        'Apache::Request',
-        'Apache::DBI' => '0.92'
-        ]
-
-    ,
-    MODPERL2 => [
-        -default => 0,
-        'CGI'    => '3.38',
-        'Apache::DBI',
-        'HTML::Mason' => '1.40',
-        ]
-
-    ,
     MYSQL => [
         -default     => 1,
         'DBD::mysql' => '2.1018'

Added: rt/3.999/trunk/TODO.lorzy
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/TODO.lorzy	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,2 @@
+* lorzy code improvements:  control flow handling like return, exception
+* test and implement ordering of rules

Modified: rt/3.999/trunk/bin/rt-crontool
==============================================================================
--- rt/3.999/trunk/bin/rt-crontool	(original)
+++ rt/3.999/trunk/bin/rt-crontool	Wed Apr  1 11:28:45 2009
@@ -109,7 +109,6 @@
     $template_obj = RT::Model::Template->new( current_user => $CurrentUser );
     $template_obj->load($template_id);
 }
-my $void_scrip = RT::Model::Scrip->new( current_user => $CurrentUser );
 my $void_scrip_action = RT::Model::ScripAction->new( current_user => $CurrentUser );
 
 #At the appointed time:
@@ -159,7 +158,6 @@
         my $condition_obj = $condition->new(
             transaction_obj => $transaction,
             ticket_obj      => $ticket,
-            scrip_obj       => $void_scrip,
             template_obj    => $template_obj,
             argument       => $condition_arg,
             current_user    => $CurrentUser,
@@ -177,7 +175,6 @@
         transaction_obj => $transaction,
         template_obj    => $template_obj,
         argument       => $action_arg,
-        scrip_obj       => $void_scrip,
         scrip_action_obj => $void_scrip_action,
         current_user    => $CurrentUser,
     );

Modified: rt/3.999/trunk/etc/RT_Config.pm
==============================================================================
--- rt/3.999/trunk/etc/RT_Config.pm	(original)
+++ rt/3.999/trunk/etc/RT_Config.pm	Wed Apr  1 11:28:45 2009
@@ -677,16 +677,6 @@
 set($LogDir, '/home/jesse/svk/3.999-DANGEROUS/var/log');
 set($LogToFileNamed , "rt.log");    #log to rt.log
 
-=item C<$LogStackTraces>
-
-If set to a log level then logging will include stack
-traces for messages with level equal to or greater than
-specified.
-
-=cut
-
-set($LogStackTraces, '');
-
 =item C<@LogToSyslogConf>
 
 On Solaris or UnixWare, set to ( socket => 'inet' ).  Options here

Modified: rt/3.999/trunk/etc/initialdata
==============================================================================
--- rt/3.999/trunk/etc/initialdata	(original)
+++ rt/3.999/trunk/etc/initialdata	Wed Apr  1 11:28:45 2009
@@ -92,9 +92,6 @@
       description => 'Sends mail to explicitly listed ccs and Bccs',      # loc
       exec_module  => 'Notify',
       argument    => 'other recipients' },
-    { name        => 'User Defined',                                      # loc
-      description => 'Perform a user-defined action',                     # loc
-      exec_module  => 'UserDefined', },
     {  name        => 'Create Tickets',                                    # loc
        description =>
          'Create new tickets based on this scrip\'s template',             # loc
@@ -169,13 +166,6 @@
 
     },
 
-    {  name                 => 'User Defined',                             # loc
-       description          => 'Whenever a user-defined condition occurs', # loc
-       applicable_trans_types => 'any',
-       exec_module           => 'UserDefined'
-
-    },
-
     {  name                 => 'On Close',                                 # loc
        description          => 'Whenever a ticket is closed', # loc
        applicable_trans_types => 'status,set',

Modified: rt/3.999/trunk/lib/RT/Bootstrap.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Bootstrap.pm	(original)
+++ rt/3.999/trunk/lib/RT/Bootstrap.pm	Wed Apr  1 11:28:45 2009
@@ -442,31 +442,20 @@
         #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) {
+            my $rule_factory = RT::Lorzy->create_scripish(
+                $item->{scrip_condition},
+                $item->{scrip_action},
+                $item->{template},
+                $item->{description},
+            );
 
-        #print "Creating scrips...";
-
-        for my $item (@Scrips) {
-            my $new_entry = RT::Model::Scrip->new( current_user => RT->system_user );
-
-            my @queues
-                = ref $item->{'queue'} eq 'ARRAY'
-                ? @{ $item->{'queue'} }
-                : $item->{'queue'} || 0;
-            push @queues, 0 unless @queues;    # add global queue at least
-
-            foreach my $q (@queues) {
-                my ( $return, $msg ) = $new_entry->create( %$item, queue => $q );
-                if ($return) {
-
-                    #print $return. ".";
-                } else {
-
-                    #print "(Error: $msg)\n";
-                }
-            }
+            my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+            $rule->create_from_factory( $rule_factory );
         }
-
-        #print "done.\n";
     }
 
     if (@Attributes) {

Modified: rt/3.999/trunk/lib/RT/Condition.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Condition.pm	(original)
+++ rt/3.999/trunk/lib/RT/Condition.pm	Wed Apr  1 11:28:45 2009
@@ -56,7 +56,6 @@
     my $foo = RT::Condition->new( 
 		transaction_obj => $tr, 
 		ticket_obj => $ti, 
-		scrip_obj => $scr, 
 		Argument => $arg, 
 		Type => $type);
 
@@ -97,7 +96,6 @@
     my %args = (
         transaction_obj       => undef,
         ticket_obj            => undef,
-        scrip_obj             => undef,
         template_obj          => undef,
         argument             => undef,
         applicable_trans_types => undef,
@@ -106,7 +104,6 @@
     );
 
     $self->{'argument'}             = $args{'argument'};
-    $self->{'scrip_obj'}             = $args{'scrip_obj'};
     $self->{'ticket_obj'}            = $args{'ticket_obj'};
     $self->{'transaction_obj'}       = $args{'transaction_obj'};
     $self->{'applicable_trans_types'} = $args{'applicable_trans_types'};
@@ -143,18 +140,6 @@
 
 
 
-=head2 scrip_obj
-
-Return the Scrip object we're talking about
-
-=cut
-
-sub scrip_obj {
-    my $self = shift;
-    return ( $self->{'scrip_obj'} );
-}
-
-
 =head2 transaction_obj
 
 Return the transaction object we're talking about
@@ -208,7 +193,6 @@
     $self->{'template_obj'} = undef;
     $self->{'ticket_obj'} = undef;
     $self->{'transaction_obj'} = undef;
-    $self->{'scrip_obj'}       = undef;
 
 }
 

Modified: rt/3.999/trunk/lib/RT/Interface/Email.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Interface/Email.pm	(original)
+++ rt/3.999/trunk/lib/RT/Interface/Email.pm	Wed Apr  1 11:28:45 2009
@@ -941,8 +941,8 @@
 sub gen_message_id {
     my %args = (
         ticket       => undef,
-        Scrip        => undef,
-        scrip_action => undef,
+        scrip        => undef,
+        sequence     => undef,
         @_
     );
     my $org = RT->config->get('Organization');
@@ -950,8 +950,7 @@
         || 0;
     my $scrip_id = ( ref $args{'Scrip'} ? $args{'Scrip'}->id : $args{'Scrip'} )
         || 0;
-    my $sent = ( ref $args{'scrip_action'} ? $args{'scrip_action'}->{'_Message_ID'} : 0 )
-        || 0;
+    my $sent = $args{sequence} || 0;
 
     return "<rt-" . $RT::VERSION . "-" . $$ . "-" . CORE::time() . "-" . int( rand(2000) ) . '.' . $ticket_id . "-" . $scrip_id . "-" . $sent . "@" . $org . ">";
 }

Modified: rt/3.999/trunk/lib/RT/Interface/Web/Handler.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Interface/Web/Handler.pm	(original)
+++ rt/3.999/trunk/lib/RT/Interface/Web/Handler.pm	Wed Apr  1 11:28:45 2009
@@ -50,7 +50,6 @@
 use CGI qw/-private_tempfiles/;
 use MIME::Entity;
 use Text::Wrapper;
-use CGI::Cookie;
 use Time::ParseDate;
 use Time::HiRes;
 use HTML::Entities;

Added: rt/3.999/trunk/lib/RT/Lorzy.pm
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/lib/RT/Lorzy.pm	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,162 @@
+package RT::Lorzy;
+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');
+
+sub evaluate {
+    my ($self, $code, %args) = @_;
+    my $ret = $EVAL->apply_script( $code, \%args );
+    return $ret;
+}
+
+sub create_scripish {
+    my ( $class, $scrip_condition, $scrip_action, $template, $description, $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 },
+    );
+
+    $sigs->{context} = Lorzy::FunctionArgument->new( name => 'context', type => 'HASH' );
+
+    my $prepare = $builder->defun(
+        ops => [ { name => 'RT.ScripAction.Prepare',
+                args => {
+                    name     => $scrip_action,
+                    context => { name => 'Symbol', args => { symbol => 'context' } },
+                    template => $template,
+                    ticket => { name => 'Symbol', args => { symbol => 'ticket' } },
+                    transaction => { name => 'Symbol', args => { symbol => 'transaction' } },
+                    } } ],
+        signature => $sigs );
+
+    my $action = $builder->defun(
+        ops => [ { name => 'RT.ScripAction.Run',
+                args => {
+                    name     => $scrip_action,
+                    context => { name => 'Symbol', args => { symbol => 'context' } },
+                    template => $template,
+                    ticket => { name => 'Symbol', args => { symbol => 'ticket' } },
+                    transaction => { name => 'Symbol', args => { symbol => 'transaction' } },
+                    } } ],
+        signature => $sigs );
+
+    RT::Lorzy::RuleFactory->make_factory(
+        { condition     => $condition,
+          prepare       => $prepare,
+          action        => $action,
+          description   => $description,
+          _stage        => 'transaction_create',
+      } )
+}
+
+package RT::Lorzy::RuleFactory;
+use base 'Class::Accessor::Fast';
+__PACKAGE__->mk_accessors(qw(description condition action prepare _stage));
+
+sub make_factory {
+    my $class = shift;
+    my $self = $class->SUPER::new(@_);
+    if (ref($self->action) eq 'CODE') {
+        # XXX: signature compat check
+        $self->action( Lorzy::Lambda::Native->new( body => $self->action,
+                                                   signature => 
+        { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+          context => Lorzy::FunctionArgument->new( name => 'context', type => 'RT::Model::Ticket' ),
+          transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) }
+
+                                               ) );
+    }
+    return $self;
+}
+
+sub new {
+    my $self = shift;
+    return RT::Lorzy::Rule->new( @_, factory => $self);
+}
+
+package RT::Lorzy::Rule;
+use base 'RT::Rule';
+use base 'Class::Accessor::Fast';
+
+__PACKAGE__->mk_accessors(qw(factory context _last_scripaction));
+
+sub _init {
+    my $self = shift;
+    Carp::cluck if scalar @_ % 2;
+    my %args = @_;
+    $self->SUPER::_init(%args);
+    $self->context({});
+    $self->factory($args{factory});
+}
+
+sub prepare {
+    my ( $self, %args ) = @_;
+    RT::Lorzy->evaluate( $self->factory->condition,
+        ticket      => $self->ticket_obj,
+        transaction => $self->transaction )
+        or return;
+
+    return 1 unless $self->factory->prepare;
+
+    RT::Lorzy->evaluate( $self->factory->prepare,
+        context     => $self->context,
+        ticket      => $self->ticket_obj,
+        transaction => $self->transaction );
+
+}
+
+sub description { $_[0]->factory->description }
+
+sub hints {
+    my $self = shift;
+    return $self->context->{hints};
+}
+
+sub commit {
+    my ($self, %args) = @_;
+    return RT::Lorzy->evaluate( $self->factory->action,
+                                context => $self->context,
+                                ticket => $self->ticket_obj,
+                                transaction => $self->transaction);
+}
+
+1;

Added: rt/3.999/trunk/lib/RT/Lorzy/Dispatcher.pm
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/lib/RT/Lorzy/Dispatcher.pm	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,28 @@
+package RT::Lorzy::Dispatcher;
+use strict;
+use warnings;
+#use base 'RT::Ruleset';
+
+sub reset_rules {
+    my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
+    for (@$rules) {
+        $_->delete;
+    }
+}
+
+sub rules {
+    my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
+    $rules->unlimit;
+    return [ map {
+        RT::Lorzy::RuleFactory->make_factory(
+            { condition     => Jifty::YAML::Load($_->condition),
+              prepare       => Jifty::YAML::Load($_->prepare),
+              action        => Jifty::YAML::Load($_->action),
+              description   => $_->description,
+              _stage        => 'transaction_create' })
+        } @$rules];
+
+    return $rules;
+}
+
+1;

Added: rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,78 @@
+package RT::Lorzy::Package::RT;
+use strict;
+use base 'Lorzy::Package';
+
+__PACKAGE__->defun( 'Condition.Applicable',
+    signature => {
+        'name'   => Lorzy::FunctionArgument->new( name => 'name' ),
+        'ticket' => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+        'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
+    },
+    native => sub {
+        my $args   = shift;
+        my $scrip_condition = RT::Model::ScripCondition->new;
+        $scrip_condition->load($args->{name}) or die "Can't load scrip condition: $args->{name}";
+        $scrip_condition->load_condition(
+                ticket_obj      => $args->{'ticket'},
+                transaction_obj => $args->{'transaction'},
+            ) or die "Can't load condition: $args->{name}";
+
+
+        # XXX: this is so wrong, the applicable_trans_type check is
+        # done in scrip level rather than condition level. see
+        # RT::Model::Scrip.
+
+        my $txn_type = $args->{transaction}->type;
+        return 0
+            unless ( $scrip_condition->applicable_trans_types =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i );
+
+        return $scrip_condition->is_applicable();
+    },
+);
+
+__PACKAGE__->defun( 'ScripAction.Prepare',
+    signature => {
+        'name'     => Lorzy::FunctionArgument->new( name => 'name' ),
+        'context'  => Lorzy::FunctionArgument->new( name => 'context' ),
+        'template' => Lorzy::FunctionArgument->new( name => 'template' ),
+        'ticket'   => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+        'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
+    },
+    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' ),
+        'ticket'   => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+        'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
+    },
+    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;
+    },
+);
+
+
+1;

Added: rt/3.999/trunk/lib/RT/Model/Rule.pm
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/lib/RT/Model/Rule.pm	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,89 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+#                                          <jesse at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/copyleft/gpl.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+=head1 NAME
+
+RT::Model::Rule - an RT Rule object represening lorzy code
+
+=head1 METHODS
+
+
+=cut
+
+use strict;
+use warnings;
+
+package RT::Model::Rule;
+
+use base qw'RT::Record';
+
+sub table {'Rules'}
+use Jifty::DBI::Schema;
+use Jifty::DBI::Record schema {
+    column action    => type is 'text';
+    column condition => type is 'text';
+    column prepare   => type is 'text';
+    column description               => type is 'text';
+};
+use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata map => {
+    created_by => 'creator',
+    created_on => 'created',
+    updated_by => 'last_updated_by',
+    updated_on => 'last_updated'
+};
+
+sub create_from_factory {
+    my ($self, $factory) = @_;
+    my %args = map { $_ => Jifty::YAML::Dump( $factory->$_ ) }
+        qw(action condition prepare );
+    $self->SUPER::create( %args,
+                          description => $factory->description );
+}
+
+1;
+

Modified: rt/3.999/trunk/lib/RT/Model/ScripAction.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Model/ScripAction.pm	(original)
+++ rt/3.999/trunk/lib/RT/Model/ScripAction.pm	Wed Apr  1 11:28:45 2009
@@ -156,7 +156,6 @@
     $self->{'action'} = $type->new(
         argument         => $self->argument,
         current_user     => $self->current_user,
-        scrip_action_obj => $self,
         scrip_obj        => $args{'scrip_obj'},
         template_obj     => $self->template_obj,
         ticket_obj       => $args{'ticket_obj'},
@@ -205,7 +204,6 @@
 
 sub prepare {
     my $self = shift;
-    $self->{_Message_ID} = 0;
     return ( $self->action->prepare() );
 
 }

Modified: rt/3.999/trunk/lib/RT/Model/ScripCondition.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Model/ScripCondition.pm	(original)
+++ rt/3.999/trunk/lib/RT/Model/ScripCondition.pm	Wed Apr  1 11:28:45 2009
@@ -144,7 +144,6 @@
     $self->{'condition'} = $type->new(
         'scrip_scrip_condition'  => $self,
         'ticket_obj'             => $args{'ticket_obj'},
-        'scrip_obj'              => $args{'scrip_obj'},
         'transaction_obj'        => $args{'transaction_obj'},
         'argument'               => $self->argument,
         'applicable_trans_types' => $self->applicable_trans_types,

Modified: rt/3.999/trunk/lib/RT/Model/Ticket.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Model/Ticket.pm	(original)
+++ rt/3.999/trunk/lib/RT/Model/Ticket.pm	Wed Apr  1 11:28:45 2009
@@ -2134,18 +2134,13 @@
     my $batch = $self->transaction_batch or return;
     return unless @$batch;
 
-    require RT::Model::ScripCollection;
-    RT::Model::ScripCollection->new( current_user => RT->system_user )->apply(
-        stage           => 'transaction_batch',
-        ticket_obj      => $self,
-        transaction_obj => $batch->[0],
-        type            => join( ',', map $_->type, grep defined, @{$batch} )
-    );
+    my $ticket = RT::Model::Ticket->new( current_user => RT::CurrentUser->superuser );
+    $ticket->load( $self->id );
 
     # Entry point of the rule system
     my $rules = RT::Ruleset->find_all_rules(
         stage           => 'transaction_batch',
-        ticket_obj      => $self,
+        ticket_obj      => $ticket,
         transaction_obj => $batch->[0],
         type            => join( ',', map $_->type, grep defined, @{$batch} )
     );

Modified: rt/3.999/trunk/lib/RT/Model/Transaction.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Model/Transaction.pm	(original)
+++ rt/3.999/trunk/lib/RT/Model/Transaction.pm	Wed Apr  1 11:28:45 2009
@@ -304,7 +304,6 @@
 use vars qw( %_brief_descriptions $Preferredcontent_type );
 
 use RT::Model::AttachmentCollection;
-use RT::Model::ScripCollection;
 use RT::Ruleset;
 
 
@@ -375,31 +374,18 @@
     #Provide a way to turn off scrips if we need to
     Jifty->log->debug( 'About to think about scrips for transaction #' . $self->id );
     if ( $activate_scrips and $args{'object_type'} eq 'RT::Model::Ticket' ) {
-        $self->{'scrips'} = RT::Model::ScripCollection->new( current_user => RT->system_user );
-
-        Jifty->log->debug( 'About to prepare scrips for transaction #' . $self->id );
-        $self->{'scrips'}->prepare(
-            stage       => 'transaction_create',
-            type        => $args{'type'},
-            ticket      => $args{'object_id'},
-            transaction => $self->id,
-        );
-
         # Entry point of the rule system
-        my $ticket = RT::Model::Ticket->new( current_user => RT->system_user );
+        my $ticket = RT::Model::Ticket->new( current_user => RT::CurrentUser->superuser );
         $ticket->load( $args{'object_id'} );
-        my $rules = RT::Ruleset->find_all_rules(
+        $self->{'active_rules'} = RT::Ruleset->find_all_rules(
             stage          => 'transaction_create',
             type           => $args{'type'},
             ticket_obj      => $ticket,
             transaction_obj => $self,
         );
-        
         if ( $commit_scrips ) {
             Jifty->log->debug( 'About to commit scrips for transaction #' . $self->id );
-            $self->{'scrips'}->commit;
-            RT::Ruleset->commit_rules($rules);
-            
+            RT::Ruleset->commit_rules($self->{'active_rules'});
         } else {
             Jifty->log->debug( 'Skipping commit of scrips for transaction #' . $self->id );
         }
@@ -418,8 +404,14 @@
 
 =cut
 
+sub rules {
+    my $self = shift;
+    return $self->{active_rules};
+}
+
 sub scrips {
     my $self = shift;
+    Carp::confess "obsoleted";
     return ( $self->{'scrips'} );
 }
 

Modified: rt/3.999/trunk/lib/RT/Rule.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Rule.pm	(original)
+++ rt/3.999/trunk/lib/RT/Rule.pm	Wed Apr  1 11:28:45 2009
@@ -54,6 +54,11 @@
 use constant _stage => 'transaction_create';
 use constant _queue => undef;
 
+sub _init {
+    my $self = shift;
+    $self->SUPER::_init(@_);
+}
+
 sub prepare {
     my $self = shift;
     return (0) if $self->_queue && $self->ticket_obj->queue->name ne $self->_queue;
@@ -80,6 +85,14 @@
 
 sub run_scrip_action {
     my ($self, $scrip_action, $template, %args) = @_;
+    my $action = $self->get_scrip_action($scrip_action, $template, %args);
+    $action->prepare or return;
+    $action->commit;
+}
+
+sub get_scrip_action {
+    my ($self, $scrip_action, $template, %args) = @_;
+
     my $ScripAction = RT::Model::ScripAction->new( current_user => $self->current_user);
     $ScripAction->load($scrip_action) or die ;
     unless (ref($template)) {
@@ -87,21 +100,20 @@
         #    $template->LoadQueueTemplate( Queue => ..., ) || $template->LoadGlobalTemplate(...)
 
         my $t = RT::Model::Template->new( current_user => $self->current_user);
-        $t->load($template) or die;
+        $t->load($template) or Carp::confess "Can't load template '$template'";
         $template = $t;
     }
 
-    my $action = $ScripAction->load_action( transaction_obj => $self->transaction,
-                                           ticket_obj => $self->ticket_obj,
-                                           %args,
-                                       );
+    my $action = $ScripAction->load_action(
+        transaction_obj         => $self->transaction,
+        ticket_obj              => $self->ticket_obj,
+        source_scripaction_name => $scrip_action,
+        %args,
+    );
 
     # XXX: fix template to allow additional arguments to be passed from here
     $action->{'template_obj'} = $template;
-    $action->{'scrip_obj'} = RT::Model::Scrip->new( current_user => $self->current_user); # Stub. sendemail action really wants a scripobj available
-    $action->prepare or return;
-    $action->commit;
-
+    return $action;
 }
 
 1;

Modified: rt/3.999/trunk/lib/RT/Ruleset.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Ruleset.pm	(original)
+++ rt/3.999/trunk/lib/RT/Ruleset.pm	Wed Apr  1 11:28:45 2009
@@ -59,9 +59,11 @@
 
 sub find_all_rules {
     my ($class, %args) = @_;
+    my $current_user = $args{ticket_obj}->current_user;
+
     return [
         grep { $_->prepare }
-        map { $_->new(current_user => RT->system_user, %args) }
+        map { $_->new(current_user => $current_user, %args) }
         grep { $_->_stage eq $args{stage} }
         map { @{$_->rules} } @RULE_SETS
     ];
@@ -73,12 +75,17 @@
         for @$rules;
 }
 
+sub register {
+    my ($class, $ruleset) = @_;
+    push @RULE_SETS, $ruleset;
+}
+
 sub add {
     my ($class, %args) = @_;
     for (@{$args{rules}}) {
         $_->require or die $UNIVERSAL::require::ERROR;
     }
-    push @RULE_SETS, $class->new(\%args);
+    $class->register($class->new(\%args));
 }
 
 1;

Modified: rt/3.999/trunk/lib/RT/ScripAction.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/ScripAction.pm	(original)
+++ rt/3.999/trunk/lib/RT/ScripAction.pm	Wed Apr  1 11:28:45 2009
@@ -83,8 +83,6 @@
     my %args = (
         argument       => undef,
         current_user    => undef,
-        scrip_action_obj => undef,
-        scrip_obj       => undef,
         template_obj    => undef,
         ticket_obj      => undef,
         transaction_obj => undef,
@@ -95,18 +93,15 @@
 
     $self->{'argument'} = $args{'argument'};
     $self->current_user( $args{'current_user'} );
-    $self->{'scrip_action_obj'} = $args{'scrip_action_obj'};
-    $self->{'scrip_obj'}       = $args{'scrip_obj'};
     $self->{'template_obj'}    = $args{'template_obj'};
     $self->{'ticket_obj'}      = $args{'ticket_obj'};
     $self->{'transaction_obj'} = $args{'transaction_obj'};
     $self->{'type'}           = $args{'type'};
 
-    Scalar::Util::weaken( $self->{'scrip_action_obj'} );
-    Scalar::Util::weaken( $self->{'scrip_obj'} );
+#    Scalar::Util::weaken( $self->{'scrip_action_obj'} );
     Scalar::Util::weaken( $self->{'template_obj'} );
-    Scalar::Util::weaken( $self->{'ticket_obj'} );
-    Scalar::Util::weaken( $self->{'transaction_obj'} );
+#    Scalar::Util::weaken( $self->{'ticket_obj'} );
+    Scalar::Util::weaken( $self->{'transaction'} );
 
 }
 
@@ -137,18 +132,6 @@
 }
 
 
-sub scrip_obj {
-    my $self = shift;
-    return ( $self->{'scrip_obj'} );
-}
-
-
-sub scrip_action_obj {
-    my $self = shift;
-    return ( $self->{'scrip_action_obj'} );
-}
-
-
 sub type {
     my $self = shift;
     return ( $self->{'Type'} );
@@ -180,6 +163,10 @@
     return ( 0, _("Prepare Stubbed") );
 }
 
+sub hints {
+    my ($self) = @_;
+    return { class => 'General' };
+}
 
 #If this rule applies to this transaction, return true.
 
@@ -194,8 +181,6 @@
 
     # We need to clean up all the references that might maybe get
     # oddly circular
-    $self->{'scrip_action_obj'} = undef;
-    $self->{'scrip_obj'}       = undef;
     $self->{'template_obj'}    = undef;
     $self->{'ticket_obj'} = undef;
     $self->{'transaction_obj'} = undef;

Modified: rt/3.999/trunk/lib/RT/ScripAction/SendEmail.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/ScripAction/SendEmail.pm	(original)
+++ rt/3.999/trunk/lib/RT/ScripAction/SendEmail.pm	Wed Apr  1 11:28:45 2009
@@ -228,6 +228,20 @@
     return $result;
 }
 
+=head2 hints
+
+=cut
+
+sub hints {
+    my ($self) = @_;
+
+    return { class => 'SendEmail',
+             recipients => { to =>  [$self->to],
+                             cc =>  [$self->cc],
+                             bcc => [$self->bcc],
+                         } };
+}
+
 =head2 to
 
 Returns an array of L<Email::Address> objects containing all the To: recipients for this notification
@@ -265,6 +279,7 @@
 sub addresses_from_header {
     my $self      = shift;
     my $field     = shift;
+    Carp::cluck unless $self->template_obj->mime_obj;
     my $header    = $self->template_obj->mime_obj->head->get($field);
     my @addresses = Email::Address->parse($header);
 
@@ -287,12 +302,13 @@
     my $msgid = $mime_obj->head->get('Message-ID');
     chomp $msgid;
 
-    $self->scrip_action_obj->{_Message_ID}++;
+    $self->{_Message_ID} ||= 0;
+    $self->{_Message_ID}++;
 
     Jifty->log->info( $msgid . " #" . $self->ticket_obj->id . "/" .
             $self->transaction->id . " - Scrip "
-            . ( $self->scrip_obj->id || '#rule' ) . " "
-            . ( $self->scrip_obj->description || '' ) );
+            . ( '#rule' ) . " ");
+
 
     my $status = RT::Interface::Email::send_email(
         entity      => $mime_obj,
@@ -585,19 +601,20 @@
         if (    $msgid
             and $msgid =~ s/<(rt-.*?-\d+-\d+)\.(\d+)-\d+-\d+\@\QRT->config->get('Organization')\E>$/
                          "<$1." . $self->ticket_obj->id
-                          . "-" . $self->scrip_obj->id
-                          . "-" . $self->scrip_action_obj->{_Message_ID}
+                          . "-" . '#rule'
+                          . "-" . $self->{_Message_ID}
                           . "@" . RT->config->get('Organization') . ">"/eg
             and $2 == $self->ticket_obj->id
             )
         {
             $self->set_header( "Message-ID" => $msgid );
         } else {
+            # XXX: only place calling gen_message_id with scrip and seq
             $self->set_header(
                 'Message-ID' => RT::Interface::Email::gen_message_id(
                     ticket       => $self->ticket_obj,
-                    scrip        => $self->scrip_obj,
-                    scrip_action => $self->scrip_action_obj
+                    scrip        => '#rule',
+                    sequence     => $self->{_Message_ID},
                 ),
             );
         }
@@ -1003,8 +1020,8 @@
         for ( @references, @in_reply_to ) {
             s/<(rt-.*?-\d+-\d+)\.(\d+-0-0)\@\Q$org\E>$/
           "<$1." . $self->ticket_obj->id .
-             "-" . $self->scrip_obj->id .
-             "-" . $self->scrip_action_obj->{_Message_ID} .
+             "-" . '#rule',
+             "-" . $self->{_Message_ID} .
              "@" . $org . ">"/eg
         }
 

Modified: rt/3.999/trunk/lib/RT/Shredder.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder.pm	(original)
+++ rt/3.999/trunk/lib/RT/Shredder.pm	Wed Apr  1 11:28:45 2009
@@ -218,7 +218,6 @@
     require RT::Shredder::Link;
     require RT::Shredder::Principal;
     require RT::Shredder::Queue;
-    require RT::Shredder::Scrip;
     require RT::Shredder::ScripAction;
     require RT::Shredder::ScripCondition;
     require RT::Shredder::Template;
@@ -239,7 +238,6 @@
     Link
     Principal
     Queue
-    Scrip
     ScripAction
     ScripCondition
     Template

Modified: rt/3.999/trunk/lib/RT/Shredder/Queue.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/Queue.pm	(original)
+++ rt/3.999/trunk/lib/RT/Shredder/Queue.pm	Wed Apr  1 11:28:45 2009
@@ -79,11 +79,6 @@
     $objs->limit( column => 'instance', value => $self->id );
     push( @$list, $objs );
 
-    # Scrips
-    $objs = RT::Model::ScripCollection->new( current_user => $self->current_user );
-    $objs->limit_to_queue( $self->id );
-    push( @$list, $objs );
-
     # Templates
     $objs = $self->templates;
     push( @$list, $objs );

Modified: rt/3.999/trunk/lib/RT/Shredder/ScripAction.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/ScripAction.pm	(original)
+++ rt/3.999/trunk/lib/RT/Shredder/ScripAction.pm	Wed Apr  1 11:28:45 2009
@@ -67,16 +67,6 @@
     my $deps = $args{'dependencies'};
     my $list = [];
 
-    # Scrips
-    my $objs = RT::Model::ScripCollection->new( current_user => $self->current_user );
-    $objs->limit( column => 'ScripAction', value => $self->id );
-    $deps->_push_dependencies(
-        base_object    => $self,
-        flags          => DEPENDS_ON,
-        target_objects => $objs,
-        shredder       => $args{'shredder'}
-    );
-
     return $self->SUPER::__depends_on(%args);
 }
 

Modified: rt/3.999/trunk/lib/RT/Shredder/ScripCondition.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/ScripCondition.pm	(original)
+++ rt/3.999/trunk/lib/RT/Shredder/ScripCondition.pm	Wed Apr  1 11:28:45 2009
@@ -67,15 +67,6 @@
     my $deps = $args{'dependencies'};
     my $list = [];
 
-    # Scrips
-    my $objs = RT::Model::ScripCollection->new( current_user => $self->current_user );
-    $objs->limit( column => 'ScripCondition', value => $self->id );
-    $deps->_push_dependencies(
-        base_object    => $self,
-        flags          => DEPENDS_ON,
-        target_objects => $objs,
-        shredder       => $args{'shredder'}
-    );
 
     return $self->SUPER::__depends_on(%args);
 }

Modified: rt/3.999/trunk/lib/RT/Shredder/Template.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/Template.pm	(original)
+++ rt/3.999/trunk/lib/RT/Shredder/Template.pm	Wed Apr  1 11:28:45 2009
@@ -67,18 +67,6 @@
     my $deps = $args{'dependencies'};
     my $list = [];
 
-    # Scrips
-    my $objs = RT::Model::ScripCollection->new( current_user => $self->current_user );
-    $objs->limit( column => 'template', value => $self->id );
-    push( @$list, $objs );
-
-    $deps->_push_dependencies(
-        base_object    => $self,
-        flags          => DEPENDS_ON,
-        target_objects => $list,
-        shredder       => $args{'shredder'},
-    );
-
     return $self->SUPER::__depends_on(%args);
 }
 

Modified: rt/3.999/trunk/lib/RT/Shredder/User.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Shredder/User.pm	(original)
+++ rt/3.999/trunk/lib/RT/Shredder/User.pm	Wed Apr  1 11:28:45 2009
@@ -69,7 +69,6 @@
     QueueCollection
     ScripActionCollection
     ScripConditionCollection
-    ScripCollection
     TemplateCollection
     ObjectCustomFieldValueCollection
     TicketCollection

Added: rt/3.999/trunk/sbin/shipwright-package
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/sbin/shipwright-package	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,42 @@
+export REPO=/Users/jesse/shipwright-rt/
+export SVN_PATH="svn:file://$REPO"
+export FS_REPO_PATH="fs:$REPO"
+
+export MIN_PERL=5.008006
+export SKIP="--skip=Apache2::Const,Apache::Request,Jifty,Jifty::DBI,DBD::Pg,DBD::Oracle,DBD::mysql" # --skip=Module::Signature,Test::Pod,Test::Pod::Coverage,Test::Distribution,Pod::Readme,Archive::Tar,Test::Script::Run,HTML::Lint,Prophet,Encode,Date::Calc"
+export IMPORT="shipwright import --min-perl-version=$MIN_PERL $SKIP -r $FS_REPO_PATH --log-file - --log-level info"
+rm -rf $REPO
+mkdir $REPO
+#svnadmin create $REPO
+shipwright create -r $FS_REPO_PATH
+# Optional deps we sitll want
+$IMPORT --name cpan-Jifty-DBI svn:http://svn.jifty.org/svn/jifty.org/Jifty-DBI/trunk
+$IMPORT --name cpan-Jifty svn:http://svn.jifty.org/svn/jifty.org/jifty/trunk
+$IMPORT --name RT svn://svn.bestpractical.com/rt/3.999/trunk
+$IMPORT cpan:Symbol
+
+#cd /tmp
+#rm -rf sdrt
+#shipwright update -r $SVN_PATH Jifty --add-deps Jifty-DBI
+#shipwright update -r $SVN_PATH RT           --add-deps Jifty
+shipwright update -r $FS_REPO_PATH cpan-Encode           --add-deps cpan-Symbol
+#shipwright maintain -r $SVN_PATH --update-order
+
+
+#cd /tmp
+#mkdir svnhack-$$
+#cd svnhack-$$
+#svn co file://${REPO}/scripts/cpan-DateTime-Format-Natural
+#cd cpan-DateTime-Format-Natural
+#perl -pi -e s'/Build test/Build/g' build
+#svn commit -m 'Made DTFN not run its tests which add a slew of deps' build
+#cd ..
+#svn co file://${REPO}/sources/cpan-Net-Bonjour/vendor
+#cd vendor
+#perl -pi -e's/^chomp.*?STDIN.*?$/my \$ans = "n";/g;' Makefile.PL
+#svn commit -m 'Made Net::Bonjour not promtp ' Makefile.PL
+#
+#
+#svn export file://$REPO /tmp/sdrt
+#rsync -rvp /tmp/sdrt/ jesse at fsck.com:/tmp/sdex-$$
+#echo "cd /tmp/sdrt-$$; ./bin/shipwright-builder"

Modified: rt/3.999/trunk/share/html/Admin/Elements/ListGlobalScrips
==============================================================================
--- rt/3.999/trunk/share/html/Admin/Elements/ListGlobalScrips	(original)
+++ rt/3.999/trunk/share/html/Admin/Elements/ListGlobalScrips	Wed Apr  1 11:28:45 2009
@@ -46,25 +46,7 @@
 %# 
 %# END BPS TAGGED BLOCK }}}
 
-% unless ( $Scrips->count ) {
 <p><i><&|/l&>(No scrips)</&></i></p>
-% } else {
-<& /Elements/CollectionList,
-    order_by => 'description',
-    order => 'ASC',
-    rows  => 0,
-    %ARGS,
-    format => $format,
-    collection => $Scrips,
-    show_header => 0,
-&>
-% }
 
 <%init>
-my $format = q{'<a href="__WebPath__/Admin/Global/Scrip.html?id=__id__&Queue=0">__id__</a>/TITLE:#'}
-    .q{,'<a href="__WebPath__/Admin/Global/Scrip.html?id=__id__&Queue=0">__Autodescription__</a>/TITLE:Condition, Action and Template'}
-    .q{__NEWLINE__,'','<small>__description__</small>'};
-
-my $Scrips = RT::Model::ScripCollection->new( current_user => Jifty->web->current_user );
-$Scrips->limit_to_global;
 </%init>

Modified: rt/3.999/trunk/share/html/Ticket/Elements/PreviewScrips
==============================================================================
--- rt/3.999/trunk/share/html/Ticket/Elements/PreviewScrips	(original)
+++ rt/3.999/trunk/share/html/Ticket/Elements/PreviewScrips	Wed Apr  1 11:28:45 2009
@@ -50,32 +50,37 @@
 
 </%args>
 <%init>
+###### XXX: this needs to be ported to introspect lorzy
+
 my %squelch = $m->comp('SELF:SquelchRecipients', %ARGS);
-my $object = $squelch{'object'};
+my $recipients = $squelch{'recipients'};
 my @non_recipients = @{ $squelch{'emails'} };
 
 </%init>
 <h2><&|/l&>This message will be sent to...</&></h2>
 
-% if ( $object and $object->scrips ) {
+% if ( my @rules = keys %{$recipients} ) {
 <i><&|/l&>(Check boxes to disable notifications to the listed recipients)</&></i><br />
 
-% foreach my $scrip (@{$object->scrips->prepared}) {
-% next unless $scrip->scrip_action->action->isa('RT::ScripAction::SendEmail');
-<b><% $scrip->description || _('Scrip #%1',$scrip->id) %></b><br />
-<&|/l, _($scrip->scrip_condition->name), _($scrip->scrip_action->name), _($scrip->template_obj->name)&>%1 %2 with template %3</&>
+% foreach my $rule (@rules) {
+<b><% $rule %></b><br />
+%# XXX: hints should give template info as well, condition might come
+ # from other places
+%#<&|/l, _($scrip->scrip_condition->name), _($scrip->scrip_action->name), _($scrip->template_obj->name)&>%1 %2 with template %3</&>
 <br />
 %foreach my $type qw(to cc bcc) {
-%my @addresses =  $scrip->scrip_action->action->$type();
+%my @addresses =  @{$recipients->{$rule}{$type}};
+%#warn Dumper(\@address)
 <ul>
 %foreach my $addr (@addresses) {
 <li> <b><%_($type)%></b>: <input type="checkbox" class="checkbox" name="Ticket-<%$ticket_obj->id%>-SquelchMailTo" value="<%$addr->address%>" /> <%$addr->address%>
 % }
 </ul>
 % }
-% if (RT->config->get('PreviewScripMessages')) {
+%# later
+% if (0 && RT->config->get('PreviewScripMessages')) {
 <textarea cols="80" rows="5">
-<%$scrip->scrip_action->template_obj->mime_obj->as_string%>
+<%#$scrip->scrip_action->template_obj->mime_obj->as_string%>
 </textarea>
 % }
 % }
@@ -128,19 +133,26 @@
     body    => $ARGS{'update_content'},
 );
 
-my ( $Transaction, $description, $object ) = $ticket_obj->$action(
+my ( $txn_id, $description, $txn ) = $ticket_obj->$action(
     cc_message_to  => $ARGS{'update_cc'},
     bcc_message_to => $ARGS{'update_bcc'},
     mime_obj      => $Message,
     time_taken    => $ARGS{'update_time_worked'},
     dry_run       => 1
 );
-unless ( $Transaction ) {
+
+unless ( $txn_id ) {
     Jifty->log->error("Coulfn't fire '$action' action: $description");
 }
 
+my $recipients = {};
+for (@{$txn->rules}) {
+    my $hints = $_->hints;
+    next unless $hints->{class} eq 'SendEmail';
+    $recipients->{$_->description} = $hints->{recipients};
+}
 
-return (object => $object, emails => [$ticket_obj->squelch_mail_to]);
+return (recipients => $recipients, emails => [$ticket_obj->squelch_mail_to]);
 </%INIT>
 </%METHOD>
 
@@ -177,12 +189,12 @@
 }
 
 my @recipients;
-foreach my $scrip ( @{ $txn->scrips->prepared } ) {
-    my $action = $scrip->scrip_action->action;
-    next unless $action->isa('RT::ScripAction::SendEmail');
+foreach my $rule ( @{ $txn->rules } ) {
+    my $hints = $rule->hints;
+    next unless $hints->{class} eq 'SendEmail';
 
     foreach my $type qw(to cc bcc) {
-        push @recipients, $action->$type();
+        push @recipients, @{$hints->{recipients}{$type}};
     }
 }
 return @recipients;
@@ -222,12 +234,12 @@
 }
 
 my @recipients;
-foreach my $scrip ( @{ $txn->scrips->prepared } ) {
-    my $action = $scrip->scrip_action->action;
-    next unless $action->isa('RT::ScripAction::SendEmail');
+foreach my $rule ( @{ $txn->rules } ) {
+    my $hints = $rule->hints;
+    next unless $hints->{class} eq 'SendEmail';
 
     foreach my $type qw(to cc bcc) {
-        push @recipients, $action->$type();
+        push @recipients, @{$hints->{recipients}{$type}};
     }
 }
 return @recipients;

Modified: rt/3.999/trunk/t/00-compile.t
==============================================================================
--- rt/3.999/trunk/t/00-compile.t	(original)
+++ rt/3.999/trunk/t/00-compile.t	Wed Apr  1 11:28:45 2009
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT::Test;
-use Test::More tests => 33;
+use Test::More tests => 32;
 
 require_ok("RT");
 require_ok("RT::Test");
@@ -12,7 +12,6 @@
 require_ok("RT::Interface::Email");
 require_ok("RT::Model::LinkCollection");
 require_ok("RT::Model::QueueCollection");
-require_ok("RT::Model::ScripCollection");
 require_ok("RT::Model::TemplateCollection");
 require_ok("RT::Model::PrincipalCollection");
 require_ok("RT::Model::AttachmentCollection");

Modified: rt/3.999/trunk/t/api/action-createtickets.t
==============================================================================
--- rt/3.999/trunk/t/api/action-createtickets.t	(original)
+++ rt/3.999/trunk/t/api/action-createtickets.t	Wed Apr  1 11:28:45 2009
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use RT::Test; use Test::More; 
-plan tests => 49;
+plan tests => 43;
 use RT;
 
 
@@ -10,7 +10,6 @@
 {
 
 ok (require RT::ScripAction::CreateTickets);
-use_ok('RT::Model::Scrip');
 use_ok('RT::Model::Template');
 use_ok('RT::Model::ScripAction');
 use_ok('RT::Model::ScripCondition');
@@ -56,16 +55,15 @@
 $q->create(name => 'WorkflowTest');
 ok ($q->id, "Created workflow test queue");
 
-my $scrip = RT::Model::Scrip->new(current_user => RT->system_user);
-my ($sval, $smsg) =$scrip->create( scrip_condition => 'On Transaction',
-                scrip_action => 'Create Tickets',
-                template => 'Approvals',
-                queue => $q->id);
-ok ($sval, $smsg);
-ok ($scrip->id, "Created the scrip");
-ok ($scrip->template_obj->id, "Created the scrip template");
-ok ($scrip->scrip_condition->id, "Created the scrip condition");
-ok ($scrip->scrip_action->id, "Created the scrip action");
+my $rule_factory = 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 );
 
 my $t = RT::Model::Ticket->new(current_user => RT->system_user);
 my($tid, $ttrans, $tmsg) = $t->create(subject => "Sample workflow test",

Added: rt/3.999/trunk/t/api/rules-preview.t
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/t/api/rules-preview.t	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+use strict;
+use RT::Test; use Test::More tests => 5;
+use_ok('RT::Interface::Web');
+my $queue = RT::Model::Queue->new(current_user => RT->system_user );
+$queue->create( name => 'RecordCustomFields-'.$$ );
+ok ($queue->id, "Created the queue" . $queue->id);
+
+my $ticket = RT::Model::Ticket->new(current_user => RT->system_user );
+$ticket->create(
+	queue => $queue->id,
+	requestor => 'root at localhost',
+	cc => 'moosecc at example.org',
+	subject => 'scrip preview test',
+);
+
+ok($ticket->id, "Created the ticket ok");
+
+our $DEBUG=1;
+
+my ( $txn_id, $description, $txn ) = $ticket->correspond(
+    cc_message_to => 'onetime at example.org',
+    content       => 'test dry run and previews',
+    time_taken    => '10',
+    dry_run       => 1,
+);
+
+ok($txn_id, 'created txn');
+
+my $preview = {};
+for (@{$txn->rules}) {
+    my $hints = $_->hints;
+    next unless $hints->{class} eq 'SendEmail';
+    $preview->{$_->description} = $hints->{recipients};
+}
+
+is_deeply($preview,
+          { 'On Correspond Notify Other Recipients' =>
+            { to => ['onetime at example.org'], cc => [], bcc => [] },
+            'On Correspond Notify requestors and ccs' =>
+            { to => [ 'root at localhost' ],
+              cc => [ 'moosecc at example.org' ],
+              bcc => [] },
+            'On Correspond Notify admin_ccs' =>
+            { to => [], cc => [], bcc => [] } }
+      );
+

Modified: rt/3.999/trunk/t/api/scrip_order.t
==============================================================================
--- rt/3.999/trunk/t/api/scrip_order.t	(original)
+++ rt/3.999/trunk/t/api/scrip_order.t	Wed Apr  1 11:28:45 2009
@@ -4,8 +4,8 @@
 use RT::Test; use Test::More tests => 7;
 
 use RT;
-
-
+SKIP: {
+skip 'port this test to lorzy', 7;
 
 # {{{ test scrip ordering based on description
 
@@ -53,5 +53,5 @@
 is  ($ticket->priority , 10, "Ticket should be priority 10");
 
 # }}}
-
+}
 1;

Modified: rt/3.999/trunk/t/approval/basic.t
==============================================================================
--- rt/3.999/trunk/t/approval/basic.t	(original)
+++ rt/3.999/trunk/t/approval/basic.t	Wed Apr  1 11:28:45 2009
@@ -8,7 +8,7 @@
         or plan skip_all => 'require Email::Abstract and Test::Email';
 }
 
-plan tests => 37;
+plan tests => 32;
 
 use RT;
 use RT::Test;
@@ -69,17 +69,16 @@
 $q->create(name => 'PO');
 ok ($q->id, "Created PO queue");
 
-my $scrip = RT::Model::Scrip->new(current_user => RT->system_user);
-my ($sval, $smsg) =$scrip->create( scrip_condition => 'On Create',
-                scrip_action => 'Create Tickets',
-                template => 'PO Approvals',
-                queue => $q->id,
-                description => 'Create Approval Tickets');
-ok ($sval, $smsg);
-ok ($scrip->id, "Created the scrip");
-ok ($scrip->template_obj->id, "Created the scrip template");
-ok ($scrip->scrip_condition->id, "Created the scrip condition");
-ok ($scrip->scrip_action->id, "Created the scrip action");
+# XXX: limit to one queue
+my $rule_factory = RT::Lorzy->create_scripish(
+    'On Create',
+    'Create Tickets',
+    'PO Approvals',
+    $q->id,
+);
+
+my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+$rule->create_from_factory( $rule_factory );
 
 my $t = RT::Model::Ticket->new(current_user => RT->system_user);
 my ($tid, $ttrans, $tmsg);
@@ -89,14 +88,14 @@
         $t->create(subject => "PO for stationary",
                    owner => "root", requestor => $users{minion}->email,
                    queue => $q->id);
-} { from => qr/RT System/,
-    to => 'cfo at company.com',
-    subject => qr/New Pending Approval: CFO Approval/,
-    body => qr/pending your approval.*Your approval is requested.*Blah/s
-},{ from => qr/PO via RT/,
+} { from => qr/PO via RT/,
     to => 'minion at company.com',
     subject => qr/PO for stationary/,
     body => qr/automatically generated in response/
+},{ from => qr/RT System/,
+    to => 'cfo at company.com',
+    subject => qr/New Pending Approval: CFO Approval/,
+    body => qr/pending your approval.*Your approval is requested.*Blah/s
 };
 
 ok ($tid,$tmsg);

Added: rt/3.999/trunk/t/lorzy/action.t
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/t/lorzy/action.t	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,77 @@
+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 RT::Test::Email;
+
+use_ok('Lorzy');
+use_ok('RT::Lorzy');
+
+my $tree    = [ { name => 'IfThen',
+                  args => { if_true => { name => 'True' },
+                            if_false => { name => 'False' },
+                            condition => { name => 'RT.Condition.Applicable',
+                                args => {
+                                    name => "On Create",
+                                    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' ) }
+);
+
+$tree    = [ { name => 'RT.ScripAction.Run',
+               args => {
+                   name => "Autoreply To requestors",
+                   template => "Autoreply",
+                   context => { name => 'Symbol', args => { symbol => 'context' } },
+                   ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+                   transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
+               } } ];
+my $auto_reply  = $builder->defun(
+    ops => $tree,
+    signature =>
+        { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+          context => Lorzy::FunctionArgument->new( name => 'context', type => 'HASH' ),
+          transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) }
+);
+
+RT::Lorzy::Dispatcher->reset_rules;
+
+RT::Lorzy::Dispatcher->add_rule(
+    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' );
+
+my $ticket = RT::Model::Ticket->new(current_user => RT->system_user );
+mail_ok {
+lives_ok {
+my ($rv, $msg) = $ticket->create( subject => 'lorzy test', queue => $queue->name, requestor => 'foo at localhost' );
+};
+} { from => qr/lorzy via RT/,
+    to => 'foo at localhost',
+    subject => qr'AutoReply: lorzy test',
+    body => qr/automatically generated/,
+};

Added: rt/3.999/trunk/t/lorzy/basic.t
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/t/lorzy/basic.t	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,77 @@
+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 });
+

Added: rt/3.999/trunk/t/lorzy/condition.t
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/t/lorzy/condition.t	Wed Apr  1 11:28:45 2009
@@ -0,0 +1,58 @@
+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.Applicable',
+                  args => {
+                      name => "On Create",
+                      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);
+

Modified: rt/3.999/trunk/t/mail/sendmail.t
==============================================================================
--- rt/3.999/trunk/t/mail/sendmail.t	(original)
+++ rt/3.999/trunk/t/mail/sendmail.t	Wed Apr  1 11:28:45 2009
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use RT::Test; use Test::More tests => 131;
+use RT::Test; use Test::More tests => 117;
 use File::Spec ();
 
 
@@ -27,7 +27,7 @@
         my $self = shift;
         my $MIME = shift;
 
-        main::_fired_scrip($self->scrip_obj);
+        main::_fired_scrip('#rule');
         main::is(ref($MIME) , 'MIME::Entity', "hey, look. it's a mime entity");
     }
 }
@@ -199,9 +199,7 @@
         my $self = shift;
         my $MIME = shift;
 
-        my $scrip = $self->scrip_obj->id;
-        ok(1, $self->scrip_obj->scrip_condition->name . " ".$self->scrip_obj->scrip_action->name);
-        main::_fired_scrip($self->scrip_obj);
+        main::_fired_scrip("#rule");
         $MIME->make_singlepart;
         main::is( ref($MIME) , \'MIME::Entity\',
                   "hey, look. it\'s a mime entity" );
@@ -226,9 +224,7 @@
         my $self = shift;
         my $MIME = shift;
 
-        my $scrip = $self->scrip_obj->id;
-        ok(1, $self->scrip_obj->scrip_condition->name . " ".$self->scrip_obj->scrip_action->name);
-        main::_fired_scrip($self->scrip_obj);
+        main::_fired_scrip("#rule");
         $MIME->make_singlepart;
         main::is( ref($MIME) , \'MIME::Entity\',
                   "hey, look. it\'s a mime entity" );
@@ -305,7 +301,7 @@
     eval 'sub RT::ScripAction::SendEmail::send_message { 
                 my $self = shift;
                 my $MIME = shift;
-                return (1) unless ($self->scrip_obj->scrip_action->name eq "Notify AdminCcs" );
+                return (1) unless ($self->hints->{source_scripaction_name} eq "Notify AdminCcs" );
                 is ($MIME->parts, 0, "generated correspondence mime entity
                         does not have parts");
                 is ($MIME->head->mime_type , "text/plain", "The mime type is a plain");
@@ -369,7 +365,7 @@
     eval 'sub RT::ScripAction::SendEmail::send_message { 
                 my $self = shift; 
                 my $MIME = shift; 
-                return (1) unless ($self->scrip_obj->scrip_action->name eq "Notify AdminCcs" );
+                return (1) unless ($self->hints->{source_scripaction_name} eq "Notify AdminCcs" );
                 is ($MIME->head->mime_type , "text/plain", "The only part is text/plain ");
                  my $subject  = $MIME->head->get("subject");
                 chomp($subject);
@@ -412,7 +408,7 @@
     eval 'sub RT::ScripAction::SendEmail::send_message { 
                 my $self = shift; 
                 my $MIME = shift; 
-                return (1) unless ($self->scrip_obj->scrip_action->name eq "Notify AdminCcs" );
+                return (1) unless ($self->hints->{source_scripaction_name} eq "Notify AdminCcs" );
                 is ($MIME->head->mime_type , "multipart/mixed", "It is a mixed multipart");
                  my $subject  =  $MIME->head->get("subject");
                  $subject  = MIME::Base64::decode_base64( $subject);

Modified: rt/3.999/trunk/t/shredder/02queue.t
==============================================================================
--- rt/3.999/trunk/t/shredder/02queue.t	(original)
+++ rt/3.999/trunk/t/shredder/02queue.t	Wed Apr  1 11:28:45 2009
@@ -9,7 +9,7 @@
 use RT::Test::Shredder;
 RT::Test::Shredder::init_db();
 
-plan tests => 16;
+plan tests => 13;
 
 diag 'simple queue' if $ENV{'TEST_VERBOSE'};
 {
@@ -24,29 +24,6 @@
 	cmp_deeply( RT::Test::Shredder::dump_current_and_savepoint('clean'), "current DB equal to savepoint");
 }
 
-diag 'queue with scrip' if $ENV{'TEST_VERBOSE'};
-{
-	RT::Test::Shredder::create_savepoint('clean');
-    my $queue = RT::Model::Queue->new(current_user => RT->system_user );
-    my ($id, $msg) = $queue->create( name => 'my queue' );
-    ok($id, 'Created queue') or diag "error: $msg";
-
-    my $scrip = RT::Model::Scrip->new(current_user => RT->system_user );
-    ($id, $msg) = $scrip->create(
-        description    => 'my scrip',
-        queue          => $queue->id,
-        scrip_condition => 'On Create',
-        scrip_action    => 'Open Tickets',
-        template       => 'Blank',
-    );
-    ok($id, 'Created scrip') or diag "error: $msg";
-
-	my $shredder = RT::Test::Shredder::shredder_new();
-	$shredder->put_objects( objects => $queue );
-	$shredder->wipeout_all;
-	cmp_deeply( RT::Test::Shredder::dump_current_and_savepoint('clean'), "current DB equal to savepoint");
-}
-
 diag 'queue with template' if $ENV{'TEST_VERBOSE'};
 {
 	RT::Test::Shredder::create_savepoint('clean');

Modified: rt/3.999/trunk/t/shredder/02template.t
==============================================================================
--- rt/3.999/trunk/t/shredder/02template.t	(original)
+++ rt/3.999/trunk/t/shredder/02template.t	Wed Apr  1 11:28:45 2009
@@ -9,7 +9,7 @@
 use RT::Test::Shredder;
 RT::Test::Shredder::init_db();
 
-plan tests => 7;
+plan tests => 4;
 
 diag 'global template' if $ENV{'TEST_VERBOSE'};
 {
@@ -44,29 +44,3 @@
 	cmp_deeply( RT::Test::Shredder::dump_current_and_savepoint('clean'), "current DB equal to savepoint");
 }
 
-diag 'template used in scrip' if $ENV{'TEST_VERBOSE'};
-{
-	RT::Test::Shredder::create_savepoint('clean');
-    my $template = RT::Model::Template->new(current_user => RT->system_user );
-    my ($id, $msg) = $template->create(
-        name => 'my template',
-        queue => 'General',
-        content => "\nsome content",
-    );
-    ok($id, 'Created template') or diag "error: $msg";
-
-    my $scrip = RT::Model::Scrip->new(current_user => RT->system_user );
-    ($id, $msg) = $scrip->create(
-        description    => 'my scrip',
-        queue          => 'General',
-        scrip_condition => 'On Create',
-        scrip_action    => 'Open Tickets',
-        template       => $template->id,
-    );
-    ok($id, 'Created scrip') or diag "error: $msg";
-
-	my $shredder = RT::Test::Shredder::shredder_new();
-	$shredder->put_objects( objects => $template );
-	$shredder->wipeout_all;
-	cmp_deeply( RT::Test::Shredder::dump_current_and_savepoint('clean'), "current DB equal to savepoint");
-}


More information about the Rt-commit mailing list