WebIO.pm

filter: Statementstmt 100% 315 / 315 Branchbran 86.6% 26 / 30 Conditioncond 62.9% 17 / 27 MC/DCmcdc 44.4% 8 / 18 Subroutinesub 100% 68 / 68 Podpod 91.5% 54 / 59 totaltotal 94.3% 488 / 517 CC 26 SCAR 16.9
CC
26
Cov
96%
_pin_count_for_obj
21.5
_role_check
4.0
temp_celsius
2.0
CRAP 5.4
↑ Summary WebIO/Device/DigitalInput.pm »
1 # Copyright (c) 2014 Timm Murray
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright notice,
8 # this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 package Device::WebIO;
25 16 $Device::WebIO::VERSION = '0.022';
26 # ABSTRACT: Duct Tape for the Internet of Things
27 16 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 16 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 16 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 16 ▶use Device::WebIO::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 has '_device_by_name' => (
33 is => 'ro',
34 15 ▶ default => sub {{
Subroutine __ANON__: called CC=1 SCAR=0.0
35 15 }},
36 16 );
37  
38  
39 sub register
40 16 ▶{
Subroutine register: called CC=1 SCAR=0.0
Pod documented
41 16 my ($self, $name, $device) = @_;
42 16 $self->_device_by_name->{$name} = $device;
43 16 return 1;
44 }
45  
46 sub device_names
47 1 ▶{
Subroutine device_names: called CC=1 SCAR=0.0
Pod documented
48 1 my ($self) = @_;
49 1 return keys %{ $self->_device_by_name };
50 }
51  
52  
53 sub pin_desc
54 1 ▶{
Subroutine pin_desc: called CC=1 SCAR=0.0
Pod documented
55 1 my ($self, $name) = @_;
56 1 my $obj = $self->_get_obj( $name );
57 1 return $obj->pin_desc;
58 }
59  
60 sub all_desc
61 2 ▶{
Subroutine all_desc: called CC=1 SCAR=0.0
Pod documented
62 2 my ($self, $name) = @_;
63 2 my $obj = $self->_get_obj( $name );
64 2 return $obj->all_desc;
65 }
66  
67  
68 sub set_as_input
69 7 ▶{
Subroutine set_as_input: called CC=1 SCAR=0.0
Pod documented
70 7 my ($self, $name, $pin) = @_;
71 7 my $obj = $self->_get_obj( $name );
72 7 $self->_role_check( $obj, 'DigitalInput' );
73 7 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
74 6 $obj->set_as_input( $pin );
75 6 return 1;
76 }
77  
78 sub set_as_output
79 5 ▶{
Subroutine set_as_output: called CC=1 SCAR=0.0
Pod documented
80 5 my ($self, $name, $pin) = @_;
81 5 my $obj = $self->_get_obj( $name );
82 5 $self->_role_check( $obj, 'DigitalOutput' );
83 5 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
84 3 $obj->set_as_output( $pin );
85 3 return 1;
86 }
87  
88 sub is_set_input
89 8 ▶{
Subroutine is_set_input: called CC=1 SCAR=0.0
Pod documented
90 8 my ($self, $name, $pin) = @_;
91 8 my $obj = $self->_get_obj( $name );
92 8 $self->_role_check( $obj, 'DigitalInput' );
93 8 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
94 8 return $obj->is_set_input( $pin );
95 }
96  
97 sub is_set_output
98 4 ▶{
Subroutine is_set_output: called CC=1 SCAR=0.0
Pod documented
99 4 my ($self, $name, $pin) = @_;
100 4 my $obj = $self->_get_obj( $name );
101 4 $self->_role_check( $obj, 'DigitalOutput' );
102 4 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
103 4 return $obj->is_set_output( $pin );
104 }
105  
106 sub digital_input_pin_count
107 3 ▶{
Subroutine digital_input_pin_count: called CC=1 SCAR=0.0
Pod documented
108 3 my ($self, $name) = @_;
109 3 my $obj = $self->_get_obj( $name );
110 3 $self->_role_check( $obj, 'DigitalInput' );
111 3 my $count = $obj->input_pin_count;
112 3 return $count;
113 }
114  
115 sub digital_output_pin_count
116 2 ▶{
Subroutine digital_output_pin_count: called CC=1 SCAR=0.0
Pod documented
117 2 my ($self, $name) = @_;
118 2 my $obj = $self->_get_obj( $name );
119 2 $self->_role_check( $obj, 'DigitalOutput' );
120 2 my $count = $obj->output_pin_count;
121 2 return $count;
122 }
123  
124 sub digital_input
125 5 ▶{
Subroutine digital_input: called CC=1 SCAR=0.0
Pod documented
126 5 my ($self, $name, $pin) = @_;
127 5 my $obj = $self->_get_obj( $name );
128 5 $self->_role_check( $obj, 'DigitalInput' );
129 4 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInput' );
130 3 return $obj->input_pin( $pin );
131 }
132  
133 sub digital_input_port
134 2 ▶{
Subroutine digital_input_port: called CC=1 SCAR=0.0
Pod documented
135 2 my ($self, $name) = @_;
136 2 my $obj = $self->_get_obj( $name );
137 2 $self->_role_check( $obj, 'DigitalInput' );
138 2 return $obj->input_port;
139 }
140  
141 sub digital_input_callback
142 3 ▶{
Subroutine digital_input_callback: called CC=1 SCAR=0.0
Pod documented
143 3 my ($self, $name, $pin, $type, $callback) = @_;
144 3 my $obj = $self->_get_obj( $name );
145 3 $self->_role_check( $obj, 'DigitalInputCallback' );
146 3 $self->_pin_count_check( $name, $obj, $pin, 'DigitalInputCallback' );
147 3 return $obj->input_callback_pin( $pin, $type, $callback );
148 }
149  
150 sub digital_input_begin_loop
151 1 ▶{
Subroutine digital_input_begin_loop: called CC=1 SCAR=0.0
Pod documented
152 1 my ($self, $name) = @_;
153 1 my $obj = $self->_get_obj( $name );
154 1 $self->_role_check( $obj, 'DigitalInputCallback' );
155 1 return $obj->input_begin_loop();
156 }
157  
158 sub set_anyevent_condvar
159 1 ▶{
Subroutine set_anyevent_condvar: called CC=1 SCAR=0.0
Pod documented
160 1 my ($self, $name, $pin, $cv) = @_;
161 1 my $obj = $self->_get_obj( $name );
162 1 $self->_role_check( $obj, 'DigitalInputAnyEvent' );
163  
164 1 $obj->set_anyevent_condvar( $pin, $cv );
165  
166 1 return;
167 }
168  
169 sub digital_output_port
170 2 ▶{
Subroutine digital_output_port: called CC=1 SCAR=0.0
Pod documented
171 2 my ($self, $name, $out) = @_;
172 2 my $obj = $self->_get_obj( $name );
173 2 $self->_role_check( $obj, 'DigitalOutput' );
174 2 $obj->output_port( $out );
175 2 return 1;
176 }
177  
178 sub digital_output
179 7 ▶{
Subroutine digital_output: called CC=1 SCAR=0.0
Pod documented
180 7 my ($self, $name, $pin, $val) = @_;
181 7 my $obj = $self->_get_obj( $name );
182 7 $self->_role_check( $obj, 'DigitalOutput' );
183 4 $self->_pin_count_check( $name, $obj, $pin, 'DigitalOutput' );
184 3 $obj->output_pin( $pin, $val );
185 3 return 1;
186 }
187  
188 sub adc_count
189 1 ▶{
Subroutine adc_count: called CC=1 SCAR=0.0
Pod documented
190 1 my ($self, $name) = @_;
191 1 my $obj = $self->_get_obj( $name );
192 1 $self->_role_check( $obj, 'ADC' );
193 1 return $obj->adc_pin_count;
194 }
195  
196 sub adc_resolution
197 2 ▶{
Subroutine adc_resolution: called CC=1 SCAR=0.0
Pod documented
198 2 my ($self, $name, $pin) = @_;
199 2 my $obj = $self->_get_obj( $name );
200 2 $self->_role_check( $obj, 'ADC' );
201 2 return $obj->adc_bit_resolution( $pin );
202 }
203  
204 sub adc_max_int
205 2 ▶{
Subroutine adc_max_int: called CC=1 SCAR=0.0
Pod documented
206 2 my ($self, $name, $pin) = @_;
207 2 my $obj = $self->_get_obj( $name );
208 2 $self->_role_check( $obj, 'ADC' );
209 2 return $obj->adc_max_int( $pin );
210 }
211  
212 sub adc_volt_ref
213 2 ▶{
Subroutine adc_volt_ref: called CC=1 SCAR=0.0
Pod documented
214 2 my ($self, $name, $pin) = @_;
215 2 my $obj = $self->_get_obj( $name );
216 2 $self->_role_check( $obj, 'ADC' );
217 2 return $obj->adc_volt_ref( $pin );
218 }
219  
220 sub adc_input_int
221 4 ▶{
Subroutine adc_input_int: called CC=1 SCAR=0.0
Pod documented
222 4 my ($self, $name, $pin) = @_;
223 4 my $obj = $self->_get_obj( $name );
224 4 $self->_role_check( $obj, 'ADC' );
225 4 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
226 3 return $obj->adc_input_int( $pin );
227 }
228  
229 sub adc_input_float
230 3 ▶{
Subroutine adc_input_float: called CC=1 SCAR=0.0
Pod documented
231 3 my ($self, $name, $pin) = @_;
232 3 my $obj = $self->_get_obj( $name );
233 3 $self->_role_check( $obj, 'ADC' );
234 3 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
235 2 return $obj->adc_input_float( $pin );
236 }
237  
238 sub adc_input_volts
239 3 ▶{
Subroutine adc_input_volts: called CC=1 SCAR=0.0
Pod documented
240 3 my ($self, $name, $pin) = @_;
241 3 my $obj = $self->_get_obj( $name );
242 3 $self->_role_check( $obj, 'ADC' );
243 3 $self->_pin_count_check( $name, $obj, $pin, 'ADC' );
244 2 return $obj->adc_input_volts( $pin );
245 }
246  
247 sub pwm_count
248 1 ▶{
Subroutine pwm_count: called CC=1 SCAR=0.0
Pod documented
249 1 my ($self, $name) = @_;
250 1 my $obj = $self->_get_obj( $name );
251 1 $self->_role_check( $obj, 'PWM' );
252 1 return $obj->pwm_pin_count;
253 }
254  
255 sub pwm_resolution
256 2 ▶{
Subroutine pwm_resolution: called CC=1 SCAR=0.0
Pod documented
257 2 my ($self, $name, $pin) = @_;
258 2 my $obj = $self->_get_obj( $name );
259 2 $self->_role_check( $obj, 'PWM' );
260 2 return $obj->pwm_bit_resolution( $pin );
261 }
262  
263 sub pwm_max_int
264 2 ▶{
Subroutine pwm_max_int: called CC=1 SCAR=0.0
Pod documented
265 2 my ($self, $name, $pin) = @_;
266 2 my $obj = $self->_get_obj( $name );
267 2 $self->_role_check( $obj, 'PWM' );
268 2 return $obj->pwm_max_int( $pin );
269 }
270  
271 sub pwm_output_int
272 3 ▶{
Subroutine pwm_output_int: called CC=1 SCAR=0.0
Pod documented
273 3 my ($self, $name, $pin, $value) = @_;
274 3 my $obj = $self->_get_obj( $name );
275 3 $self->_role_check( $obj, 'PWM' );
276 3 $self->_pin_count_check( $name, $obj, $pin, 'PWM' );
277 2 return $obj->pwm_output_int( $pin, $value );
278 }
279  
280 sub pwm_output_float
281 2 ▶{
Subroutine pwm_output_float: called CC=1 SCAR=0.0
Pod documented
282 2 my ($self, $name, $pin, $value) = @_;
283 2 my $obj = $self->_get_obj( $name );
284 2 $self->_role_check( $obj, 'PWM' );
285 2 $self->_pin_count_check( $name, $obj, $pin, 'PWM' );
286 1 return $obj->pwm_output_float( $pin, $value );
287 }
288  
289 sub vid_channels
290 1 ▶{
Subroutine vid_channels: called CC=1 SCAR=0.0
Pod documented
291 1 my ($self, $name) = @_;
292 1 my $obj = $self->_get_obj( $name );
293 1 $self->_role_check( $obj, 'VideoOutput' );
294 1 return $obj->vid_channels;
295 }
296  
297 sub vid_width
298 2 ▶{
Subroutine vid_width: called CC=1 SCAR=0.0
Pod documented
299 2 my ($self, $name, $pin) = @_;
300 2 my $obj = $self->_get_obj( $name );
301 2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
302 2 $self->_role_check( $obj, 'VideoOutput' );
303 2 return $obj->vid_width( $pin );
304 }
305  
306 sub vid_height
307 2 ▶{
Subroutine vid_height: called CC=1 SCAR=0.0
Pod documented
308 2 my ($self, $name, $pin) = @_;
309 2 my $obj = $self->_get_obj( $name );
310 2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
311 2 $self->_role_check( $obj, 'VideoOutput' );
312 2 return $obj->vid_height( $pin );
313 }
314  
315 sub vid_fps
316 2 ▶{
Subroutine vid_fps: called CC=1 SCAR=0.0
Pod documented
317 2 my ($self, $name, $pin) = @_;
318 2 my $obj = $self->_get_obj( $name );
319 2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
320 2 $self->_role_check( $obj, 'VideoOutput' );
321 2 return $obj->vid_fps( $pin );
322 }
323  
324 sub vid_kbps
325 2 ▶{
Subroutine vid_kbps: called CC=1 SCAR=0.0
Pod documented
326 2 my ($self, $name, $pin) = @_;
327 2 my $obj = $self->_get_obj( $name );
328 2 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
329 2 $self->_role_check( $obj, 'VideoOutput' );
330 2 return $obj->vid_kbps( $pin );
331 }
332  
333 sub vid_set_width
334 1 ▶{
Subroutine vid_set_width: called CC=1 SCAR=0.0
Pod documented
335 1 my ($self, $name, $pin, $value) = @_;
336 1 my $obj = $self->_get_obj( $name );
337 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
338 1 $self->_role_check( $obj, 'VideoOutput' );
339 1 return $obj->vid_set_width( $pin, $value );
340 }
341  
342 sub vid_set_height
343 1 ▶{
Subroutine vid_set_height: called CC=1 SCAR=0.0
Pod documented
344 1 my ($self, $name, $pin, $value) = @_;
345 1 my $obj = $self->_get_obj( $name );
346 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
347 1 $self->_role_check( $obj, 'VideoOutput' );
348 1 return $obj->vid_set_height( $pin, $value );
349 }
350  
351 sub vid_set_fps
352 1 ▶{
Subroutine vid_set_fps: called CC=1 SCAR=0.0
Pod undocumented
353 1 my ($self, $name, $pin, $value) = @_;
354 1 my $obj = $self->_get_obj( $name );
355 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
356 1 $self->_role_check( $obj, 'VideoOutput' );
357 1 return $obj->vid_set_fps( $pin, $value );
358 }
359  
360 sub vid_set_kbps
361 1 ▶{
Subroutine vid_set_kbps: called CC=1 SCAR=0.0
Pod undocumented
362 1 my ($self, $name, $pin, $value) = @_;
363 1 my $obj = $self->_get_obj( $name );
364 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
365 1 $self->_role_check( $obj, 'VideoOutput' );
366 1 return $obj->vid_set_kbps( $pin, $value );
367 }
368  
369 sub vid_allowed_content_types
370 1 ▶{
Subroutine vid_allowed_content_types: called CC=1 SCAR=0.0
Pod documented
371 1 my ($self, $name, $pin) = @_;
372 1 my $obj = $self->_get_obj( $name );
373 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
374 1 $self->_role_check( $obj, 'VideoOutput' );
375 1 return $obj->vid_allowed_content_types( $pin );
376 }
377  
378 sub vid_stream
379 1 ▶{
Subroutine vid_stream: called CC=1 SCAR=0.0
Pod documented
380 1 my ($self, $name, $pin, $type) = @_;
381 1 my $obj = $self->_get_obj( $name );
382 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
383 1 $self->_role_check( $obj, 'VideoOutput' );
384 1 return $obj->vid_stream( $pin, $type );
385 }
386  
387 sub vid_stream_callback
388 1 ▶{
Subroutine vid_stream_callback: called CC=1 SCAR=0.0
Pod documented
389 1 my ($self, $name, $pin, $type, $callback) = @_;
390 1 my $obj = $self->_get_obj( $name );
391 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
392 1 $self->_role_check( $obj, 'VideoOutputCallback' );
393 1 return $obj->vid_stream_callback( $pin, $type, $callback );
394 }
395  
396 sub vid_stream_begin_loop
397 1 ▶{
Subroutine vid_stream_begin_loop: called CC=1 SCAR=0.0
Pod documented
398 1 my ($self, $name, $pin) = @_;
399 1 my $obj = $self->_get_obj( $name );
400 1 $self->_pin_count_check( $name, $obj, $pin, 'VideoOutput' );
401 1 $self->_role_check( $obj, 'VideoOutputCallback' );
402 1 return $obj->vid_stream_begin_loop( $pin );
403 }
404  
405 sub img_channels
406 1 ▶{
Subroutine img_channels: called CC=1 SCAR=0.0
Pod documented
407 1 my ($self, $name) = @_;
408 1 my $obj = $self->_get_obj( $name );
409 1 $self->_role_check( $obj, 'StillImageOutput' );
410 1 return $obj->img_channels;
411 }
412  
413 sub img_width
414 2 ▶{
Subroutine img_width: called CC=1 SCAR=0.0
Pod documented
415 2 my ($self, $name, $pin) = @_;
416 2 my $obj = $self->_get_obj( $name );
417 2 $self->_role_check( $obj, 'StillImageOutput' );
418 2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
419 2 return $obj->img_width( $pin );
420 }
421  
422 sub img_height
423 2 ▶{
Subroutine img_height: called CC=1 SCAR=0.0
Pod documented
424 2 my ($self, $name, $pin) = @_;
425 2 my $obj = $self->_get_obj( $name );
426 2 $self->_role_check( $obj, 'StillImageOutput' );
427 2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
428 2 return $obj->img_height( $pin );
429 }
430  
431 sub img_quality
432 2 ▶{
Subroutine img_quality: called CC=1 SCAR=0.0
Pod documented
433 2 my ($self, $name, $pin) = @_;
434 2 my $obj = $self->_get_obj( $name );
435 2 $self->_role_check( $obj, 'StillImageOutput' );
436 2 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
437 2 return $obj->img_quality( $pin );
438 }
439  
440 sub img_set_width
441 1 ▶{
Subroutine img_set_width: called CC=1 SCAR=0.0
Pod documented
442 1 my ($self, $name, $pin, $value) = @_;
443 1 my $obj = $self->_get_obj( $name );
444 1 $self->_role_check( $obj, 'StillImageOutput' );
445 1 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
446 1 return $obj->img_set_width( $pin, $value );
447 }
448  
449 sub img_set_height
450 1 ▶{
Subroutine img_set_height: called CC=1 SCAR=0.0
Pod documented
451 1 my ($self, $name, $pin, $value) = @_;
452 1 my $obj = $self->_get_obj( $name );
453 1 $self->_role_check( $obj, 'StillImageOutput' );
454 1 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
455 1 return $obj->img_set_height( $pin, $value );
456 }
457  
458 sub img_set_quality
459 1 ▶{
Subroutine img_set_quality: called CC=1 SCAR=0.0
Pod documented
460 1 my ($self, $name, $pin, $value) = @_;
461 1 my $obj = $self->_get_obj( $name );
462 1 $self->_role_check( $obj, 'StillImageOutput' );
463 1 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
464 1 return $obj->img_set_quality( $pin, $value );
465 }
466  
467 sub img_allowed_content_types
468 1 ▶{
Subroutine img_allowed_content_types: called CC=1 SCAR=0.0
Pod documented
469 1 my ($self, $name, $pin) = @_;
470 1 my $obj = $self->_get_obj( $name );
471 1 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
472 1 return $obj->img_allowed_content_types( $pin );
473 }
474  
475 sub img_stream
476 1 ▶{
Subroutine img_stream: called CC=1 SCAR=0.0
Pod documented
477 1 my ($self, $name, $pin, $type) = @_;
478 1 my $obj = $self->_get_obj( $name );
479 1 $self->_pin_count_check( $name, $obj, $pin, 'StillImageOutput' );
480 1 return $obj->img_stream( $pin, $type );
481 }
482  
483 sub i2c_read
484 2 ▶{
Subroutine i2c_read: called CC=1 SCAR=0.0
Pod documented
485 2 my ($self, $name, $pin, $addr, $register, $num_bytes) = @_;
486 2 my $obj = $self->_get_obj( $name );
487 2 $self->_pin_count_check( $name, $obj, $pin, 'I2CProvider' );
488 2 return $obj->i2c_read( $pin, $addr, $register, $num_bytes );
489 }
490  
491 sub i2c_write
492 2 ▶{
Subroutine i2c_write: called CC=1 SCAR=0.0
Pod documented
493 2 my ($self, $name, $pin, $addr, $register, @bytes) = @_;
494 2 my $obj = $self->_get_obj( $name );
495 2 $self->_pin_count_check( $name, $obj, $pin, 'I2CProvider' );
496 2 return $obj->i2c_write( $pin, $addr, $register, @bytes );
497 }
498  
499 sub temp_celsius
500 2 ▶{
Subroutine temp_celsius: called CC=2 SCAR=7.0
Pod undocumented
501 2 my ($self, $name) = @_;
502 2 my $obj = $self->_get_obj( $name );
503 2 ▶ Device::WebIO::FunctionNotSupportedException->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->does("Device::WebIO::Device::TempSensor") 0 2 2
504 message => "Asked for temperature, but $name does not do the"
505 . " TempSensor role"
506 ) if ! $obj->does( 'Device::WebIO::Device::TempSensor' );
507 2 return $obj->temp_celsius;
508 }
509  
510 sub temp_kelvins
511 2 ▶{
Subroutine temp_kelvins: called CC=2 SCAR=7.0
Pod undocumented
512 2 my ($self, $name) = @_;
513 2 my $obj = $self->_get_obj( $name );
514 2 ▶ Device::WebIO::FunctionNotSupportedException->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->does("Device::WebIO::Device::TempSensor") 0 2 2
515 message => "Asked for temperature, but $name does not do the"
516 . " TempSensor role"
517 ) if ! $obj->does( 'Device::WebIO::Device::TempSensor' );
518 2 return $obj->temp_kelvins;
519 }
520  
521 sub temp_fahrenheit
522 2 ▶{
Subroutine temp_fahrenheit: called CC=2 SCAR=7.0
Pod undocumented
523 2 my ($self, $name) = @_;
524 2 my $obj = $self->_get_obj( $name );
525 2 ▶ Device::WebIO::FunctionNotSupportedException->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->does("Device::WebIO::Device::TempSensor") 0 2 2
526 message => "Asked for temperature, but $name does not do the"
527 . " TempSensor role"
528 ) if ! $obj->does( 'Device::WebIO::Device::TempSensor' );
529 2 return $obj->temp_fahrenheit;
530 }
531  
532 sub spi_set_speed
533 1 ▶{
Subroutine spi_set_speed: called CC=1 SCAR=0.0
Pod documented
534 1 my ($self, $name, $pin, $speed) = @_;
535 1 my $obj = $self->_get_obj( $name );
536 1 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
537 1 return $obj->spi_set_speed( $pin, $speed );
538 }
539  
540 sub spi_read
541 1 ▶{
Subroutine spi_read: called CC=1 SCAR=0.0
Pod documented
542 1 my ($self, $name, $pin, $len) = @_;
543 1 my $obj = $self->_get_obj( $name );
544 1 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
545 1 return $obj->spi_read( $pin, $len );
546 }
547  
548 sub spi_write
549 1 ▶{
Subroutine spi_write: called CC=1 SCAR=0.0
Pod documented
550 1 my ($self, $name, $pin, $data) = @_;
551 1 my $obj = $self->_get_obj( $name );
552 1 $self->_pin_count_check( $name, $obj, $pin, 'SPI' );
553 1 return $obj->spi_write( $pin, $data );
554 }
555  
556  
557 sub _get_obj
558 122 ▶{
Subroutine _get_obj: called CC=1 SCAR=0.0
559 122 my ($self, $name) = @_;
560 122 my $obj = $self->_device_by_name->{$name};
561 122 return $obj;
562 }
563  
564 sub _pin_count_check
565 84 ▶{
Subroutine _pin_count_check: called CC=2 SCAR=6.9
566 84 my ($self, $name, $obj, $pin, $type) = @_;
567 84 my $pin_count = $self->_pin_count_for_obj( $obj, $type );
568  
569 84 ▶ if( $pin_count <= $pin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pin_count <= $pin) 10 74 84
570 10 Device::WebIO::PinDoesNotExistException->throw(
571 message => "Asked for $type pin $pin, but device $name"
572 . " only has $pin_count pins",
573 );
574 }
575  
576 74 return 1;
577 }
578  
579 sub _pin_count_for_obj
580 84 ▶{
Subroutine _pin_count_for_obj: called CC=19 SCAR=30.7
581 84 my ($self, $obj, $type) = @_;
582  
583 84 my $count;
584 84 ▶ if( $type eq 'DigitalInput' &&
Branch: 9 branches
BranchTrueFalseTotal
if ($type eq 'DigitalInput' and $obj->does('Device::WebIO::Device::DigitalInput')) { } 19 65 84
elsif ($type eq 'DigitalInputCallback' and $obj->does('Device::WebIO::Device::DigitalInputCallback')) { } 3 62 65
elsif ($type eq 'DigitalOutput' and $obj->does('Device::WebIO::Device::DigitalOutput')) { } 13 49 62
elsif ($type eq 'ADC' and $obj->does('Device::WebIO::Device::ADC')) { } 10 39 49
elsif ($type eq 'PWM' and $obj->does('Device::WebIO::Device::PWM')) { } 5 34 39
elsif ($type eq 'VideoOutput' and $obj->does('Device::WebIO::Device::VideoOutput')) { } 16 18 34
elsif ($type eq 'StillImageOutput' and $obj->does('Device::WebIO::Device::StillImageOutput')) { } 11 7 18
elsif ($type eq 'I2CProvider' and $obj->does('Device::WebIO::Device::I2CProvider')) { } 4 3 7
elsif ($type eq 'SPI' and $obj->does('Device::WebIO::Device::SPI')) { } 3 0 3
Condition66%2/3
$type eq "DigitalInput" and $obj->does("Device::WebIO::Device::DigitalInput")
!ll&&!rl&&r
65019
MC/DC50%1/2
$type eq "DigitalInput" and $obj->does("Device::WebIO::Device::DigitalInput")
$type eq "DigitalInput" $obj->does("Device::WebIO::Device::DigitalInput")
Truth table66%2/3
A and B
A= $type eq "DigitalInput"B= $obj->does("Device::WebIO::Device::DigitalInput")
ABresult
0X0
100
111
585 $obj->does( 'Device::WebIO::Device::DigitalInput' ) ) {
586 19 $count = $obj->input_pin_count;
587 }
588 ▶ elsif( $type eq 'DigitalInputCallback' &&
Condition66%2/3
$type eq "DigitalInputCallback" and $obj->does("Device::WebIO::Device::DigitalInputCallback")
!ll&&!rl&&r
6203
MC/DC50%1/2
$type eq "DigitalInputCallback" and $obj->does("Device::WebIO::Device::DigitalInputCallback")
$type eq "DigitalInputCallback" $obj->does("Device::WebIO::Device::DigitalInputCallback")
Truth table66%2/3
A and B
A= $type eq "DigitalInputCallback"B= $obj->does("Device::WebIO::Device::DigitalInputCallback")
ABresult
0X0
100
111
589 $obj->does( 'Device::WebIO::Device::DigitalInputCallback' ) ) {
590 3 $count = $obj->input_pin_count;
591 }
592 ▶ elsif( $type eq 'DigitalOutput' &&
Condition66%2/3
$type eq "DigitalOutput" and $obj->does("Device::WebIO::Device::DigitalOutput")
!ll&&!rl&&r
49013
MC/DC50%1/2
$type eq "DigitalOutput" and $obj->does("Device::WebIO::Device::DigitalOutput")
$type eq "DigitalOutput" $obj->does("Device::WebIO::Device::DigitalOutput")
Truth table66%2/3
A and B
A= $type eq "DigitalOutput"B= $obj->does("Device::WebIO::Device::DigitalOutput")
ABresult
0X0
100
111
593 $obj->does( 'Device::WebIO::Device::DigitalOutput' ) ) {
594 13 $count = $obj->output_pin_count;
595 }
596 ▶ elsif( $type eq 'ADC' &&
Condition66%2/3
$type eq "ADC" and $obj->does("Device::WebIO::Device::ADC")
!ll&&!rl&&r
39010
MC/DC50%1/2
$type eq "ADC" and $obj->does("Device::WebIO::Device::ADC")
$type eq "ADC" $obj->does("Device::WebIO::Device::ADC")
Truth table66%2/3
A and B
A= $type eq "ADC"B= $obj->does("Device::WebIO::Device::ADC")
ABresult
0X0
100
111
597 $obj->does( 'Device::WebIO::Device::ADC' ) ) {
598 10 $count = $obj->adc_pin_count;
599 }
600 ▶ elsif( $type eq 'PWM' &&
Condition66%2/3
$type eq "PWM" and $obj->does("Device::WebIO::Device::PWM")
!ll&&!rl&&r
3405
MC/DC50%1/2
$type eq "PWM" and $obj->does("Device::WebIO::Device::PWM")
$type eq "PWM" $obj->does("Device::WebIO::Device::PWM")
Truth table66%2/3
A and B
A= $type eq "PWM"B= $obj->does("Device::WebIO::Device::PWM")
ABresult
0X0
100
111
601 $obj->does( 'Device::WebIO::Device::PWM' ) ) {
602 5 $count = $obj->pwm_pin_count;
603 }
604 ▶ elsif( $type eq 'VideoOutput' &&
Condition66%2/3
$type eq "VideoOutput" and $obj->does("Device::WebIO::Device::VideoOutput")
!ll&&!rl&&r
18016
MC/DC50%1/2
$type eq "VideoOutput" and $obj->does("Device::WebIO::Device::VideoOutput")
$type eq "VideoOutput" $obj->does("Device::WebIO::Device::VideoOutput")
Truth table66%2/3
A and B
A= $type eq "VideoOutput"B= $obj->does("Device::WebIO::Device::VideoOutput")
ABresult
0X0
100
111
605 $obj->does( 'Device::WebIO::Device::VideoOutput' ) ) {
606 16 $count = $obj->vid_channels;
607 }
608 ▶ elsif( $type eq 'StillImageOutput' &&
Condition66%2/3
$type eq "StillImageOutput" and $obj->does("Device::WebIO::Device::StillImageOutput")
!ll&&!rl&&r
7011
MC/DC50%1/2
$type eq "StillImageOutput" and $obj->does("Device::WebIO::Device::StillImageOutput")
$type eq "StillImageOutput" $obj->does("Device::WebIO::Device::StillImageOutput")
Truth table66%2/3
A and B
A= $type eq "StillImageOutput"B= $obj->does("Device::WebIO::Device::StillImageOutput")
ABresult
0X0
100
111
609 $obj->does( 'Device::WebIO::Device::StillImageOutput' ) ) {
610 11 $count = $obj->img_channels;
611 }
612 ▶ elsif( $type eq 'I2CProvider' &&
Condition66%2/3
$type eq "I2CProvider" and $obj->does("Device::WebIO::Device::I2CProvider")
!ll&&!rl&&r
304
MC/DC50%1/2
$type eq "I2CProvider" and $obj->does("Device::WebIO::Device::I2CProvider")
$type eq "I2CProvider" $obj->does("Device::WebIO::Device::I2CProvider")
Truth table66%2/3
A and B
A= $type eq "I2CProvider"B= $obj->does("Device::WebIO::Device::I2CProvider")
ABresult
0X0
100
111
613 $obj->does( 'Device::WebIO::Device::I2CProvider' ) ) {
614 4 $count = $obj->i2c_channels;
615 }
616 ▶ elsif( $type eq 'SPI' &&
Condition33%1/3
$type eq "SPI" and $obj->does("Device::WebIO::Device::SPI")
!ll&&!rl&&r
003
MC/DC0%0/2
$type eq "SPI" and $obj->does("Device::WebIO::Device::SPI")
$type eq "SPI" $obj->does("Device::WebIO::Device::SPI")
Truth table33%1/3
A and B
A= $type eq "SPI"B= $obj->does("Device::WebIO::Device::SPI")
ABresult
0X0
100
111
617 $obj->does( 'Device::WebIO::Device::SPI' ) ) {
618 3 $count = $obj->spi_channels;
619 }
620  
621 84 return $count;
622 }
623  
624 sub _role_check
625 104 ▶{
Subroutine _role_check: called CC=4 SCAR=13.9
626 104 my ($self, $obj, @want_types) = @_;
627  
628 104 my $does = 0;
629 104 for (@want_types) {
630 104 my $full_type = 'Device::WebIO::Device::' . $_;
631 104 ▶ if( $obj->does( $full_type ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->does($full_type)) 100 4 104
632 100 $does = 1;
633 100 last;
634 }
635 }
636 104 ▶ if(! $does ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($does) 4 100 104
637 4 Device::WebIO::FunctionNotSupportedException->throw( message =>
638 "Object of type " . ref($obj)
639 . " does not any of the " . join( ', ', @want_types ) . " roles"
640 );
641 }
642  
643 100 return 1;
644 }
645  
646  
647 16 1;
648 __END__
↑ Summary WebIO/Device/DigitalInput.pm »