FSA-Rules
view release on metacpan or search on metacpan
is $fsa->curr_state, $state, "... The current state should be '1'";
# Try run().
ok $fsa = $CLASS->new(
0 => { rules => [ 1 => [ 1, sub { shift->machine->{count}++ } ] ] },
1 => { rules => [ 0 => [ 1, sub { $_[0]->done($_[0]->machine->{count} == 3 ) } ] ] },
), "Construct with simple states to run";
is $fsa->run, $fsa, "... Run should return the FSA object";
is $fsa->{count}, 3,
"... And it should have run through the proper number of iterations.";
# Reset and try again.
$fsa->{count} = 0;
is $fsa->done(0), $fsa, "... We should be able to reset done";
ok $state = $fsa->curr_state, "... We should be left in state '0'";
isa_ok $state, 'FSA::State';
is $state->name, 0, "... The name of the current state should be '0'";
is $fsa->run, $fsa, "... Run should still work.";
is $fsa->{count}, 3,
"... And it should have run through the proper number of again.";
t/storable.t view on Meta::CPAN
$Storable::Eval = $Storable::Eval || 1;
ok my $fsa = FSA::Rules->new(
0 => { rules => [ 1 => [ 1, sub { shift->machine->{count}++ } ] ] },
1 => { rules => [ 0 => [ 1, sub { $_[0]->done($_[0]->machine->{count} == 3 ) } ] ] },
),'Construct a rules object for serialization';
isa_ok $fsa, 'FSA::Rules';
is $fsa->run, $fsa, '... Run should return the FSA object';
is $fsa->{count}, 3,
'... And it should have run through the proper number of iterations.';
ok my $frozen = freeze($fsa), 'Freeze the FSA object';
ok $fsa = thaw($frozen), 'Thaw the FSA object';
isa_ok $fsa, 'FSA::Rules', 'The thawed object';
is $fsa->{count}, 3,
'... And it should still have its internal data';
$fsa->{count} = 0;
is $fsa->reset, $fsa, '... We should be able to reset';
is $fsa->run, $fsa, '... Run should still return the FSA object';
is $fsa->{count}, 3,
'... And it should have run through the proper number of iterations.';
( run in 3.322 seconds using v1.01-cache-2.11-cpan-71847e10f99 )