blib/lib/Linux/Event/Signal.pm

filter: Statementstmt 90.1% 73 / 81 Branchbran 89.2% 25 / 28 Conditioncond 77.1% 27 / 35 MC/DCmcdc 43.7% 7 / 16 Subroutinesub 73.9% 17 / 23 Podpod 100% 1 / 1 totaltotal 81.5% 150 / 184 CC 28 SCAR 19.1
CC
28
Cov
87%
_numbers
14.3
new
9.1
_descriptor_for
5.0
CRAP 6.8
« blib/lib/Linux/Event/Timer.pm ↑ Summary blib/lib/Linux/Event/TLS.pm »
1 package Linux::Event::Signal;
2 8 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = '0.105';
7  
8 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use POSIX qw(SIGKILL SIGRTMAX SIGSTOP);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 require Linux::Event::Loop;
14 8 require XSLoader;
15 8 XSLoader::load(__PACKAGE__, $VERSION);
16  
17 8 my %CLASS_DESCRIPTOR;
18 8 fieldhash my %ENGINE_FOR_LOOP;
19  
20 18 ▶sub _descriptor_for ($class) {
Subroutine _descriptor_for: called CC=5 SCAR=16.1
21 18 ▶ return $CLASS_DESCRIPTOR{$class} if exists $CLASS_DESCRIPTOR{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $CLASS_DESCRIPTOR{$class} 7 11 18
22 11 ▶ croak 'Linux::Event::Signal is an abstract base class'
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 1 10 11
23 if $class eq __PACKAGE__;
24 10 ▶ croak "$class is not a Linux::Event::Signal subclass"
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa(__PACKAGE__) 0 10 10
25 if !$class->isa(__PACKAGE__);
26 10 ▶ my $callback = $class->can('on_signal')
Condition100%2/2
$class->can("on_signal") // croak("$class must define on_signal()")
l!l
91
MC/DC100%1/1
$class->can("on_signal") // croak("$class must define on_signal()")
$class->can("on_signal")
Truth table100%2/2
A
A= $class->can("on_signal")
Aresult
11
00
27 // croak "$class must define on_signal()";
28 9 return $CLASS_DESCRIPTOR{$class}
29 = Linux::Event::Signal::_Descriptor->new($callback);
30 }
31  
32 25 ▶sub _numbers ($value) {
Subroutine _numbers: called CC=14 SCAR=26.6
33 25 ▶ my @number = ref($value) eq 'ARRAY' ? @$value : ($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 4 21 25
34 25 ▶ croak 'new(): signals must contain at least one signal number' if !@number;
Branch: 1 branch
BranchTrueFalseTotal
unless @number 1 24 25
35 24 my (%seen, @unique);
36 24 for my $number (@number) {
37 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
38 if !defined($number) || ref($number) || $number !~ /\A\d+\z/
39 || $number == 0;
40 25 my $digits = "$number";
41 25 $digits =~ s/\A0+//;
42 25 my $maximum = '' . SIGRTMAX;
43 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
44 if length($digits) > length($maximum)
45 || (length($digits) == length($maximum)
46 && $digits gt $maximum)
47 || $number == SIGKILL || $number == SIGSTOP;
48 22 $number = 0 + $number;
49 22 ▶ push @unique, $number if !$seen{$number}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$number}++ 21 1 22
50 }
51 19 return \@unique;
52 }
53  
54 27 ▶sub new ($class, %option) {
Subroutine new: called CC=9 SCAR=22.1
Pod documented
55 27 ▶ croak 'new(): must be called as a class method' if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 27 27
56 27 my $loop = delete $option{loop};
57 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
2241
ref $loop && $loop->can('add') && $loop->can('watch')
!ll&&!rl&&r
104
ref $loop and $loop->can("add")
!ll&&!rl&&r
104
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
58 if defined($loop) && (!ref($loop) || !$loop->can('add')
59 || !$loop->can('watch'));
60 26 my $data = delete $option{data};
61 26 ▶ croak 'new(): signals is required' if !exists $option{signals};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $option{"signals"} 1 25 26
62 25 my $numbers = _numbers(delete $option{signals});
63 19 ▶ croak 'new(): unknown options: ' . join(', ', sort keys %option) if %option;
Branch: 1 branch
BranchTrueFalseTotal
if %option 1 18 19
64 18 my $signal = $class->_new_native(
65 _descriptor_for($class), $numbers, $data,
66 );
67 16 ▶ $loop->add($signal) if defined $loop;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loop 4 12 16
68 16 return $signal;
69 }
70  
71 17 ▶sub _attach_to_loop ($self, $loop) {
Subroutine _attach_to_loop: called CC=2 SCAR=7.1
72 17 ▶ my $engine = $ENGINE_FOR_LOOP{$loop}
Condition66%2/3
$ENGINE_FOR_LOOP{$loop} //= "Linux::Event::Signal::_Engine"->_new($loop)
l!l&&r!l&&!r
5120
MC/DC0%0/2
$ENGINE_FOR_LOOP{$loop} //= "Linux::Event::Signal::_Engine"->_new($loop)
$ENGINE_FOR_LOOP{$loop} "Linux::Event::Signal::_Engine"->_new($loop)
Truth table66%2/3
A //= B
A= $ENGINE_FOR_LOOP{$loop}B= "Linux::Event::Signal::_Engine"->_new($loop)
ABresult
1X1
011
000
73 //= Linux::Event::Signal::_Engine->_new($loop);
74 17 return $self->_attach_native($loop, $engine->{native});
75 }
76  
77 18 ▶sub _objects_for_loop ($class, $loop) {
Subroutine _objects_for_loop: called CC=2 SCAR=7.2
78 18 my $engine = $ENGINE_FOR_LOOP{$loop};
79 18 ▶ return $engine ? $engine->{native}->objects : [];
Branch: 1 branch
BranchTrueFalseTotal
$engine ? : 18 0 18
80 }
81  
82 0 ▶sub CLONE ($class) {
Subroutine CLONE: not called CC=1 SCAR=6.9
83 0 %CLASS_DESCRIPTOR = ();
84 0 %ENGINE_FOR_LOOP = ();
85 0 return;
86 }
87  
88 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
89  
90 package Linux::Event::Signal::_Descriptor;
91 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
92  
93 package Linux::Event::Signal::_Service;
94 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
95  
96 package Linux::Event::Signal::_Engine;
97 8 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 0 ▶sub CLONE_SKIP ($class) { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
102  
103 12 ▶sub _new ($class, $loop) {
Subroutine _new: called CC=1 SCAR=0.0
104 12 my $self = bless {
105 loop => $loop,
106 native => Linux::Event::Signal::_Service->new,
107 }, $class;
108 12 Scalar::Util::weaken($self->{loop});
109 12 ▶ my $ready = sub { $self->{native}->dispatch };
Subroutine __ANON__: called CC=1 SCAR=0.0
110 0 ▶ my $failed = sub { die "Linux::Event Signal event source failed\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
111 $loop->watch(
112 fd => $self->{native}->fd,
113 12 _internal => 1,
114 read => $ready,
115 error => $failed,
116 no_args => 1,
117 lean => 1,
118 );
119 12 return $self;
120 }
121  
122 8 1;
123  
124 __END__
« blib/lib/Linux/Event/Timer.pm ↑ Summary blib/lib/Linux/Event/TLS.pm »