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;
}