blib/lib/AnyEvent/SerialPort.pm

filter: Statementstmt 100% 47 / 47 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 98.5% 66 / 67 CC 6 SCAR 11.0
CC
6
Cov
98%
new
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package AnyEvent::SerialPort;
4 {
5 1 $AnyEvent::SerialPort::VERSION = '1.130171';
6 }
7  
8 1 ▶use base 'AnyEvent::Handle';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 DEBUG => $ENV{ANYEVENT_SERIALPORT_DEBUG},
12 1 };
13  
14 1 ▶use Carp qw/croak carp/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Device::SerialPort qw/:PARAM :STAT 0.07/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Symbol qw(gensym);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # ABSTRACT: AnyEvent::Handle subclass for serial ports
20  
21  
22 4 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
23 4 my $pkg = shift;
24 4 my %p = @_;
25 4 ▶ croak "Parameter serial_port is required" unless (exists $p{serial_port});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"serial_port"} 1 3 4
26  
27 # allow just a device name - to use defaults or array reference with
28 # device and settings
29 3 my $dev = delete $p{serial_port};
30 3 my @settings;
31 3 ▶ if (ref $dev) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dev) 1 2 3
32 1 @settings = @$dev;
33 1 $dev = shift @settings;
34 }
35  
36 3 my $fh = gensym();
37 3 ▶ my $s = tie *$fh, 'Device::SerialPort', $dev or
Branch: 1 branch
BranchTrueFalseTotal
my $s = tie(*$fh, "Device::SerialPort", $dev) or croak("Could not tie serial port, $dev, to file handle: $!") 3 0 3
38 croak "Could not tie serial port, $dev, to file handle: $!";
39  
40 3 foreach my $setting ([ baudrate => 9600 ],
41 [ databits => 8 ],
42 [ parity => 'none' ],
43 [ stopbits => 1 ],
44 [ datatype => 'raw' ],
45 @settings
46 ) {
47 16 my ($setter, @v) = @$setting;
48 16 $s->$setter(@v);
49 }
50 3 $s->write_settings();
51 3 ▶ sysopen($fh, $dev, O_RDWR|O_NOCTTY|O_NDELAY) or
Branch: 1 branch
BranchTrueFalseTotal
sysopen $fh, $dev, 2306 or croak("sysopen of '${dev}' failed: $!") 2 1 3
52 croak "sysopen of '$dev' failed: $!";
53 2 $fh->autoflush(1);
54 2 my $self = $pkg->SUPER::new(fh => $fh, %p);
55 2 $self->{serial_port} = $s;
56 2 $self;
57 }
58  
59  
60 2 ▶sub serial_port {
Subroutine serial_port: called CC=1 SCAR=0.0
Pod documented
61 shift->{serial_port}
62 2 }
63  
64 1 1;
65  
66 __END__
↑ Summary