| 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 ||= []
MC/DC0%0/1
$args ||= []
$args
Truth table50%1/2
A
A= $args
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 94 | |||||||||||||
| 95 | 0 | ▶ | $^W = 1 if $ENV{'PERLDOCDEBUG'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 0 | ▶ | pop @INC if $INC[-1] eq '.'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | 0 | require Pod::Perldoc; | |||||||||||
| 98 | 0 | local @ARGV = ($path); | |||||||||||
| 99 | 0 | exit(Pod::Perldoc->run()); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 2 | 1; | |||||||||||