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.001';
5 4     4   30175 use Moo::Role;
  4         14710  
  4         19  
6 4     4   2530 use Package::Stash;
  4         16317  
  4         105  
7              
8 4         31 use POE qw(
9             Session
10 4     4   1768 );
  4         119496  
11              
12             sub BUILD {
13 22     22 0 43275 my $self = shift;
14 22         154 my $ps = Package::Stash->new(ref $self);
15             my $session = POE::Session->create(
16             inline_states => {
17 22     22   3035 _start => sub { POE::Kernel->yield('STARTALL', \$_[5] ) },
18             map {
19 34         31 my $func = $_;
20 34         65 my ( $event ) = $func =~ /^on_(.*)$/;
21             $event, sub {
22 103     103   2017643 my ( @args ) = @_[ ARG0..$#_ ];
23 103         287 $self->$func(@args);
24 34         394 };
25 1075         876 } 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     389 heap => ( $self->{heap} ||= {} ),
    50          
38             );
39 22         2491 $self->{session_id} = $session->ID;
40             }
41              
42             sub get_session_id {
43 103     103 0 103 my ( $self ) = @_;
44 103         372 return $self->{session_id};
45             }
46              
47 100     100 0 35672 sub yield { my $self = shift; POE::Kernel->post( $self->get_session_id, @_ ) }
  100         182  
48 3     3 0 6 sub call { my $self = shift; POE::Kernel->call( $self->get_session_id, @_ ) }
  3         8  
49              
50             sub _call_kernel_with_my_session {
51 3     3   154 my ( $self, $function, @args ) = @_[ OBJECT, ARG0..$#_ ];
52 3         12 POE::Kernel->$function( @args );
53             }
54            
55 3     3 0 125 sub delay { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay' => @_ ) }
  3         9  
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 3606 my ( $self, @params ) = @_;
68 22         25 $params[4] = pop @params;
69 22         23 my @isa = @{mro::get_linear_isa(ref $self)};
  22         70  
70 22         32 for my $caller (@isa) {
71 44         1189 my $can = $caller->can('START');
72 44 100       150 $can->( $self, @params ) if $can;
73             }
74             }
75            
76             sub STOPALL {
77 22     22 0 3470 my ( $self, $params ) = @_;
78 22         25 my @isa = @{mro::get_linear_isa(ref $self)};
  22         89  
79 22         35 for my $caller (@isa) {
80 44         4658 my $can = $caller->can('STOP');
81 44 100       203 $can->( $self, $params ) if $can;
82             }
83             }
84              
85             1;
86              
87             __END__