Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the FSA-Rules CPAN distribution.

Report information
The Basics
Id: 21213
Status: resolved
Priority: 0/
Queue: FSA-Rules

People
Owner: Nobody in particular
Requestors: khalilhaddad [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.10
Fixed in: 0.26



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.

Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Mon, 28 Aug 2006 16:49:24 -0700
To: bug-FSA-Rules [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
On Aug 28, 2006, at 16:36, Khalil Haddad via RT wrote: Show quoted text
> 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"
Can you attach the script? The code got all mangled in Email, so it's hard to read. Show quoted text
> 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.
Yes, Data::Dumper can't dump code references, so it just says "DUMMY" instead. Try using Data::Dump::Streamer, instead. Show quoted text
> 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 ?
Yes, I believe that is corect. Show quoted text
> I am available on IRC if you prefer to discuss this furthermore.
Nick? Channel? Network? I'm "Theory" on MagNet (#perl) and "justatheory" on freenode (#postgresql). Best, David
Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Tue, 29 Aug 2006 10:17:28 +0200
To: bug-FSA-Rules [...] rt.cpan.org
From: "Khalil Haddad" <khalilhaddad [...] gmail.com>

Message body is not shown because sender requested not to inline it.

David, Thank you for your quick reply, attached is the complete script. I'll ping you tonight on IRC freenode. Cheers! On 8/29/06, David Wheeler via RT <bug-FSA-Rules@rt.cpan.org> wrote: Show quoted text
> > > <URL: http://rt.cpan.org/Ticket/Display.html?id=21213 > > > On Aug 28, 2006, at 16:36, Khalil Haddad via RT wrote: >
> > 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"
> > Can you attach the script? The code got all mangled in Email, so it's > hard to read. >
> > 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.
> > Yes, Data::Dumper can't dump code references, so it just says "DUMMY" > instead. Try using Data::Dump::Streamer, instead. >
> > 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 ?
> > Yes, I believe that is corect. >
> > I am available on IRC if you prefer to discuss this furthermore.
> > Nick? Channel? Network? I'm "Theory" on MagNet (#perl) and > "justatheory" on freenode (#postgresql). > > Best, > > David > >
Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Tue, 29 Aug 2006 09:24:46 -0700
To: bug-FSA-Rules [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
On Aug 29, 2006, at 01:17, Khalil Haddad via RT wrote: Show quoted text
> Thank you for your quick reply, attached is the complete script. > I'll ping you tonight on IRC freenode.
You found a bug! This script demonstrates it: use strict; use FSA::Rules; my $i; my $rules = FSA::Rules->new( { strict => 1 }, login => { do => sub { shift->notes( num => ++$i ); }, rules => [ login => sub { shift->notes('num') <= 2; }, next => sub { shift->notes('num') > 2; } ], }, next => {} ); $rules->run; I never use strict myself, so I never would have run into it. The problem is that try_switch() switches to the new state (and therefore runs its do block) before it checks the other states. I'll have to kick the guy who implemented that feature (not me :-)). I'll add the above as a test and then fix it and release a new version later today. Best, David
Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Tue, 29 Aug 2006 18:49:07 +0200
To: bug-FSA-Rules [...] rt.cpan.org
From: "Khalil Haddad" <khalilhaddad [...] gmail.com>
David, Hmm great ! been trying to debug this for hours now unsuccessfully :) Now that you explain the problem, a simple counter in the state's do block will break the try_switch design, given the order of the tests. Keep us posted! On 8/29/06, David Wheeler via RT <bug-FSA-Rules@rt.cpan.org> wrote: Show quoted text
> > > <URL: http://rt.cpan.org/Ticket/Display.html?id=21213 > > > On Aug 29, 2006, at 01:17, Khalil Haddad via RT wrote: >
> > Thank you for your quick reply, attached is the complete script. > > I'll ping you tonight on IRC freenode.
> > You found a bug! This script demonstrates it: > > use strict; > use FSA::Rules; > > my $i; > my $rules = FSA::Rules->new( > { strict => 1 }, > login => { > do => sub { > shift->notes( num => ++$i ); > }, > rules => [ > login => sub { > shift->notes('num') <= 2; > }, > next => sub { > shift->notes('num') > 2; > } > ], > }, > next => {} > ); > > $rules->run; > > I never use strict myself, so I never would have run into it. The > problem is that try_switch() switches to the new state (and therefore > runs its do block) before it checks the other states. I'll have to > kick the guy who implemented that feature (not me :-)). I'll add the > above as a test and then fix it and release a new version later today. > > Best, > > David > >
Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Tue, 29 Aug 2006 09:52:05 -0700
To: bug-FSA-Rules [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
On Aug 29, 2006, at 09:49, Khalil Haddad via RT wrote: Show quoted text
> Hmm great ! been trying to debug this for hours now unsuccessfully :) > > Now that you explain the problem, a simple counter in the state's > do block > will break the try_switch design, given the order of the tests.
Yep. I've already fixed it in svn and will put it on CPAN in a few minutes. Best, David
Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Tue, 29 Aug 2006 10:46:44 -0700
To: bug-FSA-Rules [...] rt.cpan.org
From: "David E. Wheeler" <david [...] kineticode.com>
FSA::Rules 0.26 is on its way to CPAN now.
Subject: Re: [rt.cpan.org #21213] FSA::Rules PERL module *possible* bug
Date: Tue, 29 Aug 2006 23:49:44 +0200
To: bug-FSA-Rules [...] rt.cpan.org
From: "Khalil Haddad" <khalilhaddad [...] gmail.com>
Excellent, version 0.26 works as expected with strict mode. Thank you for your quick fix! On 8/29/06, David Wheeler via RT <bug-FSA-Rules@rt.cpan.org> wrote: Show quoted text
> > > <URL: http://rt.cpan.org/Ticket/Display.html?id=21213 > > > FSA::Rules 0.26 is on its way to CPAN now. > > >