Supervisor/Supervised.pm

filter: Statementstmt 91.8% 56 / 61 Branchbran 33.3% 2 / 6 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.3% 14 / 15 Podpod 100% 8 / 8 totaltotal 84.5% 82 / 97 CC 7 SCAR 9.6
CC
7
Cov
83%
should_restart
7.2
_get_handle_attributes
3.1
_inherit_attributes_from_handle_class
2.0
CRAP 2.6
« Supervisor/Handle/Session.pm ↑ Summary Supervisor.pm »
1 package POE::Component::Supervisor::Supervised;
2  
3 26 our $VERSION = '0.09';
4  
5 26 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 26 with qw(POE::Component::Supervisor::Supervised::Interface);
10  
11 26 has handle_class => (
12 isa => "ClassName",
13 is => "rw",
14 required => 1,
15 # handles => {
16 # create_handle => "new",
17 # },
18 );
19  
20 2026 ▶sub spawn {
Subroutine spawn: called CC=1 SCAR=0.0
Pod documented
21 2026 my ( $self, @args ) = @_;
22 2026 $self->create_handle( @args );
23 }
24  
25 41 ▶sub _get_handle_attributes {
Subroutine _get_handle_attributes: called CC=3 SCAR=11.3
26 41 my ( $class, $handle_class ) = @_;
27  
28 41 my $meta = $class->meta;
29  
30 41 ▶ $handle_class ||= $meta->get_attribute("handle_class")->default || die "no default handle_class for $class";
Condition40%2/5
$handle_class ||= $meta->get_attribute("handle_class")->default || die("no default handle_class for $class")
l!l&&r!l&&!r
0410
$meta->get_attribute('handle_class')->default || die("no default handle_class for $class")
l!l
410
MC/DC0%0/2
$handle_class ||= $meta->get_attribute("handle_class")->default || die("no default handle_class for $class")
$handle_class $meta->get_attribute('handle_class')->default
Truth table33%1/3
A ||= B
A= $handle_classB= $meta->get_attribute('handle_class')->default
ABresult
1X1
011
000
31  
32 41 my $handle_meta = $handle_class->meta;
33  
34 my @handle_attrs =
35 519 map { $_->clone }
36 519 grep { not $meta->has_attribute($_->name) }
37 41 grep { defined $_->init_arg } grep { $_->name !~ /^(?: child | supervisor | logger )$/x }
38 $handle_meta->get_all_attributes;
39 }
40  
41 41 ▶sub _inherit_attributes_from_handle_class {
Subroutine _inherit_attributes_from_handle_class: called CC=2 SCAR=6.9
42 41 my ( $class, @args ) = @_;
43  
44 41 my $meta = $class->meta;
45  
46 41 my @handle_attrs = do {
47 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 41 @{ "${class}::_handle_attrs" } = $class->_get_handle_attributes(@args)
49 };
50  
51 41 $meta->add_attribute($_) for @handle_attrs;
52 }
53  
54 2026 ▶sub create_handle {
Subroutine create_handle: called CC=1 SCAR=0.0
Pod documented
55 2026 my ( $self, @args ) = @_;
56  
57 2026 my $class = ref $self;
58  
59 2026 my @handle_attrs = do {
60 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2026 @{ "${class}::_handle_attrs" };
62 };
63  
64 $self->construct_handle(
65 child => $self,
66 2026 ( map { $_->init_arg => scalar($_->get_value($self)) } grep { $_->has_value($self) } @handle_attrs ),
67 @args,
68 );
69 }
70  
71 2026 ▶sub construct_handle {
Subroutine construct_handle: called CC=1 SCAR=0.0
Pod documented
72 2026 my ( $self, @args ) = @_;
73 2026 $self->handle_class->new(@args);
74 }
75  
76 26 requires 'is_abnormal_exit';
77  
78 26 has restart_policy => (
79 isa => enum(__PACKAGE__ . "::RestartPolicy" => [qw(permanent transient temporary)]),
80 is => "rw",
81 default => "transient",
82 );
83  
84 202 ▶sub is_transient {
Subroutine is_transient: called CC=1 SCAR=0.0
Pod documented
85 202 my $self = shift;
86 202 $self->restart_policy eq 'transient';
87 }
88  
89 202 ▶sub is_permanent {
Subroutine is_permanent: called CC=1 SCAR=0.0
Pod documented
90 202 my $self = shift;
91 202 $self->restart_policy eq 'permanent';
92 }
93  
94 0 ▶sub is_temporary {
Subroutine is_temporary: not called CC=1 SCAR=6.9
Pod documented
95 0 my $self = shift;
96 0 $self->restart_policy eq 'temporary';
97 }
98  
99 202 ▶sub should_restart {
Subroutine should_restart: called CC=4 SCAR=19.7
Pod documented
100 202 my ( $self, @args ) = @_;
101  
102 202 ▶ if ( $self->is_permanent ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->is_permanent) { } 0 202 202
elsif ($self->is_transient) { } 202 0 202
elsif ($self->is_temporary) { } 0 0 0
103 0 return 1;
104 } elsif ( $self->is_transient ) {
105 202 return $self->is_abnormal_exit(@args);
106 } elsif ( $self->is_temporary ) {
107 0 return;
108 }
109  
110 # never reached
111 0 return 1;
112 }
113  
114 968 ▶sub respawn { shift->spawn(@_) }
Subroutine respawn: called CC=1 SCAR=0.0
Pod documented
115  
116 26 __PACKAGE__
117  
118 __END__
« Supervisor/Handle/Session.pm ↑ Summary Supervisor.pm »