blib/lib/SigAction/SetCallBack.pm

filter: Statementstmt 81.8% 54 / 66 Branchbran 42.8% 6 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 12 / 14 Podpod 100% 2 / 2 totaltotal 74.2% 75 / 101 CC 10 SCAR 14.1
CC
10
Cov
73%
sig_registry
8.3
_sigaction
6.0
set_sa_mask
2.7
CRAP 4.1
↑ Summary
1 package SigAction::SetCallBack;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7  
8 1 ▶use POSIX qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 # sa_mask manager
11 1 $SigAction::SetCallBack::SA_MASK = 'SA_NODEFER';
12 0 ▶ sub set_sa_mask {
Subroutine set_sa_mask: not called CC=2 SCAR=10.1
Pod documented
13 0 my ($class,$new_sa_mask) = @_;
14 0 my $change = 0;
15 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0 ▶ if (defined "POSIX::${new_sa_mask}") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined "POSIX::$new_sa_mask") 0 0 0
17 0 $SigAction::SetCallBack::SA_MASK = $new_sa_mask;
18 0 $change++;
19 }
20 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 $change;
22 }
23  
24 # stack callbacks storage
25 1 my $sig_action_table = {};
26
27 # registry callback for signal
28 2 ▶ sub sig_registry {
Subroutine sig_registry: called CC=8 SCAR=21.1
Pod documented
29 2 my ($class,$sig,$func) = @_;
30 2 ▶ return 0 unless ($sig and $func);
Branch: 1 branch
BranchTrueFalseTotal
unless $sig and $func 0 2 2
Condition33%1/3
$sig and $func
!ll&&!rl&&r
002
MC/DC0%0/2
$sig and $func
$sig $func
Truth table33%1/3
A and B
A= $sigB= $func
ABresult
0X0
100
111
31 2 my ($package) = caller;
32 2 ▶ if (ref $func ne 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $func ne "CODE") 2 0 2
33 # only exists method for callback
34 2 ▶ return 0 unless $package->can($func);
Branch: 1 branch
BranchTrueFalseTotal
unless $package->can($func) 0 2 2
35 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 $func = \&{$package.'::'.$func};
37 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 };
39
40 2 ($sig = uc($sig)) =~ s/^SIG//;
41 2 my $bad_sig = 0;
42 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶ $bad_sig++ unless defined "POSIX::SIG$sig"->();
Branch: 1 branch
BranchTrueFalseTotal
unless defined(("POSIX::SIG$sig")->()) 0 2 2
44 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶ return 0 if $bad_sig;
Branch: 1 branch
BranchTrueFalseTotal
if $bad_sig 0 2 2
46
47 2 ▶ unless (exists $sig_action_table->{$sig}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $sig_action_table->{$sig}) 2 0 2
48 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 my $action = POSIX::SigAction->new(
50 \&_sigaction,
51 POSIX::SigSet->new(),
52 "POSIX::${SigAction::SetCallBack::SA_MASK}"->()
53 );
54 2 POSIX::sigaction("POSIX::SIG$sig"->(), $action);
55 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 }
57
58 2 push @{$sig_action_table->{$sig}->{$package}},$func;
59
60 2 return 1;
61 }
62  
63 # action for any signal
64 0 ▶ sub _sigaction {
Subroutine _sigaction: not called CC=2 SCAR=17.9
65 0 my ($sig) = @_;
66 0 foreach my $pckg (keys %{$sig_action_table->{$sig}}) {
67 map {
68 0 $_->($pckg);
69 0 } @{$sig_action_table->{$sig}->{$pckg}}
70 };
71 }
72  
73 1 1;
74 __END__
↑ Summary