NAME

Trigger - Trigger framework

SYNOPSIS

	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.
  }

DESCRIPTION

When conditions (Triggers) are set, the specified action will be processed automatically. More than one Trigger and action can be defined.

METHODS

new(%args)

A trigger and action are defined.

eval(@args)

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.

AUTHOR

Yuji Suzuki <yuji.suzuki.perl@gmail.com>

http://arbolbell.jp/ # Japanese only

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Trigger

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

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.