Qgoda/Command.pm

filter: Statementstmt 68.5% 37 / 54 Branchbran 20.0% 2 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 3 totaltotal 57.8% 48 / 83 CC 8 SCAR 17.3
CC
8
Cov
61%
_displayHelp
20.0
parseOptions
4.1
run
2.0
CRAP 5.6
« Qgoda/Migrator.pm ↑ Summary Qgoda/Logger.pm »
1 #! /bin/false
2  
3 # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>,
4 # all rights reserved.
5  
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10  
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15  
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18  
19 package Qgoda::Command;
20 2 $Qgoda::Command::VERSION = 'v0.9.2';
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Getopt::Long 2.36 qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 ▶use Qgoda::CLI;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Qgoda::Util qw(class2module);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub new {
30 2 ▶ my ($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
31  
32 2 my $self = '';
33 2 bless \$self, $class;
34 }
35  
36 sub run {
37 2 ▶ my ($self, $args, $global_options) = @_;
Subroutine run: called CC=2 SCAR=7.0
Pod undocumented
38  
39 2 ▶ $args ||= [];
Condition50%1/2
$args ||= []
l!l
20
MC/DC0%0/1
$args ||= []
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
40 2 my %options = $self->parseOptions($args);
41  
42 2 return $self->_run($args, $global_options, %options);
43 }
44  
45 sub parseOptions {
46 2 ▶ my ($self, $args) = @_;
Subroutine parseOptions: called CC=4 SCAR=14.2
Pod undocumented
47  
48 2 my %options = $self->_getDefaults;
49 2 my %specs = $self->_getOptionSpecs;
50 2 $specs{help} = 'h|help';
51  
52 2 my %optspec;
53 2 foreach my $key (keys %specs) {
54 $optspec{$specs{$key}} =
55 10 ▶ ref $options{$key} ? $options{$key} : \$options{$key};
Branch: 1 branch
BranchTrueFalseTotal
ref $options{$key} ? : 0 10 10
56 }
57  
58 2 Getopt::Long::Configure('bundling');
59 {
60 2 local $SIG{__WARN__} = sub {
61 0 ▶ $SIG{__WARN__} = 'DEFAULT';
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 $self->__usageError(shift);
63 2 };
64  
65 2 GetOptionsFromArray($args, %optspec);
66 }
67  
68 # Exits.
69 2 ▶ $self->_displayHelp if $options{help};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"help"} 0 2 2
70  
71 2 return %options;
72 }
73  
74 ▶sub _getDefaults {}
Subroutine _getDefaults: not called CC=1 SCAR=0.0
75 ▶sub _getOptionSpecs {};
Subroutine _getOptionSpecs: not called CC=1 SCAR=0.0
76  
77 sub __usageError {
78 0 ▶ my ($self, @msg) = @_;
Subroutine __usageError: not called CC=1 SCAR=6.9
79  
80 0 my $class = ref $self;
81 0 $class =~ s/^Qgoda::Command:://;
82 0 my $cmd = join '-', map { lcfirst $_ } split /::/, $class;
83  
84 0 return Qgoda::CLI->commandUsageError($cmd, @msg);
85 }
86  
87 sub _displayHelp {
88 0 ▶ my ($self) = @_;
Subroutine _displayHelp: not called CC=4 SCAR=30.0
89  
90 0 my $module = class2module ref $self;
91  
92 0 my $path = $INC{$module};
93 0 ▶ $path = './' . $path if !File::Spec->file_name_is_absolute($path);
Branch: 1 branch
BranchTrueFalseTotal
unless "File::Spec"->file_name_is_absolute($path) 0 0 0
94  
95 0 ▶ $^W = 1 if $ENV{'PERLDOCDEBUG'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERLDOCDEBUG"} 0 0 0
96 0 ▶ pop @INC if $INC[-1] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $INC[-1] eq "." 0 0 0
97 0 require Pod::Perldoc;
98 0 local @ARGV = ($path);
99 0 exit(Pod::Perldoc->run());
100 }
101  
102 2 1;
« Qgoda/Migrator.pm ↑ Summary Qgoda/Logger.pm »