Trigger - Trigger framework
use Trigger; my $trigger = Trigger->new( inline_states => { heap => {}, # \%hash or \@array or \$scalar or \&sub or object init => sub { my $context = shift; my $heap = $context->heap; # Initial processing }, process => sub { my $context = shift; my $heap = $context->heap; my @args = @_; # Main processing }, trigger_and_action => [ sub { # trigger # The place which defines conditions. my $context = shift; my $heap = $context->heap; my @args = @_; # The return value of 'process' # 'trigger' must return a value or must return FALSE. # ex.) defined $result ? return $result : return; } => sub { # action my $context = shift; my $heap = $context->heap; # Processing to carry out when a condition was satisfied # 'action' will be performed if 'trigger' returns true. my @trigger_re = @_; # The return value of 'trigger' }, # One or more triggers and actions can be defined. sub { # trigger # : } => [ # The reference of arrangement can define two or more "actions." # "Action" is performed by the defined turn. sub { # action my $context = shift; my $heap = $context->heap; # : }, sub { # action my $context = shift; my $heap = $context->heap; # : }, ], ], end => sub { my $context = shift; my $heap = $context->heap; # Post-processing }, } ); while ( @list ){ my @args = split /,/, $_; my $result = $trigger->eval(@args) or last; # It evaluates whether the conditions of a trigger are fulfilled. }
When conditions (Triggers) are set, the specified action will be processed automatically. More than one Trigger and action can be defined.
A trigger and action are defined.
The result of an eval method returned the result processed by 'process'. When the conditions of a trigger are fulfilled, the result of action serves as a return value of an eval method. When one or more triggers are defined, the return value of action performed at the end turns into a return value of an eval method.
Yuji Suzuki <yuji.suzuki.perl@gmail.com>
http://arbolbell.jp/ # Japanese only
Please report any bugs or feature requests to bug-trigger at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Trigger. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-trigger at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Trigger
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Trigger
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Trigger
CPAN Ratings
http://cpanratings.perl.org/d/Trigger
Search CPAN
http://search.cpan.org/dist/Trigger
Copyright 2007 Yuji Suzuki, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Trigger, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Trigger
CPAN shell
perl -MCPAN -e shell install Trigger
For more information on module installation, please visit the detailed CPAN module installation guide.