File Coverage

blib/lib/MooX/POE.pm
Criterion Covered Total %
statement 43 61 70.4
branch 6 8 75.0
condition 1 2 50.0
subroutine 13 22 59.0
pod 0 16 0.0
total 63 109 57.8


line stmt bran cond sub pod time code
1             package MooX::POE;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: POE::Session combined with Moo (or Moose, if you want)
4             $MooX::POE::VERSION = '0.002';
5 4     4   29513 use Moo::Role;
  4         13122  
  4         17  
6 4     4   2397 use Package::Stash;
  4         15486  
  4         104  
7              
8 4         25 use POE qw(
9             Session
10 4     4   1726 );
  4         113617  
11              
12             sub BUILD {
13 22     22 0 41605 my $self = shift;
14 22         137 my $ps = Package::Stash->new(ref $self);
15             my $session = POE::Session->create(
16             inline_states => {
17 22     22   2847 _start => sub { POE::Kernel->yield('STARTALL', \$_[5] ) },
18             map {
19 34         31 my $func = $_;
20 34         64 my ( $event ) = $func =~ /^on_(.*)$/;
21             $event, sub {
22 103     103   2017274 my ( @args ) = @_[ ARG0..$#_ ];
23 103         257 $self->$func(@args);
24 34         367 };
25 1075         853 } grep { /^on_/ } $ps->list_all_symbols('CODE'),
26             },
27             object_states => [
28             $self => {
29             STARTALL => 'STARTALL',
30             _stop => 'STOPALL',
31             $self->can('CHILD') ? ( _child => 'CHILD' ) : (),
32             $self->can('PARENT') ? ( _parent => 'PARENT' ) : (),
33             _call_kernel_with_my_session => '_call_kernel_with_my_session',
34             },
35             ],
36             args => [ $self ],
37 22 50 50     358 heap => ( $self->{heap} ||= {} ),
    50          
38             );
39 22         2374 $self->{session_id} = $session->ID;
40             }
41              
42             sub get_session_id {
43 103     103 0 102 my ( $self ) = @_;
44 103         340 return $self->{session_id};
45             }
46              
47 100     100 0 41544 sub yield { my $self = shift; POE::Kernel->post( $self->get_session_id, @_ ) }
  100         150  
48 3     3 0 4 sub call { my $self = shift; POE::Kernel->call( $self->get_session_id, @_ ) }
  3         7  
49              
50             sub _call_kernel_with_my_session {
51 3     3   128 my ( $self, $function, @args ) = @_[ OBJECT, ARG0..$#_ ];
52 3         10 POE::Kernel->$function( @args );
53             }
54            
55 3     3 0 120 sub delay { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay' => @_ ) }
  3         7  
56 0     0 0 0 sub alarm { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm', @_ ) }
  0         0  
57 0     0 0 0 sub alarm_add { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_add', @_ ) }
  0         0  
58 0     0 0 0 sub delay_add { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_add', @_ ) }
  0         0  
59 0     0 0 0 sub alarm_set { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_set', @_ ) }
  0         0  
60 0     0 0 0 sub alarm_adjust { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_adjust', @_ ) }
  0         0  
61 0     0 0 0 sub alarm_remove { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_remove', @_ ) }
  0         0  
62 0     0 0 0 sub alarm_remove_all { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_remove_all', @_ ) }
  0         0  
63 0     0 0 0 sub delay_set { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_set', @_ ) }
  0         0  
64 0     0 0 0 sub delay_adjust { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_adjust', @_ ) }
  0         0  
65            
66             sub STARTALL {
67 22     22 0 3697 my ( $self, @params ) = @_;
68 22         25 $params[4] = pop @params;
69 22         16 my @isa = @{mro::get_linear_isa(ref $self)};
  22         68  
70 22         25 for my $caller (@isa) {
71 44         1132 my $can = $caller->can('START');
72 44 100       144 $can->( $self, @params ) if $can;
73             }
74             }
75            
76             sub STOPALL {
77 22     22 0 3141 my ( $self, $params ) = @_;
78 22         22 my @isa = @{mro::get_linear_isa(ref $self)};
  22         99  
79 22         32 for my $caller (@isa) {
80 44         4737 my $can = $caller->can('STOP');
81 44 100       194 $can->( $self, $params ) if $can;
82             }
83             }
84              
85             1;
86              
87             __END__