blib/lib/Udev/FFI/Monitor.pm

filter: Statementstmt 29.7% 22 / 74 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 38.8% 7 / 18 Podpod 90.0% 9 / 10 totaltotal 30.1% 38 / 126 CC 13 SCAR 20.8
CC
13
Cov
22%
start
20.0
filter_by_subsystem_devtype
12.0
filter_by_tag
12.0
CRAP 8.0
« blib/lib/Udev/FFI.pm ↑ Summary blib/lib/Udev/FFI/Enumerate.pm »
1 package Udev::FFI::Monitor;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Errno qw(EPERM);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Udev::FFI::Functions qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Udev::FFI::Device;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 sub new {
15 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 0 my $self = {
18 _monitor => shift,
19 _udev => shift,
20 _is_started => 0
21 };
22  
23 0 bless $self, $class;
24  
25 0 return $self;
26 }
27  
28  
29  
30 sub get_udev {
31 0 ▶ return $_[0]->{_udev};
Subroutine get_udev: not called CC=1 SCAR=6.9
Pod documented
32 }
33  
34  
35  
36 sub set_receive_buffer_size {
37 # self, bytes
38 0 ▶ if (0 == udev_monitor_set_receive_buffer_size($_[0]->{_monitor}, $_[1])) {
Subroutine set_receive_buffer_size: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (0 == udev_monitor_set_receive_buffer_size($_[0]{"_monitor"}, $_[1])) 0 0 0
39 0 return 1;
40 }
41  
42 0 return 0;
43 }
44  
45  
46  
47 sub filter_by_subsystem_devtype {
48 0 ▶ if (1 == $_[0]->{_is_started}) {
Subroutine filter_by_subsystem_devtype: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (1 == $_[0]{"_is_started"}) 0 0 0
49 0 $! = EPERM;
50 0 return 0;
51 }
52  
53 # self, subsystem, devtype
54 0 ▶ if (0 == ($! = udev_monitor_filter_add_match_subsystem_devtype($_[0]->{_monitor}, $_[1], $_[2]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == ($! = udev_monitor_filter_add_match_subsystem_devtype($_[0]{"_monitor"}, $_[1], $_[2]))) 0 0 0
55 0 return 1;
56 }
57  
58 0 $! = -$!;
59 0 return 0;
60 }
61  
62  
63  
64 sub filter_by_tag {
65 0 ▶ if (1 == $_[0]->{_is_started}) {
Subroutine filter_by_tag: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (1 == $_[0]{"_is_started"}) 0 0 0
66 0 $! = EPERM;
67 0 return 0;
68 }
69  
70 # self, tag
71 0 ▶ if (0 == ($! = udev_monitor_filter_add_match_tag($_[0]->{_monitor}, $_[1]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == ($! = udev_monitor_filter_add_match_tag($_[0]{"_monitor"}, $_[1]))) 0 0 0
72 0 return 1;
73 }
74  
75 0 $! = -$!;
76 0 return 0;
77 }
78  
79  
80  
81 sub filter_update {
82 0 ▶ if (0 == ($! = udev_monitor_filter_update($_[0]->{_monitor}))) {
Subroutine filter_update: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (0 == ($! = udev_monitor_filter_update($_[0]{"_monitor"}))) 0 0 0
83 0 return 1;
84 }
85  
86 0 $! = -$!;
87 0 return 0;
88 }
89  
90  
91  
92 sub filter_remove {
93 0 ▶ if (0 != udev_monitor_filter_remove($_[0]->{_monitor})) {
Subroutine filter_remove: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (0 != udev_monitor_filter_remove($_[0]{"_monitor"})) 0 0 0
94 0 return 1;
95 }
96  
97 0 $! = -$!;
98 0 return 0;
99 }
100  
101  
102  
103 sub start {
104 0 ▶ my $self = shift;
Subroutine start: not called CC=4 SCAR=30.0
Pod documented
105  
106 return 1
107 0 ▶ if $self->{_is_started};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_is_started"} 0 0 0
108  
109 0 ▶ if (0 != ($! = udev_monitor_enable_receiving( $self->{_monitor} ))) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 != ($! = udev_monitor_enable_receiving($self->{"_monitor"}))) 0 0 0
110 0 $! = -$!;
111 0 return 0;
112 }
113  
114 0 my $fd = udev_monitor_get_fd($self->{_monitor});
115  
116 0 my $fdh;
117 0 ▶ unless (open($fdh, "<&=", $fd)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fdh, "<&=", $fd) 0 0 0
118 0 return 0;
119 }
120  
121 0 $self->{_select} = IO::Select->new();
122 0 $self->{_select}->add($fdh);
123  
124 0 $self->{_is_started} = 1;
125 0 return 1;
126 }
127  
128  
129  
130 sub poll {
131 0 ▶ my $self = shift;
Subroutine poll: not called CC=3 SCAR=24.8
Pod documented
132 0 my $timeout = shift;
133  
134 croak('udev monitor is not running')
135 0 ▶ unless $self->{_is_started};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_is_started"} 0 0 0
136  
137 0 ▶ if ($self->{_select}->can_read($timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_select"}->can_read($timeout)) 0 0 0
138 0 my $device = udev_monitor_receive_device( $self->{_monitor} );
139  
140 0 return Udev::FFI::Device->new( $device );
141 }
142  
143 0 return undef;
144 }
145  
146  
147  
148 sub is_started {
149 0 ▶ return $_[0]->{_is_started};
Subroutine is_started: not called CC=1 SCAR=6.9
Pod documented
150 }
151  
152  
153  
154 sub DESTROY {
155 0 ▶ udev_monitor_unref( $_[0]->{_monitor} );
Subroutine DESTROY: not called CC=1 SCAR=6.9
156 }
157  
158  
159  
160 3 1;
161  
162  
163  
164 __END__
« blib/lib/Udev/FFI.pm ↑ Summary blib/lib/Udev/FFI/Enumerate.pm »