Skip Menu |

This queue is for tickets about the MooseX-POE CPAN distribution.

Report information
The Basics
Id: 53830
Status: open
Priority: 0/
Queue: MooseX-POE

People
Owner: Nobody in particular
Requestors: rdb [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Constructor refactor and bug fix
This patch does the following: Adds a grep { $_->can('meta' } filter to get_all_events, otherwise if anything in the inheritance tree is not a Moose class, it breaks. Refactors the constructor as follows: put session creation logic into its own method. delete the existing constructor, which is a "standard" moose constructor but also contains session creation logic. add an around() new that invokes session create after the standard constructor (defined by moose and no longer present in the class) is done. similar changes made in Meta::Trait::Constructor, but I was never able to get an immutable to run without the error message: "not defining constructor cause one already exists."
Subject: session_start_refactor.patch
diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Class.pm lib/MooseX/POE/Meta/Trait/Class.pm --- MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Class.pm 2009-06-22 06:23:04.000000000 -0700 +++ lib/MooseX/POE/Meta/Trait/Class.pm 2010-01-19 00:57:19.000000000 -0800 @@ -44,7 +44,7 @@ grep { $_->meta->can('does_role') && $_->meta->does_role($wanted_role) } - map { $_->meta } $self->linearized_isa; + map { $_->meta } grep { $_->can('meta') } $self->linearized_isa; return %events; } diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Constructor.pm lib/MooseX/POE/Meta/Trait/Constructor.pm --- MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Constructor.pm 2009-06-22 13:37:02.000000000 -0700 +++ lib/MooseX/POE/Meta/Trait/Constructor.pm 2010-01-19 02:37:37.000000000 -0800 @@ -12,25 +12,8 @@ my $orig = shift; my ($self, $var, $class_var) = @_; - my %events = $self->_meta_instance->associated_metaclass->get_all_events; - $events{STARTALL} = 'STARTALL'; - $events{_stop} = 'STOPALL'; - - my $events = join(', ', map { - s/'/\\'/g; - "'$_'" - } %events); - my $source = $orig->(@_) . <<"EOF" -my \$session = POE::Session->create( - inline_states => { _start => sub { POE::Kernel->yield('STARTALL', \$_[5] ) }, }, - object_states => [ - $var => { $events } - ], - args => [ $var ], - heap => (${var}->{heap} ||= {}), -); -${var}->{session_id} = \$session->ID; +$var->_start_object_session(); EOF }; diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Object.pm lib/MooseX/POE/Meta/Trait/Object.pm --- MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Object.pm 2009-06-22 13:37:02.000000000 -0700 +++ lib/MooseX/POE/Meta/Trait/Object.pm 2010-01-19 02:28:36.000000000 -0800 @@ -2,10 +2,15 @@ use Moose::Role; -sub new { +around new => sub { + my $constructor = shift; my $class = shift; - my $params = $class->BUILDARGS(@_); - my $self = $class->meta->new_object($params); + + $class->$constructor(@_)->_start_object_session; +}; + +sub _start_object_session { + my $self = shift; my $session = POE::Session->create( inline_states => @@ -22,7 +27,6 @@ ); $self->{session_id} = $session->ID; - $self->BUILDALL($params); return $self; }
So, please disregard the last patch and try this one, whicih passes all tests. Also refactored is, no more Instance metarole, and the get_session_id method is instantiated in the Meta::Trait::Object class.
Subject: session_start_refactor.patch
diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Class.pm lib/MooseX/POE/Meta/Trait/Class.pm --- MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Class.pm 2009-06-22 06:23:04.000000000 -0700 +++ lib/MooseX/POE/Meta/Trait/Class.pm 2010-01-19 00:57:19.000000000 -0800 @@ -44,7 +44,7 @@ grep { $_->meta->can('does_role') && $_->meta->does_role($wanted_role) } - map { $_->meta } $self->linearized_isa; + map { $_->meta } grep { $_->can('meta') } $self->linearized_isa; return %events; } diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Constructor.pm lib/MooseX/POE/Meta/Trait/Constructor.pm --- MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Constructor.pm 2009-06-22 13:37:02.000000000 -0700 +++ lib/MooseX/POE/Meta/Trait/Constructor.pm 2010-01-19 22:26:07.000000000 -0800 @@ -12,25 +12,8 @@ my $orig = shift; my ($self, $var, $class_var) = @_; - my %events = $self->_meta_instance->associated_metaclass->get_all_events; - $events{STARTALL} = 'STARTALL'; - $events{_stop} = 'STOPALL'; - - my $events = join(', ', map { - s/'/\\'/g; - "'$_'" - } %events); - my $source = $orig->(@_) . <<"EOF" -my \$session = POE::Session->create( - inline_states => { _start => sub { POE::Kernel->yield('STARTALL', \$_[5] ) }, }, - object_states => [ - $var => { $events } - ], - args => [ $var ], - heap => (${var}->{heap} ||= {}), -); -${var}->{session_id} = \$session->ID; +$var->_create_session_object(); EOF }; diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Object.pm lib/MooseX/POE/Meta/Trait/Object.pm --- MooseX-POE-0.205/lib/MooseX/POE/Meta/Trait/Object.pm 2009-06-22 13:37:02.000000000 -0700 +++ lib/MooseX/POE/Meta/Trait/Object.pm 2010-01-20 01:15:21.000000000 -0800 @@ -2,11 +2,28 @@ use Moose::Role; +# this one makes MooseX::Declare warn about around() not +# propagating right. +0 and around new => sub { + my $constructor = shift; + my $class = shift; + + $class->$constructor(@_)->_start_object_session; +}; + sub new { my $class = shift; my $params = $class->BUILDARGS(@_); my $self = $class->meta->new_object($params); + $self->_create_session_object->BUILDALL($params); + + $self +}; + +sub _create_session_object { + my $self = shift; + my $session = POE::Session->create( inline_states => { _start => sub { POE::Kernel->yield('STARTALL') }, }, @@ -22,13 +39,13 @@ ); $self->{session_id} = $session->ID; - $self->BUILDALL($params); return $self; } sub get_session_id { my ($self) = @_; - return $self->meta->get_meta_instance->get_session_id($self); + # return $self->meta->get_meta_instance->get_session_id($self); + return $self->{session_id}; } sub yield { my $self = shift; POE::Kernel->post( $self->get_session_id, @_ ) } @@ -127,7 +144,8 @@ =item yield -A cheap alias for POE::Kernel->yield() which will gurantee posting to the object's session. +A cheap alias for POE::Kernel->yield() which will guarantee posting to +the object's session. =item STARTALL diff --exclude='*~' -uwr MooseX-POE-0.205/lib/MooseX/POE.pm lib/MooseX/POE.pm --- MooseX-POE-0.205/lib/MooseX/POE.pm 2009-06-26 06:50:24.000000000 -0700 +++ lib/MooseX/POE.pm 2010-01-20 00:48:23.000000000 -0800 @@ -1,6 +1,6 @@ package MooseX::POE; -our $VERSION = '0.205'; +our $VERSION = '0.206_1'; use Moose (); use Moose::Exporter; @@ -22,7 +22,7 @@ for_class => $for, metaclass_roles => ['MooseX::POE::Meta::Trait::Class'], constructor_class_roles => ['MooseX::POE::Meta::Trait::Constructor'], - instance_metaclass_roles => ['MooseX::POE::Meta::Trait::Instance'], + # instance_metaclass_roles => ['MooseX::POE::Meta::Trait::Instance'], ); Moose::Util::MetaRole::apply_base_class_roles(