Manager/Service.pm

filter: Statementstmt 96.6% 114 / 118 Branchbran 90.0% 27 / 30 Conditioncond 50.0% 21 / 42 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 89.6% 26 / 29 Podpod 80.0% 8 / 10 totaltotal 76.2% 196 / 257 CC 34 SCAR 26.0
CC
34
Cov
85%
init
29.2
BEGIN
8.4
post_fork_hook
2.0
CRAP 13.4
« Manager/Service/Handle.pm ↑ Summary Manager/Spawn.pm »
1 package IPC::Manager::Service;
2 189 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 189 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 189 our $VERSION = '0.000035';
6  
7 189 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 189 ▶use List::Util qw/max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 189 my @ACTIONS;
11 BEGIN {
12 189 ▶ @ACTIONS = qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
13 on_all
14 on_cleanup
15 on_general_message
16 on_interval
17 on_peer_delta
18 on_pid
19 on_start
20 on_unhandled
21 should_end
22 };
23 }
24  
25 use Object::HashBase(
26 qw{
27 <name
28 <orig_io
29 <ipcm_info
30 <redirect
31  
32 pid
33 use_posix_exit
34 intercept_errors
35 expose_error_details
36 watch_pids
37  
38 <interval
39 <cycle
40 +on_sig
41 +handle_request
42 +handle_response
43 <post_fork
44 },
45  
46 189 map { "<$_" } @ACTIONS,
47 189 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 189 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 189 with 'IPC::Manager::Role::Service';
51  
52 117 ▶sub signals_to_grab { keys %{$_[0]->{+ON_SIG}} }
Subroutine signals_to_grab: called CC=1 SCAR=0.0
Pod documented
53 124 ▶sub handle_request { $_[0]->{+HANDLE_REQUEST}->(@_) }
Subroutine handle_request: called CC=1 SCAR=0.0
Pod documented
54 4 ▶sub handle_response { $_[0]->{+HANDLE_RESPONSE}->(@_) }
Subroutine handle_response: called CC=1 SCAR=0.0
Pod documented
55  
56 sub post_fork_hook {
57 116 ▶ my $self = shift;
Subroutine post_fork_hook: called CC=2 SCAR=6.9
Pod undocumented
58 116 ▶ my $cb = $self->{+POST_FORK} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cb = $self->{"post_fork"} or return 108 8 116
59 8 $cb->($self);
60 }
61  
62 sub init {
63 279 ▶ my $self = shift;
Subroutine init: called CC=25 SCAR=33.7
Pod undocumented
64  
65 279 $self->clear_service_fields();
66  
67 279 ▶ $self->{+CYCLE} //= $self->IPC::Manager::Role::Service::cycle();
Condition66%2/3
$self->{"cycle"} //= $self->IPC::Manager::Role::Service::cycle
l!l&&r!l&&!r
12780
MC/DC0%0/2
$self->{"cycle"} //= $self->IPC::Manager::Role::Service::cycle
$self->{"cycle"} $self->IPC::Manager::Role::Service::cycle
Truth table66%2/3
A //= B
A= $self->{"cycle"}B= $self->IPC::Manager::Role::Service::cycle
ABresult
1X1
011
000
68 279 ▶ $self->{+INTERVAL} //= $self->IPC::Manager::Role::Service::interval();
Condition66%2/3
$self->{"interval"} //= $self->IPC::Manager::Role::Service::interval
l!l&&r!l&&!r
172620
MC/DC0%0/2
$self->{"interval"} //= $self->IPC::Manager::Role::Service::interval
$self->{"interval"} $self->IPC::Manager::Role::Service::interval
Truth table66%2/3
A //= B
A= $self->{"interval"}B= $self->IPC::Manager::Role::Service::interval
ABresult
1X1
011
000
69 279 ▶ $self->{+USE_POSIX_EXIT} //= $self->IPC::Manager::Role::Service::use_posix_exit();
Condition33%1/3
$self->{"use_posix_exit"} //= $self->IPC::Manager::Role::Service::use_posix_exit
l!l&&r!l&&!r
02790
MC/DC0%0/2
$self->{"use_posix_exit"} //= $self->IPC::Manager::Role::Service::use_posix_exit
$self->{"use_posix_exit"} $self->IPC::Manager::Role::Service::use_posix_exit
Truth table33%1/3
A //= B
A= $self->{"use_posix_exit"}B= $self->IPC::Manager::Role::Service::use_posix_exit
ABresult
1X1
011
000
70 279 ▶ $self->{+INTERCEPT_ERRORS} //= $self->IPC::Manager::Role::Service::intercept_errors();
Condition66%2/3
$self->{"intercept_errors"} //= $self->IPC::Manager::Role::Service::intercept_errors
l!l&&r!l&&!r
82710
MC/DC0%0/2
$self->{"intercept_errors"} //= $self->IPC::Manager::Role::Service::intercept_errors
$self->{"intercept_errors"} $self->IPC::Manager::Role::Service::intercept_errors
Truth table66%2/3
A //= B
A= $self->{"intercept_errors"}B= $self->IPC::Manager::Role::Service::intercept_errors
ABresult
1X1
011
000
71 279 ▶ $self->{+EXPOSE_ERROR_DETAILS} //= $self->IPC::Manager::Role::Service::expose_error_details();
Condition66%2/3
$self->{"expose_error_details"} //= $self->IPC::Manager::Role::Service::expose_error_details
l!l&&r!l&&!r
162630
MC/DC0%0/2
$self->{"expose_error_details"} //= $self->IPC::Manager::Role::Service::expose_error_details
$self->{"expose_error_details"} $self->IPC::Manager::Role::Service::expose_error_details
Truth table66%2/3
A //= B
A= $self->{"expose_error_details"}B= $self->IPC::Manager::Role::Service::expose_error_details
ABresult
1X1
011
000
72  
73 279 ▶ croak "'post_fork' must be a coderef" if $self->{+POST_FORK} && ref($self->{+POST_FORK}) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"post_fork"} and ref $self->{"post_fork"} ne "CODE" 0 279 279
Condition66%2/3
$self->{"post_fork"} and ref $self->{"post_fork"} ne "CODE"
!ll&&!rl&&r
263160
MC/DC0%0/2
$self->{"post_fork"} and ref $self->{"post_fork"} ne "CODE"
$self->{"post_fork"} ref $self->{"post_fork"} ne "CODE"
Truth table66%2/3
A and B
A= $self->{"post_fork"}B= ref $self->{"post_fork"} ne "CODE"
ABresult
0X0
100
111
74  
75 279 ▶ if ($self->{+ON_ALL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'on_all'}) { } 31 248 279
76 31 ▶ $self->{+HANDLE_REQUEST} //= sub { return () };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$self->{"handle_request"} //= sub { return (); }
l!l&&r!l&&!r
0310
MC/DC0%0/2
$self->{"handle_request"} //= sub { return (); }
$self->{"handle_request"} sub { return (); }
Truth table33%1/3
A //= B
A= $self->{"handle_request"}B= sub { return (); }
ABresult
1X1
011
000
77 31 ▶ $self->{+HANDLE_RESPONSE} //= sub { return () };
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$self->{"handle_response"} //= sub { return (); }
l!l&&r!l&&!r
0310
MC/DC0%0/2
$self->{"handle_response"} //= sub { return (); }
$self->{"handle_response"} sub { return (); }
Truth table33%1/3
A //= B
A= $self->{"handle_response"}B= sub { return (); }
ABresult
1X1
011
000
78 }
79 else {
80 248 ▶ my $req_handler = $self->{+HANDLE_REQUEST} or croak "Either 'on_all' or 'handle_request' callback is required";
Branch: 1 branch
BranchTrueFalseTotal
my $req_handler = $self->{"handle_request"} or croak("Either 'on_all' or 'handle_request' callback is required") 1 247 248
81 247 ▶ my $resp_handler = $self->{+HANDLE_RESPONSE} //= sub { confess "Got a response, but no response handler set" };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Condition66%2/3
$self->{"handle_response"} //= sub { confess("Got a response, but no response handler set"); }
l!l&&r!l&&!r
132340
MC/DC0%0/2
$self->{"handle_response"} //= sub { confess("Got a response, but no response handler set"); }
$self->{"handle_response"} sub { confess("Got a response, but no response handler set"); }
Truth table66%2/3
A //= B
A= $self->{"handle_response"}B= sub { confess("Got a response, but no response handler set"); }
ABresult
1X1
011
000
82  
83 247 ▶ croak "'handle_request' must be a coderef" unless ref($req_handler) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $req_handler eq "CODE" 1 246 247
84 246 ▶ croak "'handle_response' must be a coderef" unless ref($resp_handler) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $resp_handler eq "CODE" 1 245 246
85 }
86  
87 276 for my $action (@ACTIONS) {
88 2474 my $in = delete $self->{$action};
89 2474 ▶ my $do = $in ? (ref($in) eq 'ARRAY' ? $in : [$in]) : [];
Branch: 2 branches
BranchTrueFalseTotal
$in ? : 246 2228 2474
ref $in eq 'ARRAY' ? : 2 244 246
90  
91 2474 my @bad = grep { ref($_) ne 'CODE' } @$do;
92 2474 ▶ croak "All '$action' callbacks must be coderefs, got: " . join(', ' => @bad) if @bad;
Branch: 1 branch
BranchTrueFalseTotal
if @bad 2 2472 2474
93  
94 2472 $self->{$action} = $do;
95 }
96  
97 274 ▶ if (my $sigs = delete $self->{+ON_SIG}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sigs = delete $self->{'on_sig'}) { } 19 255 274
98 19 ▶ croak "'on_sig' must be a hashref" unless ref($sigs) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sigs eq "HASH" 1 18 19
99  
100 18 my $new = {};
101 18 for my $sig (keys %$sigs) {
102 19 ▶ my $do = $sigs->{$sig} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $do = $sigs->{$sig} or next 0 19 19
103 19 ▶ $do = [$do] unless ref($do) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $do eq "ARRAY" 19 0 19
104 19 my @bad = grep { ref($_) ne 'CODE' } @$do;
105 19 ▶ croak "All signal handlers must be coderefs, got: " . join(', ' => @bad) if @bad;
Branch: 1 branch
BranchTrueFalseTotal
if @bad 1 18 19
106 18 $new->{$sig} = $do;
107 }
108  
109 17 $self->{+ON_SIG} = $new;
110 }
111 else {
112 255 $self->{+ON_SIG} = {};
113 }
114 }
115  
116 #<<< Do not tidy this
117 1 ▶sub clear_on_sig { delete $_[0]->{+ON_SIG}->{$_[1]} }
Subroutine clear_on_sig: called CC=1 SCAR=0.0
Pod documented
118 2 ▶sub push_on_sig { push @{$_[0]->{+ON_SIG}->{$_[1]}} => $_[2] }
Subroutine push_on_sig: called CC=1 SCAR=0.0
Pod documented
119 0 ▶sub unshift_on_sig { unshift @{$_[0]->{+ON_SIG}->{$_[1]}} => $_[2] }
Subroutine unshift_on_sig: not called CC=1 SCAR=6.9
Pod documented
120 11 ▶sub run_on_sig { my @args = @_; [map { $_->(@args) } @{$_[0]->{+ON_SIG}->{$_[1]}}] }
Subroutine run_on_sig: called CC=1 SCAR=0.0
Pod documented
121 1 ▶sub remove_on_sig { my $cb = $_[2]; @{$_[0]->{+ON_SIG}->{$_[1]}} = grep { $_ != $cb } @{$_[0]->{+ON_SIG}->{$_[1]}} }
Subroutine remove_on_sig: called CC=1 SCAR=0.0
Pod documented
122 #>>>
123  
124 BEGIN {
125 189 ▶ my %inject;
Subroutine BEGIN: called CC=8 SCAR=21.3
126  
127 # Should end needs to return true/false
128 189 ▶ $inject{'run_should_end'} = sub { my @args = @_; my $count = grep { $_->(@args) } @{$_[0]->{should_end}}; $count ? 1 : 0 };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 25 241 266
129  
130 189 for my $action (@ACTIONS) {
131 1701 my $key = $action;
132  
133 #<<< Do not tidy this
134 1701 ▶ $inject{"clear_$key"} //= sub { delete $_[0]->{$key} };
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$inject{"clear_$key"} //= sub { delete $_[0]{$key}; }
l!l&&r!l&&!r
017010
MC/DC0%0/2
$inject{"clear_$key"} //= sub { delete $_[0]{$key}; }
$inject{"clear_$key"} sub { delete $_[0]{$key}; }
Truth table33%1/3
A //= B
A= $inject{"clear_$key"}B= sub { delete $_[0]{$key}; }
ABresult
1X1
011
000
135 1701 ▶ $inject{"push_$key"} //= sub { push @{$_[0]->{$key}} => $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
$inject{"push_$key"} //= sub { push @{$_[0]{$key};}, $_[1]; }
l!l&&r!l&&!r
017010
MC/DC0%0/2
$inject{"push_$key"} //= sub { push @{$_[0]{$key};}, $_[1]; }
$inject{"push_$key"} sub { push @{$_[0]{$key};}, $_[1]; }
Truth table33%1/3
A //= B
A= $inject{"push_$key"}B= sub { push @{$_[0]{$key};}, $_[1]; }
ABresult
1X1
011
000
136 1701 ▶ $inject{"unshift_$key"} //= sub { unshift @{$_[0]->{$key}} => $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.4
Condition33%1/3
$inject{"unshift_$key"} //= sub { unshift @{$_[0]{$key};}, $_[1]; }
l!l&&r!l&&!r
017010
MC/DC0%0/2
$inject{"unshift_$key"} //= sub { unshift @{$_[0]{$key};}, $_[1]; }
$inject{"unshift_$key"} sub { unshift @{$_[0]{$key};}, $_[1]; }
Truth table33%1/3
A //= B
A= $inject{"unshift_$key"}B= sub { unshift @{$_[0]{$key};}, $_[1]; }
ABresult
1X1
011
000
137 1701 ▶ $inject{"run_$key"} //= sub { my @args = @_; [map { $_->(@args) } @{$_[0]->{$key}}] };
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition66%2/3
$inject{"run_$key"} //= sub { my(@args) = @_; [map({&$_(@args);} @{$_[0]{$key};})]; }
l!l&&r!l&&!r
18915120
MC/DC0%0/2
$inject{"run_$key"} //= sub { my(@args) = @_; [map({&$_(@args);} @{$_[0]{$key};})]; }
$inject{"run_$key"} sub { my(@args) = @_; [map({&$_(@args);} @{$_[0]{$key};})]; }
Truth table66%2/3
A //= B
A= $inject{"run_$key"}B= sub { my(@args) = @_; [map({&$_(@args);} @{$_[0]{$key};})]; }
ABresult
1X1
011
000
138 1701 ▶ $inject{"remove_$key"} //= sub { my $cb = $_[1]; @{$_[0]->{$key}} = grep { $_ != $cb } @{$_[0]->{$key}} };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition33%1/3
$inject{"remove_$key"} //= sub { my $cb = $_[1]; @{$_[0]{$key};} = grep({$_ != $cb;} @{$_[0]{$key};}); }
l!l&&r!l&&!r
017010
MC/DC0%0/2
$inject{"remove_$key"} //= sub { my $cb = $_[1]; @{$_[0]{$key};} = grep({$_ != $cb;} @{$_[0]{$key};}); }
$inject{"remove_$key"} sub { my $cb = $_[1]; @{$_[0]{$key};} = grep({$_ != $cb;} @{$_[0]{$key};}); }
Truth table33%1/3
A //= B
A= $inject{"remove_$key"}B= sub { my $cb = $_[1]; @{$_[0]{$key};} = grep({$_ != $cb;} @{$_[0]{$key};}); }
ABresult
1X1
011
000
139 #>>>
140 }
141  
142 189 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
143 189 *{$_} = $inject{$_} for keys %inject;
144 }
145  
146 sub DESTROY {
147 175 ▶ my $self = shift;
Subroutine DESTROY: called CC=1 SCAR=0.0
148 175 local $?;
149 175 $self->terminate_workers;
150 }
151  
152 189 1;
153  
154 __END__
« Manager/Service/Handle.pm ↑ Summary Manager/Spawn.pm »