duino/Command/com.pm

filter: Statementstmt 60.0% 18 / 30 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 55.1% 27 / 49 CC 4 SCAR 20.3
CC
4
Cov
50%
execute
20.0
abstract
2.0
usage_desc
2.0
CRAP 7.6
« duino/Command/models.pm ↑ Summary duino/Command/clean.pm »
1 package App::duino::Command::com;
2 {
3 1 $App::duino::Command::com::VERSION = '0.10';
4 }
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use App::duino -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Device::SerialPort;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IPC::Cmd qw(can_run);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 App::duino::Command::com - Open a serial monitor to an Arduino
17  
18 =head1 VERSION
19  
20 version 0.10
21  
22 =head1 SYNOPSIS
23  
24 $ duino com --port /dev/ttyACM0
25  
26 =head1 DESCRIPTION
27  
28 This command can be used to initiate a serial monitor with an Arduino board (or
29 any other device that supports serial communication). The C<picocom> terminal
30 emulator will be used if installed, otherwise a built-in RX-only terminal will
31 be started.
32  
33 =cut
34  
35 0 ▶sub abstract { 'open a serial monitor to an Arduino' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
36  
37 0 ▶sub usage_desc { '%c upload %o [sketch.ino]' }
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
38  
39 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
40 0 my ($self) = @_;
41  
42 return (
43 0 [ 'port|p=s', 'specify the serial port to use',
44 { default => $self -> default_config('port') } ],
45 );
46 }
47  
48 0 ▶sub execute {
Subroutine execute: not called CC=4 SCAR=30.0
Pod documented
49 0 my ($self, $opt, $args) = @_;
50  
51 0 ▶ if (can_run('picocom')) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_run('picocom')) { } 0 0 0
52 0 system 'picocom', $opt -> port;
53 } else {
54 0 ▶ open my $fh, '<', $opt -> port
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $opt->port or die q[Can't open serial port '] . $opt->port . "'.\n" 0 0 0
55 or die "Can't open serial port '".$opt -> port."'.\n";
56  
57 0 my $fd = fileno $fh;
58  
59 0 ▶ while (read $fh, my $char, 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $char, 1) 0 0 0
60 0 print $char;
61 }
62  
63 0 close $fh;
64 }
65 }
66  
67 =head1 OPTIONS
68  
69 =over 4
70  
71 =item B<--port>, B<-p>
72  
73 The path to the Arduino serial port. The environment variable C<ARDUINO_PORT>
74 will be used if present and if the command-line option is not set. If neither
75 of them is set the default value (C</dev/ttyACM0>) will be used.
76  
77 =back
78  
79 =head1 AUTHOR
80  
81 Alessandro Ghedini <alexbio@cpan.org>
82  
83 =head1 LICENSE AND COPYRIGHT
84  
85 Copyright 2013 Alessandro Ghedini.
86  
87 This program is free software; you can redistribute it and/or modify it
88 under the terms of either: the GNU General Public License as published
89 by the Free Software Foundation; or the Artistic License.
90  
91 See http://dev.perl.org/licenses/ for more information.
92  
93 =cut
94  
95 1 1; # End of App::duino::Command::com
« duino/Command/models.pm ↑ Summary duino/Command/clean.pm »