duino/Command.pm

filter: Statementstmt 36.7% 18 / 49 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 4 totaltotal 17.5% 23 / 131 CC 27 SCAR 55.1
CC
27
Cov
17%
default_config
420.0
board_config
42.0
ini
6.0
CRAP 248.0
↑ Summary duino/Command/upload.pm »
1 package App::duino::Command;
2 {
3 7 $App::duino::Command::VERSION = '0.10';
4 }
5  
6 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use App::Cmd::Setup -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Config::INI::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 App::duino::Command - Base class for App::duino commands
17  
18 =head1 VERSION
19  
20 version 0.10
21  
22 =cut
23  
24 0 ▶sub ini {
Subroutine ini: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my ($self, $config) = @_;
26  
27 0 ▶ if (-e 'duino.ini') {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "duino.ini") 0 0 0
28 0 my $cfg = Config::INI::Reader -> read_file('duino.ini');
29 0 return $cfg -> {'_'} -> {$config};
30 }
31  
32 0 return undef;
33 }
34  
35 0 ▶sub default_config {
Subroutine default_config: not called CC=20 SCAR=60.4
Pod undocumented
36 0 my ($self, $config) = @_;
37  
38 0 ▶ return $self -> ini($config) || $ENV{'ARDUINO_BOARD'} || 'uno'
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "board" 0 0 0
Condition0%0/5
$self->ini($config) || $ENV{'ARDUINO_BOARD'} || 'uno'
l!l
00
$self->ini($config) or $ENV{"ARDUINO_BOARD"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->ini($config) || $ENV{'ARDUINO_BOARD'} || 'uno'
$self->ini($config) $ENV{"ARDUINO_BOARD"}
Truth table0%0/3
A or B
A= $self->ini($config)B= $ENV{"ARDUINO_BOARD"}
ABresult
1X1
011
000
39 if $config eq 'board';
40  
41 0 ▶ return $ENV{'ARDUINO_PORT'} || '/dev/ttyACM0'
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "port" 0 0 0
Condition0%0/2
$ENV{'ARDUINO_PORT'} || '/dev/ttyACM0'
l!l
00
MC/DC0%0/1
$ENV{'ARDUINO_PORT'} || '/dev/ttyACM0'
$ENV{'ARDUINO_PORT'}
Truth table0%0/2
A
A= $ENV{'ARDUINO_PORT'}
Aresult
11
00
42 if $config eq 'port';
43  
44 0 ▶ return $ENV{'ARDUINO_FUSES'} || 0
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "fuses" 0 0 0
Condition0%0/2
$ENV{'ARDUINO_FUSES'} || 0
l!l
00
MC/DC0%0/1
$ENV{'ARDUINO_FUSES'} || 0
$ENV{'ARDUINO_FUSES'}
Truth table0%0/2
A
A= $ENV{'ARDUINO_FUSES'}
Aresult
11
00
45 if $config eq 'fuses';
46  
47 0 ▶ return $ENV{'ARDUINO_UPLOADER'} || undef
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "uploader" 0 0 0
Condition0%0/2
$ENV{'ARDUINO_UPLOADER'} || undef
l!l
00
MC/DC0%0/1
$ENV{'ARDUINO_UPLOADER'} || undef
$ENV{'ARDUINO_UPLOADER'}
Truth table0%0/2
A
A= $ENV{'ARDUINO_UPLOADER'}
Aresult
11
00
48 if $config eq 'uploader';
49  
50 0 ▶ return $self -> ini($config) || $ENV{'ARDUINO_LIBS'} || ''
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "libs" 0 0 0
Condition0%0/5
$self->ini($config) || $ENV{'ARDUINO_LIBS'} || ''
l!l
00
$self->ini($config) or $ENV{"ARDUINO_LIBS"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->ini($config) || $ENV{'ARDUINO_LIBS'} || ''
$self->ini($config) $ENV{"ARDUINO_LIBS"}
Truth table0%0/3
A or B
A= $self->ini($config)B= $ENV{"ARDUINO_LIBS"}
ABresult
1X1
011
000
51 if $config eq 'libs';
52  
53 0 ▶ return $ENV{'ARDUINO_SKETCHBOOK'} || "$ENV{'HOME'}/sketchbook"
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "sketchbook" 0 0 0
Condition0%0/2
$ENV{'ARDUINO_SKETCHBOOK'} || "$ENV{'HOME'}/sketchbook"
l!l
00
MC/DC0%0/1
$ENV{'ARDUINO_SKETCHBOOK'} || "$ENV{'HOME'}/sketchbook"
$ENV{'ARDUINO_SKETCHBOOK'}
Truth table0%0/2
A
A= $ENV{'ARDUINO_SKETCHBOOK'}
Aresult
11
00
54 if $config eq 'sketchbook';
55  
56 0 ▶ return $ENV{'ARDUINO_ROOT'} || '/usr/share/arduino'
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "root" 0 0 0
Condition0%0/2
$ENV{'ARDUINO_ROOT'} || '/usr/share/arduino'
l!l
00
MC/DC0%0/1
$ENV{'ARDUINO_ROOT'} || '/usr/share/arduino'
$ENV{'ARDUINO_ROOT'}
Truth table0%0/2
A
A= $ENV{'ARDUINO_ROOT'}
Aresult
11
00
57 if $config eq 'root';
58  
59 0 ▶ return $self -> ini($config) || $ENV{'ARDUINO_HARDWARE'} || 'arduino'
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "hardware" 0 0 0
Condition0%0/5
$self->ini($config) || $ENV{'ARDUINO_HARDWARE'} || 'arduino'
l!l
00
$self->ini($config) or $ENV{"ARDUINO_HARDWARE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->ini($config) || $ENV{'ARDUINO_HARDWARE'} || 'arduino'
$self->ini($config) $ENV{"ARDUINO_HARDWARE"}
Truth table0%0/3
A or B
A= $self->ini($config)B= $ENV{"ARDUINO_HARDWARE"}
ABresult
1X1
011
000
60 if $config eq 'hardware';
61 }
62  
63 0 ▶sub board_config {
Subroutine board_config: not called CC=6 SCAR=37.4
Pod undocumented
64 0 my ($self, $opt, $config) = @_;
65  
66 0 my $board = $opt -> board;
67  
68 0 my $boards = $self -> file($opt, 'hardware/' .
69 $opt -> hardware . '/boards.txt');
70  
71 0 ▶ open my $fh, '<', $boards
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $boards or die "Can't open file 'boards.txt'.\n" 0 0 0
72 or die "Can't open file 'boards.txt'.\n";
73  
74 0 my $value = undef;
75  
76 0 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
77 0 chomp $line;
78  
79 0 my $first = substr $line, 0, 1;
80  
81 0 ▶ next if $first eq '#' or $first eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $first eq "#" or $first eq "" 0 0 0
Condition0%0/3
$first eq "#" or $first eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
$first eq "#" or $first eq ""
$first eq "#" $first eq ""
Truth table0%0/3
A or B
A= $first eq "#"B= $first eq ""
ABresult
1X1
011
000
82 0 ▶ next unless $line =~ /^$board\.$config\=/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^$board\.$config\=/ 0 0 0
83  
84 0 (undef, $value) = split '=', $line;
85 }
86  
87 0 close $fh;
88  
89 0 return $value;
90 }
91  
92 0 ▶sub file {
Subroutine file: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my ($self, $opt, $file) = @_;
94  
95 0 my $path = $opt -> root . '/' . $file;
96 0 ▶ return $path if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 0 0
97  
98 0 die "Can't find file '" . basename($file) . "'.\n";
99 }
100  
101 =head1 AUTHOR
102  
103 Alessandro Ghedini <alexbio@cpan.org>
104  
105 =head1 LICENSE AND COPYRIGHT
106  
107 Copyright 2013 Alessandro Ghedini.
108  
109 This program is free software; you can redistribute it and/or modify it
110 under the terms of either: the GNU General Public License as published
111 by the Free Software Foundation; or the Artistic License.
112  
113 See http://dev.perl.org/licenses/ for more information.
114  
115 =cut
116  
117 7 1; # End of App::duino::Command
↑ Summary duino/Command/upload.pm »