Subject: | FSA::Rules PERL module *possible* bug |
Date: | Tue, 29 Aug 2006 01:35:56 +0200 |
To: | bug-fsa-rules [...] rt.cpan.org |
From: | "Khalil Haddad" <khalilhaddad [...] gmail.com> |
Hello
First off, thank you for your fantastic work on FSA::Rules, been using it
for a couple of days and I just love it, simple yet powerful !
Sorry if this is not in a proper bug report format, I very rarely submit
bugs, as I rarely find any !
Now to the little problem I have :
I tried to build states under the static pragma. I did make sure that only
one rule can match during a switch at any given time. But I always get the
exception telling me that multiple rules are found. I might be completely
off and misunderstood a basic concept, I apologize in advance if this is the
case!
Here are my states (the interesting bit) :
my $fsa = FSA::Rules->new(
{ strict => 1, },
### init ###
init => {
label => 'Init',
do => sub {
my $state = shift;
$state->machine->{loginretries}
= 0;
print "I am ready to work,
Master\n";
},
rules => [ login => 1, ],
},
### login ###
login => {
label => 'Can I Login?',
on_enter => sub { print "<*> Login step start\n"; },
do => sub {
my $state = shift;
$state->result(0);
$state->machine->{loginretries}
++;
do_login($site);
},
rules => [
success => {
rule => sub {
my $state = shift;
$state->result == 1;
},
action => sub { print "<**> w00t login ok!\n"; },
message => 'login ok',
},
login => {
rule => sub {
my $state = shift;
(($state->result == 0) &&
($state->machine->{loginretries} <= $maxloginretries));
},
action => sub { my $state = shift; my $nextstep =
shift; print "<**> Trying to login again!
(".$state->machine->{loginretries}."). So going to state:
".$nextstep->label."\n"; },
message => 'login repeat',
},
failure => {
rule => sub {
my $state = shift;
(($state->result == 0) &&
($state->machine->{loginretries} > $maxloginretries));
},
action => sub { my $state = shift; my $nextstep =
shift; print "<**> Hmm damn, max tries reached, lets stop. So going to
state: ".$nextstep->label."\n"; },
message => 'login nok',
},
],
on_exit => sub { print "<*> Login step done\n"; },
},
### end ###
success => {
label => 'Success',
do => sub {
my $state = shift;
do_logout($site);
$state->machine->done(1);
},
on_exit => sub { print "Success! End.\n"; },
},
failure => {
label => 'Failure',
on_enter => sub { print "STATE FAILURE!!!!\n"; },
do => sub {
my $state = shift;
#do_logout($site);
$state->machine->done(1);
},
rules => [
end => 1,
],
on_exit => sub { print "Failure! End.\n"; },
},
}
## TEST
sub do_login() { print "DOLOGIN\n"; my $site = shift;
$FSAs->{$site}->curr_state->result(0); }
This is a kind of ftp connection checking system. I run the FSA::Rules with
run and switch the state's result accordingly to the do_events I have
elswhere.
Without strict pragma, it obviously works as expected, the Failure is called
after 3 attempts and if the result slot is not set to 1. And as said before,
with strict, I get:
-> Attempt to switch from state "login" improperly found multiple possible
destination states: "login", "failure"
I tried to debut the switch and try_switch to understand how it checks the
rules under the strict pragma, but didn't quite understand the concept, I
kept seeing "DUMMY" subs.
If I understand correctly, a try_switch or switch will move to the next
state which has a matched rule, meaning that it will perform the current
action, on_exit, next on_start and do subs, and stop there is this correct ?
I am available on IRC if you prefer to discuss this furthermore.
Again thank you for your great work.
BR
Khalil Haddad
Message body is not shown because it is too large.