FSA-Rules
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/FSA/Rules.pm view on Meta::CPAN
=cut
sub STORABLE_freeze {
my ($self, $clone) = @_;
return if $clone;
my $fsa = $machines{$self};
return ( $self, [ { %$self }, $fsa, @states{ @{ $fsa->{ord} } } ] );
}
##############################################################################
=head3 STORABLE_thaw
=end comment
=cut
sub STORABLE_thaw {
my ($self, $clone, $junk, $data) = @_;
return if $clone;
%{ $self } = %{ shift @$data };
my $fsa = shift @$data;
$machines{ $self } = $fsa;
@states{ @{ $fsa->{ord} } } = @$data;
return $self;
}
##############################################################################
package FSA::State;
$FSA::State::VERSION = '0.35';
=head1 FSA::State Interface
FSA::State objects represent individual states in a state machine. They are
passed as the first argument to state actions, where their methods can be
called to handle various parts of the processing, set up messages and results,
or access the state machine object itself.
Like FSA::Rules objects, FSA::State objects are empty hashes, so you can feel
free to stash data in them. But note that each state object is independent of
all others, so if you want to stash data for other states to access, you'll
likely have to stash it in the state machine object (in its hash
implementation or via the C<notes()> method), or retrieve other states from
the state machine using its C<states()> method and then access their hash data
directly.
=head2 Constructor
=head3 new
my $state = FSA::State->new;
Constructs and returns a new FSA::State object. Not intended to be called
directly, but by FSA::Rules.
=cut
sub new {
my $class = shift;
return bless {@_} => $class;
}
##############################################################################
=head2 Instance Methods
=head3 name
my $name = $state->name;
Returns the name of the state.
=cut
sub name { $states{shift()}->{name} }
##############################################################################
=head3 label
my $label = $state->label;
Returns the label of the state.
=cut
sub label { $states{shift()}->{label} }
##############################################################################
=head3 machine
my $machine = $state->machine;
Returns the FSA::Rules object for which the state was defined.
=cut
sub machine { $states{shift()}->{machine} }
##############################################################################
=head3 result
my $fsa = FSA::Rules->new(
# ...
some_state => {
do => sub {
my $state = shift;
# Do stuff...
$state->result(1); # We're done!
},
rules => [
bad => sub { ! shift->result },
good => sub { shift->result },
]
},
# ...
);
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.075 second using v1.00-cache-2.02-grep-82fe00e-cpan-503542c4f10 )