Skip to content
Browse files

Some code cleanup in POE::NFA.

Revision 2803 is mistaken.  Rob Hildred reported the problem and
provided the test case that was instrumental in helping me resolve it.
And the bug report was rt.cpan.org 53517.  I mistakenly assumed the
currently open tab was the same ticket I was debugging.
  • Loading branch information...
1 parent d803ccd commit bc5e82887151246f7919e899a25c79c74bb68d82 @rcaputo committed Feb 14, 2010
Showing with 29 additions and 24 deletions.
  1. +29 −24 lib/POE/NFA.pm
View
53 lib/POE/NFA.pm
@@ -151,32 +151,36 @@ sub import {
sub _add_ref_states {
my ($states, $refs) = @_;
- foreach my $state (keys %$refs) {
- $states->{$state} = {};
- my $data = $refs->{$state};
- croak "the data for state '$state' should be an array"
- unless (ref $data eq 'ARRAY');
- croak "the array for state '$state' has an odd number of elements"
- if (@$data & 1);
-
- while (my ($ref, $events) = splice(@$data, 0, 2)) {
- if (ref $events eq 'ARRAY') {
- foreach my $event (@$events) {
- $states->{$state}->{$event} = [ $ref, $event ];
- }
- }
- elsif (ref $events eq 'HASH') {
- foreach my $event (keys %$events) {
- my $method = $events->{$event};
- $states->{$state}->{$event} = [ $ref, $method ];
- }
+
+ foreach my $state (keys %$refs) {
+ $states->{$state} = {};
+
+ my $data = $refs->{$state};
+ croak "the data for state '$state' should be an array" unless (
+ ref $data eq 'ARRAY'
+ );
+ croak "the array for state '$state' has an odd number of elements" if (
+ @$data & 1
+ );
+
+ while (my ($ref, $events) = splice(@$data, 0, 2)) {
+ if (ref $events eq 'ARRAY') {
+ foreach my $event (@$events) {
+ $states->{$state}->{$event} = [ $ref, $event ];
}
- else {
- croak "events with '$ref' for state '$state' " .
- "need to be a hash or array ref";
+ }
+ elsif (ref $events eq 'HASH') {
+ foreach my $event (keys %$events) {
+ my $method = $events->{$event};
+ $states->{$state}->{$event} = [ $ref, $method ];
}
}
+ else {
+ croak "events with '$ref' for state '$state' " .
+ "need to be a hash or array ref";
+ }
}
+ }
}
sub spawn {
@@ -507,8 +511,9 @@ sub _register_state {
"redefining handler for event($name) for session(",
$POE::Kernel::poe_kernel->ID_session_to_id($self), ")"
)
- if ( $self->[SELF_OPTIONS]->{+OPT_DEBUG} &&
- (exists $self->[SELF_INTERNALS]->{$name})
+ if (
+ $self->[SELF_OPTIONS]->{+OPT_DEBUG} and
+ (exists $self->[SELF_INTERNALS]->{$name})
);
$self->[SELF_INTERNALS]->{$name} = $handler;
}

0 comments on commit bc5e828

Please sign in to comment.
Something went wrong with that request. Please try again.