[Rt-commit] r18827 - in rt/3.999/branches/lorzy: lib/RT lib/RT/Lorzy lib/RT/Lorzy/Package lib/RT/Model t/api
clkao at bestpractical.com
clkao at bestpractical.com
Tue Mar 17 13:25:30 EDT 2009
Author: clkao
Date: Tue Mar 17 13:25:30 2009
New Revision: 18827
Added:
rt/3.999/branches/lorzy/t/api/rules-preview.t
Modified:
rt/3.999/branches/lorzy/TODO.lorzy
rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm
rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm
rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm
rt/3.999/branches/lorzy/lib/RT/Rule.pm
rt/3.999/branches/lorzy/lib/RT/ScripAction.pm
Log:
wip for rule and lorzy rule hinting subsystem.
Modified: rt/3.999/branches/lorzy/TODO.lorzy
==============================================================================
--- rt/3.999/branches/lorzy/TODO.lorzy (original)
+++ rt/3.999/branches/lorzy/TODO.lorzy Tue Mar 17 13:25:30 2009
@@ -1,41 +1,4 @@
-*** scrip actions
-
-* scrip action =>
-
- { name => 'Autoreply To requestors', # loc
- description =>
-'Always sends a message to the requestors independent of message sender' , # loc
- exec_module => 'Autoreply', # scripaction::autoreply
- argument => 'requestor' }, # passed over to scripaction
-
-
-* script condition =>
-
- { name => 'On Create', # referenced by scrip objects
- description => 'When a ticket is Created',
- applicable_trans_types => 'Create', # matched in Scrip::is_applicable
- exec_module => 'AnyTransaction', }, # a module
-
-* scrip =>
-
-
- { description => 'On Create Autoreply To requestors',
- scrip_condition => 'On Create', # reference to script_condition objects
- scrip_action => 'AutoReply To requestors',
- template => 'AutoReply' },
-
-script::condition: exec_mode for matching
-
-
-# to return a testing closure for a simplified trans_type and field etc matching?
-
-*** lorzy
-
-* Lorzy::Dispatcher: registered rule, may have to have two instances for both Stages.
-
-
-* for queue exceptions, we can simply insert some sort of
-
+* hinting subsystem: fix coderef passing and callback in lorzy
* lorzy code improvements: control flow handling like return, exception
@@ -49,4 +12,4 @@
- commit
- run_scrip_action("AutoReply", "requestor")
- - RT.Action.SendEmail( template => 'autoreply', etc etc )
\ No newline at end of file
+ - RT.Action.SendEmail( template => 'autoreply', etc etc )
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy.pm Tue Mar 17 13:25:30 2009
@@ -64,14 +64,27 @@
} } ],
signature => $sigs );
+ my $hints = $builder->defun(
+ ops => [ { name => 'RT.ScripAction.Hints',
+ args => {
+ name => $scrip_action,
+ template => $template,
+ ticket => { name => 'Symbol', args => { symbol => 'ticket' } },
+ callback => { name => 'Symbol', args => { symbol => 'callback' } },
+ transaction => { name => 'Symbol', args => { symbol => 'transaction' } },
+ } } ],
+ signature => {%$sigs,
+ callback => Lorzy::FunctionArgument->new( name => 'callback', type => 'CODE' ) } );
+
RT::Lorzy::Rule->new(
- { condition => $condition,
- action => $action } )
+ { condition => $condition,
+ collect_hints => $hints,
+ action => $action } )
}
package RT::Lorzy::Rule;
use base 'Class::Accessor::Fast';
-__PACKAGE__->mk_accessors(qw(condition action));
+__PACKAGE__->mk_accessors(qw(condition action collect_hints));
sub new {
my $class = shift;
@@ -93,6 +106,12 @@
return RT::Lorzy->evaluate( $self->condition, ticket => $ticket_obj, transaction => $transaction_obj);
}
+sub hints {
+ my ($self, $ticket_obj, $transaction_obj, $hints) = @_;
+ return unless $self->collect_hints;
+ return RT::Lorzy->evaluate( $self->collect_hints, ticket => $ticket_obj, transaction => $transaction_obj, callback => 1);
+}
+
sub commit {
my ($self, $ticket_obj, $transaction_obj) = @_;
return RT::Lorzy->evaluate( $self->action, ticket => $ticket_obj, transaction => $transaction_obj);
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy/Dispatcher.pm Tue Mar 17 13:25:30 2009
@@ -29,4 +29,14 @@
}
}
+sub hints {
+ my ($self, $callback) = @_;
+ warn "... hi hints".$self->transaction->object;
+ warn "... hi hints".$self->transaction;
+ return unless $self->transaction->object;
+ for ( @{$self->{prepared}} ) {
+ $_->hints( $self->transaction->object, $self->transaction, $callback );
+ }
+}
+
1;
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm Tue Mar 17 13:25:30 2009
@@ -47,4 +47,22 @@
},
);
+__PACKAGE__->defun( 'ScripAction.Hints',
+ signature => {
+ 'name' => Lorzy::FunctionArgument->new( name => 'name' ),
+ 'template' => Lorzy::FunctionArgument->new( name => 'template' ),
+ 'callback' => Lorzy::FunctionArgument->new( name => 'callback' ),
+ '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}
+ );
+ $rule->scrip_action_hints(@{$args}{qw(name template callback)});
+ },
+);
+
1;
Modified: rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Model/Transaction.pm Tue Mar 17 13:25:30 2009
@@ -377,17 +377,15 @@
# Entry point of the rule system
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 );
- RT::Ruleset->commit_rules($rules);
-
+ RT::Ruleset->commit_rules($self->{'active_rules'});
} else {
Jifty->log->debug( 'Skipping commit of scrips for transaction #' . $self->id );
}
@@ -406,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/branches/lorzy/lib/RT/Rule.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Rule.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Rule.pm Tue Mar 17 13:25:30 2009
@@ -80,6 +80,21 @@
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 scrip_action_hints {
+ my ($self, $scrip_action, $template, $callback, %args) = @_;
+ my $action = $self->_get_scrip_action($scrip_action, $template, %args);
+ $action->prepare or return;
+ $action->hints($callback);
+}
+
+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)) {
@@ -100,9 +115,7 @@
# XXX: fix template to allow additional arguments to be passed from here
$action->{'template_obj'} = $template;
- $action->prepare or return;
- $action->commit;
-
+ return $action;
}
1;
Modified: rt/3.999/branches/lorzy/lib/RT/ScripAction.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/ScripAction.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/ScripAction.pm Tue Mar 17 13:25:30 2009
@@ -102,10 +102,10 @@
$self->{'type'} = $args{'type'};
$self->{'hints'} = $args{'hints'};
- Scalar::Util::weaken( $self->{'scrip_action_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->{'transaction'} );
}
Added: rt/3.999/branches/lorzy/t/api/rules-preview.t
==============================================================================
--- (empty file)
+++ rt/3.999/branches/lorzy/t/api/rules-preview.t Tue Mar 17 13:25:30 2009
@@ -0,0 +1,49 @@
+#!/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',
+ subject => 'scrip preview test',
+);
+
+ok($ticket->id, "Created the ticket ok");
+
+our $DEBUG=1;
+
+my ( $txn_id, $description, $txn ) = $ticket->correspond(
+ content => 'test dry run and previews',
+ time_taken => '10',
+ dry_run => 1,
+);
+
+ok($txn_id, 'created txn');
+
+diag $txn;
+diag $description;
+diag $txn_id;
+
+my $preview = {};
+
+sub hints_callback {
+ my ($action_class, $description, $key, $value) = @_;
+ if ($action_class eq 'SendEmail') {
+ push @{$preview->{$description}{$key} ||= []}, $value;
+ }
+}
+
+for (@{$txn->rules}) {
+ warn $_;
+# warn Dumper($_);
+ $_->hints(\&hints_callback);
+}
+
+warn Dumper($preview);
+
+use Data::Dumper;
More information about the Rt-commit
mailing list