Supervisor/Handle.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 33.3% 1 / 3 totaltotal 95.5% 43 / 45 SCAR 11.0
CC
3
Cov
100%
notify_spawn
2.0
notify_stop
2.0
BEGIN
1.0
CRAP 3.0
« Supervisor/Supervised.pm ↑ Summary Supervisor/Supervised/Proc.pm »
1 #!/usr/bin/perl
2  
3 package POE::Component::Supervisor::Handle;
4 23 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use POE::Component::Supervisor::Interface ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 23 ▶use POE::Component::Supervisor::Supervised ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 23 with qw(POE::Component::Supervisor::Handle::Interface);
12  
13 23 has child => (
14 does => "POE::Component::Supervisor::Supervised",
15 is => "ro",
16 required => 1,
17 );
18  
19 23 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 23 has spawned => (
28 isa => "Bool",
29 is => "rw",
30 writer => "_spawned",
31 );
32  
33 23 has stopped => (
34 isa => "Bool",
35 is => "rw",
36 writer => "_stopped",
37 );
38  
39 23 has [map { "${_}_callback" } qw(spawned stopped)] => (
40 isa => "CodeRef",
41 is => "rw",
42 required => 0,
43 );
44  
45 427 ▶sub stop_for_restart { shift->stop(@_) }
Subroutine stop_for_restart: called CC=1 SCAR=0.0
Pod documented
46  
47 sub notify_spawn {
48 1085 ▶ my ( $self, @args ) = @_;
Subroutine notify_spawn: called CC=2 SCAR=6.9
Pod undocumented
49  
50 1085 $self->_spawned(1);
51  
52 1085 $self->notify_spawned( $self->child, @args);
53  
54 1085 ▶ if ( my $cb = $self->spawned_callback ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->spawned_callback) 1 1084 1085
55 1 $self->$cb(@args);
56 }
57 }
58  
59 sub notify_stop {
60 1042 ▶ my ( $self, @args ) = @_;
Subroutine notify_stop: called CC=2 SCAR=6.9
Pod undocumented
61  
62 1042 $self->_stopped(1);
63  
64 1042 $self->notify_stopped( $self->child, @args);
65  
66 1042 ▶ if ( my $cb = $self->stopped_callback ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->stopped_callback) 13 1029 1042
67 13 $self->$cb(@args);
68 }
69 }
70  
71 23 __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  
« Supervisor/Supervised.pm ↑ Summary Supervisor/Supervised/Proc.pm »