blib/lib/Linux/Event/Kernel/Signal.pm

filter: Statementstmt 80.4% 78 / 97 Branchbran 70.0% 28 / 40 Conditioncond 65.8% 27 / 41 MC/DCmcdc 36.8% 7 / 19 Subroutinesub 66.6% 18 / 27 Podpod 0.0% 0 / 1 totaltotal 70.2% 158 / 225 CC 36 SCAR 21.5
CC
36
Cov
75%
_fork_preflight
30.0
_numbers
14.3
_fork_child_drop_loop
12.0
CRAP 8.6
« blib/lib/Linux/Event/IO/TTY.pm ↑ Summary bench/run-callback-batching-fairness.pl »
1 package Linux::Event::Kernel::Signal;
2 11 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 our $VERSION = '0.119';
7  
8 11 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use POSIX qw(SIGKILL SIGRTMAX SIGSTOP);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Scalar::Util qw(refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 11 require Linux::Event::Loop;
14 11 require XSLoader;
15 11 XSLoader::load(__PACKAGE__, $VERSION);
16  
17 11 my %CLASS_DESCRIPTOR;
18 11 fieldhash my %ENGINE_FOR_LOOP;
19  
20 27 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=4 SCAR=13.9
21 27 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 16 11 27
22 11 ▶ croak "$class is not a Linux::Event::Kernel::Signal subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 11 11
23 if !$class->isa(__PACKAGE__);
24 11 ▶ my $callback = $class->can('on_signal')
Condition100%2/2
$class->can("on_signal") // croak("$class must define on_signal() or receive on_signal => coderef")
l!l
92
MC/DC100%1/1
$class->can("on_signal") // croak("$class must define on_signal() or receive on_signal => coderef")
$class->can("on_signal")
Truth table100%2/2
A
A= $class->can("on_signal")
Aresult
11
00
25 // croak "$class must define on_signal() or receive on_signal => coderef";
26 9 return $CLASS_DESCRIPTOR{$class}
27 = Linux::Event::Kernel::Signal::_Descriptor->new($callback);
28 }
29  
30 30 ▶sub _effective_descriptor ($class, $option) {
Subroutine _effective_descriptor: called CC=4 SCAR=13.9
31 30 ▶ croak "$class is not a Linux::Event::Kernel::Signal subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 30 30
32 if !$class->isa(__PACKAGE__);
33 30 ▶ return _descriptor_for($class) if !exists $option->{on_signal};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option->{"on_signal"} 27 3 30
34 3 my $callback = delete $option->{on_signal};
35 3 ▶ croak 'new(): on_signal must be a coderef' if ref($callback) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback ne "CODE" 1 2 3
36 2 return Linux::Event::Kernel::Signal::_Descriptor->new($callback);
37 }
38  
39 25 ▶sub _numbers ($value) {
Subroutine _numbers: called CC=14 SCAR=26.6
40 25 ▶ my @number = ref($value) eq 'ARRAY' ? @$value : ($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 4 21 25
41 25 ▶ croak 'new(): signals must contain at least one signal number' if !@number;
Branch: 1 branch
BranchTrueFalseTotal
unless @number 1 24 25
42 24 my (%seen, @unique);
43 24 for my $number (@number) {
44 27 ▶ croak 'new(): every signal must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $number or ref $number or not $number =~ /\A\d+\z/u or $number == 0 2 25 27
Condition66%6/9
not defined $number or ref $number or not $number =~ /\A\d+\z/u or $number == 0
l!l&&r!l&&!r
1125
not defined $number or ref $number or not $number =~ /\A\d+\z/u
l!l&&r!l&&!r
0126
not defined $number or ref $number
l!l&&r!l&&!r
0027
MC/DC50%2/4
not defined $number or ref $number or not $number =~ /\A\d+\z/u or $number == 0
not defined $number ref $number not $number =~ /\A\d+\z/u $number == 0
Truth table60%3/5
not(A) or B or not(C) or D
A= not defined $numberB= ref $numberC= not $number =~ /\A\d+\z/uD= $number == 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
45 if !defined($number) || ref($number) || $number !~ /\A\d+\z/
46 || $number == 0;
47 25 my $digits = "$number";
48 25 $digits =~ s/\A0+//;
49 25 my $maximum = '' . SIGRTMAX;
50 25 ▶ croak "signal number $number cannot be used with signalfd"
Branch: 1 branch
BranchTrueFalseTotal
if length $digits > length $maximum or length $digits == length $maximum and $digits gt $maximum or $number == 9 or $number == 19 3 22 25
Condition83%10/12
length $digits > length $maximum or length $digits == length $maximum and $digits gt $maximum or $number == 9 or $number == 19
l!l&&r!l&&!r
2122
length $digits > length $maximum or length $digits == length $maximum and $digits gt $maximum or $number == 9
l!l&&r!l&&!r
1123
length $digits > length $maximum or length $digits == length $maximum and $digits gt $maximum
l!l&&r!l&&!r
1024
length $digits == length $maximum and $digits gt $maximum
!ll&&!rl&&r
1230
MC/DC40%2/5
length $digits > length $maximum or length $digits == length $maximum and $digits gt $maximum or $number == 9 or $number == 19
length $digits > length $maximum length $digits == length $maximum $digits gt $maximum $number == 9 $number == 19
Truth table50%4/8
A or B and C or D or E
A= length $digits > length $maximumB= length $digits == length $maximumC= $digits gt $maximumD= $number == 9E= $number == 19
ABCDEresult
1XXXX1
011XX1
00X1X1
0101X1
00X011
010011
00X000
010000
51 if length($digits) > length($maximum)
52 || (length($digits) == length($maximum)
53 && $digits gt $maximum)
54 || $number == SIGKILL || $number == SIGSTOP;
55 22 $number = 0 + $number;
56 22 ▶ push @unique, $number if !$seen{$number}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$number}++ 21 1 22
57 }
58 19 return \@unique;
59 }
60  
61 30 ▶sub new ($class, %option) {
Subroutine new: called CC=9 SCAR=22.1
Pod undocumented
62 30 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 30 30
63 30 my $descriptor = _effective_descriptor($class, \%option);
64 27 my $loop = delete $option{loop};
65 27 ▶ croak 'new(): loop must be an object implementing add() and watch()'
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch") 1 26 27
Condition77%7/9
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
!ll&&!rl&&r
2061
ref $loop && $loop->can('add') && $loop->can('watch')
!ll&&!rl&&r
106
ref $loop and $loop->can("add")
!ll&&!rl&&r
106
MC/DC50%2/4
defined $loop and not ref $loop && $loop->can("add") && $loop->can("watch")
defined $loop ref $loop $loop->can("add") $loop->can('watch')
Truth table60%3/5
A and not(B and C && D)
A= defined $loopB= ref $loopC= $loop->can("add")D= $loop->can('watch')
ABCDresult
0XXX0
11110
10XX1
110X1
11101
66 if defined($loop) && (!ref($loop) || !$loop->can('add')
67 || !$loop->can('watch'));
68 26 my $data = delete $option{data};
69 26 ▶ croak 'new(): signals is required' if !exists $option{signals};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{"signals"} 1 25 26
70 25 my $numbers = _numbers(delete $option{signals});
71 19 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %option) if %option;
Branch: 1 branch
BranchTrueFalseTotal
if %option 1 18 19
72 18 my $signal = $class->_new_native(
73 $descriptor, $numbers, $data,
74 );
75 18 ▶ $loop->add($signal) if defined $loop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop 6 12 18
76 18 return $signal;
77 }
78  
79 19 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=2 SCAR=7.1
80 19 ▶ my $engine = $ENGINE_FOR_LOOP{$loop}
Condition66%2/3
$ENGINE_FOR_LOOP{$loop} //= "Linux::Event::Kernel::Signal::_Engine"->_new($loop)
l!l&&r!l&&!r
5140
MC/DC0%0/2
$ENGINE_FOR_LOOP{$loop} //= "Linux::Event::Kernel::Signal::_Engine"->_new($loop)
$ENGINE_FOR_LOOP{$loop} "Linux::Event::Kernel::Signal::_Engine"->_new($loop)
Truth table66%2/3
A //= B
A= $ENGINE_FOR_LOOP{$loop}B= "Linux::Event::Kernel::Signal::_Engine"->_new($loop)
ABresult
1X1
011
000
81 //= Linux::Event::Kernel::Signal::_Engine->_new($loop);
82 19 return $self->_attach_native($loop, $engine->{native});
83 }
84  
85 0 ▶sub _fork_preflight ($self, $mode, $loop) {
Subroutine _fork_preflight: not called CC=5 SCAR=34.0
86 0 ▶ croak "fork(): Signal does not support '$mode'" if $mode ne 'drop';
Branch: 1 branch
BranchTrueFalseTotal
if $mode ne "drop" 0 0 0
87 0 my $owner = $self->loop;
88 0 ▶ croak 'fork(): Signal is not active in this Loop'
Branch: 1 branch
BranchTrueFalseTotal
if not $owner or builtin::refaddr($owner) != builtin::refaddr($loop) or not $self->is_active 0 0 0
Condition0%0/6
not $owner or builtin::refaddr($owner) != builtin::refaddr($loop) or not $self->is_active
l!l&&r!l&&!r
000
not $owner or builtin::refaddr($owner) != builtin::refaddr($loop)
l!l&&r!l&&!r
000
MC/DC0%0/3
not $owner or builtin::refaddr($owner) != builtin::refaddr($loop) or not $self->is_active
not $owner builtin::refaddr($owner) != builtin::refaddr($loop) not $self->is_active
Truth table0%0/4
not(A) or B or not(C)
A= not $ownerB= builtin::refaddr($owner) != builtin::refaddr($loop)C= not $self->is_active
ABCresult
1XX1
01X1
0011
0000
89 if !$owner || refaddr($owner) != refaddr($loop) || !$self->is_active;
90 0 return 1;
91 }
92  
93 0 ▶sub _fork_child_drop ($self, $loop) {
Subroutine _fork_child_drop: not called CC=1 SCAR=6.9
94 0 return;
95 }
96  
97 0 ▶sub _fork_child_drop_loop ($class, $loop) {
Subroutine _fork_child_drop_loop: not called CC=3 SCAR=24.8
98 0 my $engine = delete $ENGINE_FOR_LOOP{$loop};
99 0 ▶ return if !$engine;
Branch: 1 branch
BranchTrueFalseTotal
unless $engine 0 0 0
100 0 my $native = delete $engine->{native};
101 0 $engine->{loop} = undef;
102 0 ▶ $native->_fork_child_drop if $native;
Branch: 1 branch
BranchTrueFalseTotal
if $native 0 0 0
103 0 return;
104 }
105  
106 28 ▶sub _objects_for_loop ($class, $loop) {
Subroutine _objects_for_loop: called CC=2 SCAR=7.2
107 28 my $engine = $ENGINE_FOR_LOOP{$loop};
108 28 ▶ return $engine ? $engine->{native}->objects : [];
Branch: 1 branch
BranchTrueFalseTotal
$engine ? : 28 0 28
109 }
110  
111 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=1 SCAR=6.9
112 0 %CLASS_DESCRIPTOR = ();
113 0 %ENGINE_FOR_LOOP = ();
114 0 return;
115 }
116  
117 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
118  
119 package Linux::Event::Kernel::Signal::_Descriptor;
120 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
121  
122 package Linux::Event::Kernel::Signal::_Service;
123 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
124  
125 package Linux::Event::Kernel::Signal::_Engine;
126 11 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
131  
132 14 ▶sub _new ($class, $loop) {
Subroutine _new: called CC=1 SCAR=0.0
133 14 my $self = bless {
134 loop => $loop,
135 native => Linux::Event::Kernel::Signal::_Service->new,
136 }, $class;
137 14 Scalar::Util::weaken($self->{loop});
138 14 ▶ my $ready = sub { $self->{native}->dispatch };
Subroutine __ANON__: called CC=1 SCAR=0.0
139 0 ▶ my $failed = sub { die "Linux::Event Signal event source failed\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
140 $loop->watch(
141 fd => $self->{native}->fd,
142 14 _internal => 1,
143 read => $ready,
144 error => $failed,
145 no_args => 1,
146 lean => 1,
147 );
148 14 return $self;
149 }
150  
151 11 1;
152 __END__
« blib/lib/Linux/Event/IO/TTY.pm ↑ Summary bench/run-callback-batching-fairness.pl »