blib/lib/Signal/Unsafe.pm

filter: Statementstmt 58.4% 52 / 89 Branchbran 14.2% 2 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 56.0% 14 / 25 Podpod 0.0% 0 / 1 totaltotal 51.4% 69 / 134 CC 10 SCAR 21.0
CC
10
Cov
52%
make_action
28.5
NEXTKEY
12.0
CLEAR
6.0
CRAP 8.2
↑ Summary
1 package Signal::Unsafe;
2 1 $Signal::Unsafe::VERSION = '0.007';
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 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 XSLoader::load(__PACKAGE__, Signal::Unsafe->VERSION);
8  
9 1 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our @EXPORT_OK = qw/sigaction/;
11  
12 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use IPC::Signal qw/sig_num sig_name/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use List::Util 'reduce';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Signal::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 {
20 1 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 tie %Signal::Unsafe, __PACKAGE__;
22 }
23 1 our $Flags = POSIX::SA_SIGINFO;
24 1 our $Mask = POSIX::SigSet->new;
25  
26 1 my $sig_max = $Config{sig_count} - 1;
27  
28 1 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
29 1 my $class = shift;
30 1 my $self = { iterator => 1, };
31 1 return bless $self, $class;
32 }
33  
34 0 ▶sub _get_status {
Subroutine _get_status: not called CC=1 SCAR=6.9
35 0 my ($self, $num) = @_;
36 0 my $ret = POSIX::SigAction->new;
37 0 sigaction($num, undef, $ret);
38 0 return [ $ret->handler, $ret->flags, $ret->mask ];
39 }
40  
41 0 ▶sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
42 0 my ($self, $key) = @_;
43 0 return $self->_get_status(sig_num($key));
44 }
45  
46 1 my %flag_values = (
47 siginfo => POSIX::SA_SIGINFO,
48 nodefer => POSIX::SA_NODEFER,
49 restart => POSIX::SA_RESTART,
50 onstack => POSIX::SA_ONSTACK,
51 resethand => POSIX::SA_RESETHAND,
52 nocldstop => POSIX::SA_NOCLDSTOP,
53 nocldwait => POSIX::SA_NOCLDWAIT,
54 );
55  
56 2 ▶sub make_action {
Subroutine make_action: called CC=7 SCAR=33.5
Pod undocumented
57 2 my $value = shift;
58 2 ▶ if (blessed($value) && $value->isa('POSIX::SigAction')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($value) and $value->isa('POSIX::SigAction')) { } 0 2 2
elsif (ref $value eq 'ARRAY') { } 0 2 2
Condition33%1/3
builtin::blessed($value) and $value->isa("POSIX::SigAction")
!ll&&!rl&&r
200
MC/DC0%0/2
builtin::blessed($value) and $value->isa("POSIX::SigAction")
builtin::blessed($value) $value->isa("POSIX::SigAction")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= $value->isa("POSIX::SigAction")
ABresult
0X0
100
111
59 0 return $value;
60 } elsif (ref $value eq 'ARRAY') {
61 0 my ($handler, $flags, $mask) = @{$value};
62 0 ▶ $mask = $Mask if not defined $mask;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mask 0 0 0
63 0 ▶ $flags = not defined $flags ? $Flags : ref($flags) ne 'ARRAY' ? $flags : reduce { $a | $b } map { $flag_values{$_} } @{$flags};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
defined $flags ? : 0 0 0
ref $flags ne 'ARRAY' ? : 0 0 0
64 0 return POSIX::SigAction->new($handler, $mask, $flags);
65 }
66 else {
67 2 return POSIX::SigAction->new($value, $Mask, $Flags);
68 }
69 }
70  
71 2 ▶sub STORE {
Subroutine STORE: called CC=1 SCAR=0.0
72 2 my ($self, $key, $value) = @_;
73 2 sigaction(sig_num($key), make_action($value));
74 2 return;
75 }
76  
77 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
78 0 my ($self, $key) = @_;
79 0 my $old = POSIX::SigAction->new("DEFAULT", $Mask, $Flags);
80 0 sigaction(sig_num($key), POSIX::SigAction->new("DEFAULT", $Mask, $Flags), $old);
81 0 return ($old->handler, $old->mask, $old->flags);
82 }
83  
84 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=2 SCAR=17.9
85 0 my ($self) = @_;
86 0 for my $sig_no (1 .. $sig_max) {
87 0 sigaction($sig_no, POSIX::SigAction->new("DEFAULT", $Mask, $Flags));
88 }
89 0 return;
90 }
91  
92 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
93 0 my ($self, $key) = @_;
94 0 return defined sig_num($key);
95 }
96  
97 0 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: not called CC=1 SCAR=6.9
98 0 my $self = shift;
99 0 $self->{iterator} = 1;
100 0 return $self->NEXTKEY;
101 }
102  
103 0 ▶sub NEXTKEY {
Subroutine NEXTKEY: not called CC=3 SCAR=24.8
104 0 my $self = shift;
105 0 ▶ if ($self->{iterator} <= $sig_max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'iterator'} <= $sig_max) { } 0 0 0
106 0 my $num = $self->{iterator}++;
107 0 ▶ return wantarray ? (sig_name($num) => $self->_get_status($num)) : sig_name($num);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
108 }
109 else {
110 0 return;
111 }
112 }
113  
114 0 ▶sub SCALAR {
Subroutine SCALAR: not called CC=1 SCAR=6.9
115 0 return 1;
116 }
117  
118 0 ▶sub UNTIE {
Subroutine UNTIE: not called CC=1 SCAR=6.9
119 0 my $self = shift;
120 0 $self->CLEAR;
121 0 return;
122 }
123  
124 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
125 }
126  
127 1 1;
128  
129 #ABSTRACT: Unsafe signal handlers made convenient
130  
131 __END__
↑ Summary