scripts/yatt

filter: Statementstmt 76.1% 64 / 84 Branchbran 29.1% 7 / 24 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 84.2% 16 / 19 Podpod n/a totaltotal 65.9% 89 / 135 CC 12 SCAR 15.8
CC
12
Cov
65%
subcmd_path
20.0
usage
6.0
BEGIN
4.1
CRAP 4.9
« blib/lib/YATT/Lite/Response.pm ↑ Summary blib/lib/YATT/Lite/Partial.pm »
1 #!/usr/bin/env perl
2 # -*- mode: perl; coding: utf-8 -*-
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use constant DEBUG_LIB => $ENV{DEBUG_YATT_CLI_LIB};
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use FindBin; BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=3 SCAR=14.2
7 1 ▶ if (-r (my $libFn = "$FindBin::RealBin/libdir.pl")) {
Branch: 2 branches
BranchTrueFalseTotal
if (-r (my $libFn = "$FindBin::RealBin/libdir.pl")) { } 1 0 1
elsif ($FindBin::RealBin =~ m[/local/bin$ ]x) { } 0 0 0
8 1 print STDERR "# using $libFn\n" if DEBUG_LIB;
9 1 do $libFn
10 }
11 elsif ($FindBin::RealBin =~ m{/local/bin$ }x) {
12 0 print STDERR "# using local/lib/perl5\n" if DEBUG_LIB;
13 0 require lib;
14 0 lib->import($FindBin::RealBin . "/../lib/perl5");
15 }
16 else {
17 0 print STDERR "# No special libdir\n" if DEBUG_LIB;
18 }
19 }
20  
21 sub MY () {__PACKAGE__}
22 #----------------------------------------
23 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use base qw/YATT::Lite::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 use YATT::Lite::MFields
27 1 ▶ (()
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 , [help => doc => "show help messages"]
29 , [script_path => doc => "script search path for yatt subcommands"]
30 , [debug => doc => "run in perldebugger"]
31 1 );
32 # XXX: Should use doc strings in help message.
33  
34 1 ▶use YATT::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use YATT::Lite::Util::CmdLine qw/parse_opts/;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use List::Util qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 {
39 1 my MY $self = MY->new(MY->parse_opts(\@ARGV, undef, {h => "help", d => "debug"}));
40  
41 1 ▶ my $cmd = shift // 'help';
Condition50%1/2
shift @ARGV // "help"
l!l
01
MC/DC0%0/1
shift @ARGV // "help"
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
42  
43 1 ▶ if (my $sub = $self->can("cmd_$cmd")) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $sub = $self->can("cmd_$cmd")) { } 1 0 1
elsif (my $fn = $self->subcmd_path($cmd)) { } 0 0 0
44 1 $sub->($self, @ARGV);
45 } elsif (my $fn = $self->subcmd_path($cmd)) {
46 0 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'debug'}) { } 0 0 0
47 0 ▶ exec $^X, "-d", $fn, @ARGV or die "couldn't exec $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
exec $^X, "-d", $fn, @ARGV or die "couldn't exec ${fn}: $!" 0 0 0
48 } else {
49 0 ▶ exec $fn, @ARGV or die "couldn't exec $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
exec $fn, @ARGV or die "couldn't exec ${fn}: $!" 0 0 0
50 }
51 } else {
52 0 $self->usage("No such command: $cmd");
53 }
54 }
55  
56 0 ▶sub usage {
Subroutine usage: not called CC=2 SCAR=17.9
57 0 (my MY $self, my $message) = @_;
58 0 ▶ print STDERR "$message\n" if $message;
Branch: 1 branch
BranchTrueFalseTotal
if $message 0 0 0
59 0 $self->cmd_help;
60 }
61  
62 1 ▶sub cmd_help {
Subroutine cmd_help: called CC=1 SCAR=0.0
63 1 my MY $self = shift;
64 1 print STDERR <<END;
65 1 Usage: @{[File::Basename::basename $0]} [--option=value] <command> [<args>]
66  
67 Available commands are:
68 END
69  
70 1 print STDERR " ", join("\n ", $self->subcmd_list), "\n";
71 1 exit 1;
72 }
73  
74 1 ▶sub subcmd_list {
Subroutine subcmd_list: called CC=4 SCAR=13.9
75 1 (my MY $self) = @_;
76 1 my $prefix = "$self->{script_path}yatt";
77 1 my %hidden; $hidden{$_} = 1
78 1 for qw(backend call command dispatcher
79 lintany lintpm lintrc
80 xgettext);
81 grep {
82 13 not $hidden{$_}
83 }
84 uniq sort map {
85 15 my $rest = substr($_, length($prefix));
86 15 ▶ if ($rest =~ s/^\.//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rest =~ s/^\.//) { } 12 3 15
elsif ($rest =~ /^-([-\w]+)/) { } 1 2 3
87 12 $rest;
88 } elsif ($rest =~ /^-([-\w]+)/) {
89 1 $1;
90 } else {
91 2 ();
92 }
93 }
94 1 grep {-x}
95 1 ▶ glob("$prefix*");
Subroutine BEGIN: called CC=1 SCAR=0.0
96 }
97  
98 0 ▶sub subcmd_path {
Subroutine subcmd_path: not called CC=4 SCAR=30.0
99 0 (my MY $self, my $subcmd) = @_;
100 0 foreach my $fnPat (qw(yatt-%s* yatt.%s)) {
101 0 my $glob = $self->{script_path}. sprintf($fnPat, $subcmd);
102 0 foreach my $fn (glob($glob)) {
103 0 ▶ return $fn if -x $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -x $fn 0 0 0
104 }
105 }
106 }
107  
108 0 ▶sub find_libdir {
Subroutine find_libdir: not called CC=1 SCAR=6.9
109 0 shift;
110 0 my $pm = 'YATT/Lite.pm';
111 0 substr($INC{$pm}, 0, -1-length($pm));
112 }
113  
114 1 ▶sub after_new {
Subroutine after_new: called CC=3 SCAR=12.7
115 1 (my MY $self) = @_;
116 1 ▶ $self->{script_path} //= do {
Condition33%1/3
$self->{"script_path"} //= do { if ($FindBin::RealBin =~ m[/YATT/scripts\z]) { $self->find_libdir . '/YATT/scripts/'; } else { $FindBin::Bin . '/'; } }
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"script_path"} //= do { if ($FindBin::RealBin =~ m[/YATT/scripts\z]) { $self->find_libdir . '/YATT/scripts/'; } else { $FindBin::Bin . '/'; } }
$self->{"script_path"} do { if ($FindBin::RealBin =~ m[/YATT/scripts\z]) { $self->find_libdir . '/YATT/scripts/'; } else { $FindBin::Bin . '/'; } }
Truth table33%1/3
A //= B
A= $self->{"script_path"}B= do { if ($FindBin::RealBin =~ m[/YATT/scripts\z]) { $self->find_libdir . '/YATT/scripts/'; } else { $FindBin::Bin . '/'; } }
ABresult
1X1
011
000
117 1 ▶ if ($FindBin::RealBin =~ m{/YATT/scripts\z}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FindBin::RealBin =~ m[/YATT/scripts\z]) { } 0 1 1
118 0 $self->find_libdir . "/YATT/scripts/"
119 } else {
120 1 $FindBin::Bin . "/";
121 }
122 };
123 }
« blib/lib/YATT/Lite/Response.pm ↑ Summary blib/lib/YATT/Lite/Partial.pm »