-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a constructor meta trait so we can inling things. Needs git versi…
…on (will be 0.73) of Moose Signed-off-by: Chris Prather <chris@prather.org>
- Loading branch information
Showing
5 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package MooseX::POE::Meta::Trait::Constructor; | ||
|
||
use Moose::Role; | ||
|
||
sub _expected_constructor_class { "MooseX::POE::Meta::Trait::Object" } | ||
|
||
around _generate_instance => sub { | ||
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') }, }, | ||
object_states => [ | ||
$var => { $events } | ||
], | ||
args => [ $var ], | ||
heap => (${var}->{heap} ||= {}), | ||
); | ||
${var}->{session_id} = \$session->ID; | ||
EOF | ||
}; | ||
|
||
no Moose::Role; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters