| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$sig and $func
MC/DC0%0/2
$sig and $func
$sig
$func
Truth table33%1/3
A and B
A= $sigB= $func
| |||||||||||||||||||||||||||||
| 31 | 2 | my ($package) = caller; | |||||||||||||||||||||||||||
| 32 | 2 | ▶ | if (ref $func ne 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | # only exists method for callback | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | return 0 unless $package->can($func); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | return 0 if $bad_sig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | unless (exists $sig_action_table->{$sig}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||