File Coverage

blib/lib/POE/Component/Supervisor/Handle.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package POE::Component::Supervisor::Handle;
4 1     1   3009 use Moose::Role;
  0            
  0            
5              
6             use POE::Component::Supervisor::Interface ();
7             use POE::Component::Supervisor::Supervised ();
8              
9             use namespace::clean -except => 'meta';
10              
11             with qw(POE::Component::Supervisor::Handle::Interface);
12              
13             has child => (
14             does => "POE::Component::Supervisor::Supervised",
15             is => "ro",
16             required => 1,
17             );
18              
19             has supervisor => (
20             does => "POE::Component::Supervisor::Interface",
21             is => "rw",
22             weak_ref => 1,
23             required => 1,
24             handles => [qw(notify_spawned notify_stopped)],
25             );
26              
27             has spawned => (
28             isa => "Bool",
29             is => "rw",
30             writer => "_spawned",
31             );
32              
33             has stopped => (
34             isa => "Bool",
35             is => "rw",
36             writer => "_stopped",
37             );
38              
39             has [map { "${_}_callback" } qw(spawned stopped)] => (
40             isa => "CodeRef",
41             is => "rw",
42             required => 0,
43             );
44              
45             sub stop_for_restart { shift->stop(@_) }
46              
47             sub notify_spawn {
48             my ( $self, @args ) = @_;
49              
50             $self->_spawned(1);
51              
52             $self->notify_spawned( $self->child, @args);
53              
54             if ( my $cb = $self->spawned_callback ) {
55             $self->$cb(@args);
56             }
57             }
58              
59             sub notify_stop {
60             my ( $self, @args ) = @_;
61              
62             $self->_stopped(1);
63              
64             $self->notify_stopped( $self->child, @args);
65              
66             if ( my $cb = $self->stopped_callback ) {
67             $self->$cb(@args);
68             }
69             }
70              
71             __PACKAGE__
72              
73             __END__
74              
75             =pod
76              
77             =head1 NAME
78              
79             POE::Component::Supervisor::Handle - Base role for supervision handles
80              
81             =head1 SYNOPSIS
82            
83             # see Handle::Proc and Handle::Session
84              
85             =head1 DESCRIPTION
86              
87             This is a base role for supervision handles.
88              
89             =head1 ATTRIBUTES
90              
91             =over 4
92              
93             =item supervisor
94              
95             The L<POE::Component::Supervisor> utilizing over this handle.
96              
97             =item child
98              
99             The child descriptor this handle was spawned for.
100              
101             =item spawned_callback
102              
103             =item stopped_callback
104              
105             These callbacks are called as handle methods with the arguments sent to the
106             supervisor.
107              
108             Note that they are not invoked with L<POE>'s calling convention, but rather
109             arbitrary arguments from the supervision handle.
110              
111             =back
112              
113             =head1 METHODS
114              
115             =over 4
116              
117             =item stop
118              
119             Stops the running supervised thingy.
120              
121             Required.
122              
123             =item is_running
124              
125             Checks if the supervised thingy is running.
126              
127             Required.
128              
129             =item stop_for_restart
130              
131             By default an alias to C<stop>.
132              
133             If stopping for the purpose of a restart should be handled differently this can
134             be overridden.
135              
136             =back
137              
138             =cut
139              
140