Trigger - Trigger framework
use Trigger; my $trigger = Trigger->new( inline_states => { heap => {}, # \%hash or \@array or \$scalar or \&sub or object init => sub { my $heap = shift; # 初期処理 }, process => sub { my $context = shift; my $heap = $context->heap; my @args = @_; # eval メソッドの引数 # メイン処理 }, trigger_and_action => [ sub { # trigger # トリガーとなる条件を定義するところ my $context = shift; my $heap = $context->heap; my @args = @_; # 'process'の戻り値をパラメータとして受け取る # 'trigger'は、値を返すか又はFALSEを返さなければならない。 # false を戻り値としたい場合、return 0 としてはならない、 # false を戻り値としたい場合は、ただ単に return と書くこと。 # 例)defined $result ? return $result : return; } => sub { # action # 'trigger'にの戻り値がある場合に実行される アクションを定義する。 my $context = shift; my $heap = $context->heap; # トリガーの戻り値をパラメータとして受け取る my @trigger_re = @_; }, # 'trigger'と'action'は、対で定義する必要がある。 # 複数の'trigger'を定義することができます。 sub { # trigger my $context = shift; my $heap = $context->heap; # : } => [ # 「アクション」を配列のリファレンスで複数定義できます。 # 定義した順番に「アクション」は実行されます。 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; # 後処理 # 例えばファイルハンドルをClose、DBのdisconnectなど。 }, } ); while ( @list ){ my @args = split /,/, $_; my $result = $trigger->eval(@args) or last; }
条件(トリガ)がセットされる時、指定されたアクションは自動的に処理されるでしょう。 1つを越えるTriggerおよびアクションは定義することができます。
トリガおよびアクションを定義します。
通常 evalメソッドの戻り値は、'process' で処理した結果を返しますが、 'trigger' の条件が満たされた場合、'action'が実行され、'action'の結果が、evalメソッドの戻り値となります。 1つ以上のトリガが定義されている場合、最後に実行された'action'の結果が、evalメソッドの戻り値となります。
Yuji Suzuki <yuji.suzuki.perl@gmail.com>
http://arbolbell.jp/
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 perldoc Trigger::JA ;# 日本語ドキュメント
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.