Respite/CommandLine.pm

filter: Statementstmt 6.9% 13 / 186 Branchbran 0.0% 0 / 114 Conditioncond 0.0% 0 / 123 MC/DCmcdc 0.0% 0 / 68 Subroutinesub 17.3% 4 / 23 Podpod 12.5% 1 / 8 totaltotal 3.4% 18 / 522 CC 109 SCAR 61.2
CC
109
Cov
3%
_run_method
870.0
print_data
702.0
_pod
420.0
CRAP 455.0
« Respite/Server.pm ↑ Summary Respite/Base.pm »
1 package Net::Respite::CommandLine;
2  
3 =head1 NAME
4  
5 Net::Respite::CommandLine - Provide an easy way to get commandline abstraction of Net::Respite::Base
6  
7 =cut
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Throw qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
15 0 my ($class, $args) = @_;
16 0 ▶ return bless {%{$args || {}}}, $class;
Condition0%0/2
$args || {}
l!l
00
MC/DC0%0/1
$args || {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
17 }
18  
19 0 ▶sub api_meta { shift->{'api_meta'} }
Subroutine api_meta: not called CC=1 SCAR=6.9
Pod documented
20 0 ▶sub dispatch_class { shift->{'dispatch_class'} }
Subroutine dispatch_class: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 0 ▶sub dispatch_factory { # this is identical to code in Net::Respite::Server
Subroutine dispatch_factory: not called CC=10 SCAR=47.0
Pod undocumented
23 0 my ($self, $preload) = @_;
24 0 ▶ return $self->{'dispatch_factory'} ||= do {
Condition0%0/3
$self->{"dispatch_factory"} ||= do { my $meta = $self->api_meta || $self->dispatch_class || throw("Missing one of api_meta or dispatch_class"); if (not ref $meta) { (my $file = "$meta.pm") =~ s[::][/]g; throw("Failed to load dispatch class", {"class", $meta, "file", $file, "msg", $@}) unless $meta->can("new") or eval { do { require $file } }; throw("Specified class does not have a run_method method", {"class", $meta}) unless $meta->can("run_method"); sub { $meta->new(@_); } ; } elsif ($meta->{"remote"}) { require Net::Respite::Client; sub { "Net::Respite::Client"->new({%{shift() or {};}, %$meta}); } ; } else { require Net::Respite::Base; "Net::Respite::Base"->new({"api_meta", $meta})->api_preload if $preload; sub { "Net::Respite::Base"->new({%{shift() or {};}, "api_meta", $meta}); } ; } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dispatch_factory"} ||= do { my $meta = $self->api_meta || $self->dispatch_class || throw("Missing one of api_meta or dispatch_class"); if (not ref $meta) { (my $file = "$meta.pm") =~ s[::][/]g; throw("Failed to load dispatch class", {"class", $meta, "file", $file, "msg", $@}) unless $meta->can("new") or eval { do { require $file } }; throw("Specified class does not have a run_method method", {"class", $meta}) unless $meta->can("run_method"); sub { $meta->new(@_); } ; } elsif ($meta->{"remote"}) { require Net::Respite::Client; sub { "Net::Respite::Client"->new({%{shift() or {};}, %$meta}); } ; } else { require Net::Respite::Base; "Net::Respite::Base"->new({"api_meta", $meta})->api_preload if $preload; sub { "Net::Respite::Base"->new({%{shift() or {};}, "api_meta", $meta}); } ; } }
$self->{"dispatch_factory"} do { my $meta = $self->api_meta || $self->dispatch_class || throw("Missing one of api_meta or dispatch_class"); if (not ref $meta) { (my $file = "$meta.pm") =~ s[::][/]g; throw("Failed to load dispatch class", {"class", $meta, "file", $file, "msg", $@}) unless $meta->can("new") or eval { do { require $file } }; throw("Specified class does not have a run_method method", {"class", $meta}) unless $meta->can("run_method"); sub { $meta->new(@_); } ; } elsif ($meta->{"remote"}) { require Net::Respite::Client; sub { "Net::Respite::Client"->new({%{shift() or {};}, %$meta}); } ; } else { require Net::Respite::Base; "Net::Respite::Base"->new({"api_meta", $meta})->api_preload if $preload; sub { "Net::Respite::Base"->new({%{shift() or {};}, "api_meta", $meta}); } ; } }
Truth table0%0/3
A ||= B
A= $self->{"dispatch_factory"}B= do { my $meta = $self->api_meta || $self->dispatch_class || throw("Missing one of api_meta or dispatch_class"); if (not ref $meta) { (my $file = "$meta.pm") =~ s[::][/]g; throw("Failed to load dispatch class", {"class", $meta, "file", $file, "msg", $@}) unless $meta->can("new") or eval { do { require $file } }; throw("Specified class does not have a run_method method", {"class", $meta}) unless $meta->can("run_method"); sub { $meta->new(@_); } ; } elsif ($meta->{"remote"}) { require Net::Respite::Client; sub { "Net::Respite::Client"->new({%{shift() or {};}, %$meta}); } ; } else { require Net::Respite::Base; "Net::Respite::Base"->new({"api_meta", $meta})->api_preload if $preload; sub { "Net::Respite::Base"->new({%{shift() or {};}, "api_meta", $meta}); } ; } }
ABresult
1X1
011
000
25 0 ▶ my $meta = $self->api_meta || $self->dispatch_class || throw "Missing one of api_meta or dispatch_class";
Condition0%0/6
$self->api_meta || $self->dispatch_class || throw('Missing one of api_meta or dispatch_class')
l!l&&r!l&&!r
000
$self->api_meta or $self->dispatch_class
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->api_meta || $self->dispatch_class || throw('Missing one of api_meta or dispatch_class')
$self->api_meta $self->dispatch_class throw('Missing one of api_meta or dispatch_class')
Truth table0%0/4
A or B || C
A= $self->api_metaB= $self->dispatch_classC= throw('Missing one of api_meta or dispatch_class')
ABCresult
1XX1
01X1
0011
0000
26 0 ▶ if (!ref $meta) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $meta) { } 0 0 0
elsif ($meta->{'remote'}) { } 0 0 0
27 0 (my $file = "$meta.pm") =~ s|::|/|g;
28 0 ▶ throw "Failed to load dispatch class", {class => $meta, file => $file, msg => $@} if !$meta->can('new') && !eval { require $file };
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->can("new") or eval { do { require $file } } 0 0 0
Condition0%0/3
$meta->can("new") or eval { do { require $file } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->can("new") or eval { do { require $file } }
$meta->can("new") eval { do { require $file } }
Truth table0%0/3
A or B
A= $meta->can("new")B= eval { do { require $file } }
ABresult
1X1
011
000
29 0 ▶ throw "Specified class does not have a run_method method", {class => $meta} if ! $meta->can('run_method');
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->can("run_method") 0 0 0
30 0 ▶ sub { $meta->new(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 } elsif ($meta->{'remote'}) {
32 0 require Net::Respite::Client;
33 0 ▶ sub { Net::Respite::Client->new({%{shift() || {}}, %$meta}) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
34 } else {
35 0 require Net::Respite::Base;
36 0 ▶ Net::Respite::Base->new({api_meta => $meta})->api_preload if $preload;
Branch: 1 branch
BranchTrueFalseTotal
if $preload 0 0 0
37 0 ▶ sub { Net::Respite::Base->new({%{shift() || {}}, api_meta => $meta}) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
38 }
39 };
40 }
41  
42 ###----------------------------------------------------------------###
43  
44 0 ▶sub run_commandline { shift->run(@_) }
Subroutine run_commandline: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 0 ▶sub run {
Subroutine run: not called CC=18 SCAR=58.3
Pod undocumented
47 0 my ($self, $args) = @_;
48 0 ▶ $self = $self->new($args) if ! ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
49  
50 0 my $obj = $self->dispatch_factory->();
51 0 ▶ my $ARGV = $args->{'argv'} || $self->{'argv'} || \@ARGV;
Condition0%0/5
$args->{'argv'} || $self->{'argv'} || \@ARGV
l!l
00
$args->{"argv"} or $self->{"argv"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'argv'} || $self->{'argv'} || \@ARGV
$args->{"argv"} $self->{"argv"}
Truth table0%0/3
A or B
A= $args->{"argv"}B= $self->{"argv"}
ABresult
1X1
011
000
52  
53 0 ▶ my $method = shift(@$ARGV) || return print $self->_pod($obj, {brief => 1});
Condition0%0/2
shift @$ARGV || (return print($self->_pod($obj, {'brief', 1})))
l!l
00
MC/DC0%0/1
shift @$ARGV || (return print($self->_pod($obj, {'brief', 1})))
shift @$ARGV
Truth table0%0/2
A
A= shift @$ARGV
Aresult
11
00
54 0 ▶ return print $self->_pod($obj, {format => $1}) if $method =~ /^-{0,2}(help|h|pod|p)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $method =~ /^-{0,2}(help|h|pod|p)$/ 0 0 0
55 0 return print $self->_pod($obj, {method => $method, format => $_}) for grep {/^-{1,2}(help|h|pod|p)$/} @ARGV;
56  
57 0 ▶ throw "Odd number of args passed to commandline. If you want the last value to be undef pass a :null", {argv => $ARGV, _pretty=>1} if @$ARGV % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$ARGV % 2 0 0 0
58 0 my $req = {@$ARGV};
59 0 ▶ throw "Cannot use '' as a keyname - possible invalid args", {argv => $ARGV} if exists $req->{''};
Branch: 1 branch
BranchTrueFalseTotal
if exists $req->{""} 0 0 0
60 0 ▶ foreach my $key (keys %$req) { $req->{$key} = __PACKAGE__->can("_$1")->() if $req->{$key} && $req->{$key} =~ /^:(null|true|false)$/ }
Branch: 1 branch
BranchTrueFalseTotal
if $req->{$key} and $req->{$key} =~ /^:(null|true|false)$/ 0 0 0
Condition0%0/3
$req->{$key} and $req->{$key} =~ /^:(null|true|false)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{$key} and $req->{$key} =~ /^:(null|true|false)$/
$req->{$key} $req->{$key} =~ /^:(null|true|false)$/
Truth table0%0/3
A and B
A= $req->{$key}B= $req->{$key} =~ /^:(null|true|false)$/
ABresult
0X0
100
111
61 0 ▶ $req = Data::URIEncode::flat_to_complex($req) || {} if !$self->{'no_data_uriencode'} && eval { require Data::URIEncode };
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"no_data_uriencode"} and eval { do { require Data::URIEncode } } 0 0 0
Condition0%0/5
not $self->{"no_data_uriencode"} and eval { do { require Data::URIEncode } }
!ll&&!rl&&r
000
Data::URIEncode::flat_to_complex($req) || {}
l!l
00
MC/DC0%0/2
not $self->{"no_data_uriencode"} and eval { do { require Data::URIEncode } }
not $self->{"no_data_uriencode"} eval { do { require Data::URIEncode } }
MC/DC0%0/1
Data::URIEncode::flat_to_complex($req) || {}
Data::URIEncode::flat_to_complex($req)
Truth table0%0/3
not(A) and B
A= not $self->{"no_data_uriencode"}B= eval { do { require Data::URIEncode } }
ABresult
0X0
100
111
Truth table0%0/2
A
A= Data::URIEncode::flat_to_complex($req)
Aresult
11
00
62  
63 0 my $data = $self->_run_method($obj,$method, $req);
64 0 ▶ my $meta = $ENV{'SHOW_META'} ? $self->_run_method($obj,"${method}__meta", $req) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'SHOW_META'} ? : 0 0 0
65 0 $self->print_data($data, $req, $meta);
66 0 ▶ exit(1) if ref($data) && $data->{'error'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $data and $data->{"error"} 0 0 0
Condition0%0/3
ref $data and $data->{"error"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data and $data->{"error"}
ref $data $data->{"error"}
Truth table0%0/3
A and B
A= ref $dataB= $data->{"error"}
ABresult
0X0
100
111
67 }
68  
69 0 ▶sub run_method {
Subroutine run_method: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my ($self, $method, $args) = @_;
71 0 ▶ $self = $self->new($args) if ! ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
72 0 my $obj = $self->dispatch_factory->();
73 0 return $self->_run_method($obj, $method, $args);
74 }
75  
76 0 ▶sub _run_method {
Subroutine _run_method: not called CC=29 SCAR=67.7
77 0 my ($self, $obj, $method, $args, $extra) = @_;
78  
79 0 ▶ local $args->{'_c'} = ['commandline'] if $obj->can('config') ? !$obj->config(no_trace => undef) : 1;
Branch: 2 branches
BranchTrueFalseTotal
if $obj->can("config") ? !$obj->config("no_trace", undef) : 1 0 0 0
$obj->can('config') ? : 0 0 0
80  
81 0 ▶ local $obj->{'remote_ip'} = local $obj->{'api_ip'} = ($ENV{'REALUSER'} || $ENV{'SUDO_USER'}) ? 'sudo' : 'cmdline';
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'REALUSER'} || $ENV{'SUDO_USER'} ? : 0 0 0
Condition0%0/3
$ENV{"REALUSER"} or $ENV{"SUDO_USER"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"REALUSER"} or $ENV{"SUDO_USER"}
$ENV{"REALUSER"} $ENV{"SUDO_USER"}
Truth table0%0/3
A or B
A= $ENV{"REALUSER"}B= $ENV{"SUDO_USER"}
ABresult
1X1
011
000
82 0 ▶ local $obj->{'api_brand'} = $ENV{'BRAND'} || $ENV{'PROV'} if $obj->isa('Net::Respite::Base') && ($ENV{'BRAND'} || $ENV{'PROV'});
Branch: 1 branch
BranchTrueFalseTotal
if $obj->isa("Net::Respite::Base") and $ENV{"BRAND"} || $ENV{"PROV"} 0 0 0
Condition0%0/9
$obj->isa("Net::Respite::Base") and $ENV{"BRAND"} || $ENV{"PROV"}
!ll&&!rl&&r
000
$ENV{"BRAND"} or $ENV{"PROV"}
l!l&&r!l&&!r
000
$ENV{'BRAND'} || $ENV{'PROV'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$obj->isa("Net::Respite::Base") and $ENV{"BRAND"} || $ENV{"PROV"}
$obj->isa("Net::Respite::Base") $ENV{"BRAND"} $ENV{"PROV"}
MC/DC0%0/2
$ENV{'BRAND'} || $ENV{'PROV'}
$ENV{'BRAND'} $ENV{'PROV'}
Truth table0%0/4
A and B or C
A= $obj->isa("Net::Respite::Base")B= $ENV{"BRAND"}C= $ENV{"PROV"}
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/3
A || B
A= $ENV{'BRAND'}B= $ENV{'PROV'}
ABresult
1X1
011
000
83 0 ▶ local $obj->{'remote_user'} = $ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid($<))[0] || '-unknown-';
Condition0%0/14
$ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid $<)[0] || '-unknown-'
l!l
00
$ENV{"REALUSER"} or $ENV{"SUDO_USER"} or $ENV{"REMOTE_USER"} or $ENV{"USER"} or (getpwuid $<)[0]
l!l&&r!l&&!r
000
$ENV{"REALUSER"} or $ENV{"SUDO_USER"} or $ENV{"REMOTE_USER"} or $ENV{"USER"}
l!l&&r!l&&!r
000
$ENV{"REALUSER"} or $ENV{"SUDO_USER"} or $ENV{"REMOTE_USER"}
l!l&&r!l&&!r
000
$ENV{"REALUSER"} or $ENV{"SUDO_USER"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid $<)[0] || '-unknown-'
$ENV{"REALUSER"} $ENV{"SUDO_USER"} $ENV{"REMOTE_USER"} $ENV{"USER"} (getpwuid $<)[0]
Truth table0%0/6
A or B or C or D or E
A= $ENV{"REALUSER"}B= $ENV{"SUDO_USER"}C= $ENV{"REMOTE_USER"}D= $ENV{"USER"}E= (getpwuid $<)[0]
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
84 0 ▶ local $obj->{'token'} = $self->{'token'} || $ENV{'ADMIN_Respite_TOKEN'} if $self->{'token'} || $ENV{'ADMIN_Respite_TOKEN'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"token"} or $ENV{"ADMIN_Respite_TOKEN"} 0 0 0
Condition0%0/6
$self->{"token"} or $ENV{"ADMIN_Respite_TOKEN"}
l!l&&r!l&&!r
000
$self->{'token'} || $ENV{'ADMIN_Respite_TOKEN'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"token"} or $ENV{"ADMIN_Respite_TOKEN"}
$self->{"token"} $ENV{"ADMIN_Respite_TOKEN"}
MC/DC0%0/2
$self->{'token'} || $ENV{'ADMIN_Respite_TOKEN'}
$self->{'token'} $ENV{'ADMIN_Respite_TOKEN'}
Truth table0%0/3
A or B
A= $self->{"token"}B= $ENV{"ADMIN_Respite_TOKEN"}
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $self->{'token'}B= $ENV{'ADMIN_Respite_TOKEN'}
ABresult
1X1
011
000
85 0 local $obj->{'transport'} = 'cmdline';
86 0 ▶ $obj->commandline_init($method, $args, $self) if $obj->can('commandline_init');
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("commandline_init") 0 0 0
87  
88 0 ▶ my $run = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
89 0 ▶ my $data = eval { $obj->can('run_method') ? $obj->run_method(@_) : $obj->$method($args, ($extra ? $extra : ())) };
Branch: 2 branches
BranchTrueFalseTotal
$obj->can('run_method') ? : 0 0 0
$extra ? : 0 0 0
90 0 ▶ $data = $@ if ! ref $data;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data 0 0 0
91 0 ▶ return !ref($data) ? {error => 'Commandline failed', msg => $data} : (blessed($data) && $data->can('data')) ? $data->data : $data;
Branch: 2 branches
BranchTrueFalseTotal
!ref($data) ? : 0 0 0
builtin::blessed($data) && $data->can('data') ? : 0 0 0
Condition0%0/3
builtin::blessed($data) and $data->can("data")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($data) and $data->can("data")
builtin::blessed($data) $data->can("data")
Truth table0%0/3
A and B
A= builtin::blessed($data)B= $data->can("data")
ABresult
0X0
100
111
92 0 };
93 0 my $ref = $run->($method, $args, $extra);
94 0 ▶ while ($ref->{'error'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->{"error"}) 0 0 0
95 0 ▶ last if !$ref->{'type'} || $ref->{'type'} !~ /^token_\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->{"type"} and $ref->{"type"} =~ /^token_\w+$/ 0 0 0
Condition0%0/3
$ref->{"type"} and $ref->{"type"} =~ /^token_\w+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$ref->{"type"} and $ref->{"type"} =~ /^token_\w+$/
$ref->{"type"} $ref->{"type"} =~ /^token_\w+$/
Truth table0%0/3
A and B
A= $ref->{"type"}B= $ref->{"type"} =~ /^token_\w+$/
ABresult
0X0
100
111
96 0 ▶ last if $self->{'no_token_retry'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"no_token_retry"} 0 0 0
97 0 warn "Prompting for authorization and retry ($ref->{'type'}: $ref->{'error'})\n";
98 0 ▶ eval { require IO::Prompt } || throw "Please install IO::Prompt to authenticate from commandline", {msg => $@};
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Prompt } } or throw("Please install IO::Prompt to authenticate from commandline", {"msg", $@}) 0 0 0
99 0 ▶ my $user = ''.IO::Prompt::prompt(" Web Auth Username: ", -d => $obj->{'remote_user'}) || $obj->{'remote_user'};
Condition0%0/3
'' . IO::Prompt::prompt(' Web Auth Username: ', '-d', $obj->{'remote_user'}) || $obj->{'remote_user'}
l!l&&r!l&&!r
000
MC/DC0%0/2
'' . IO::Prompt::prompt(' Web Auth Username: ', '-d', $obj->{'remote_user'}) || $obj->{'remote_user'}
'' . IO::Prompt::prompt(' Web Auth Username: ', '-d', $obj->{'remote_user'}) $obj->{'remote_user'}
Truth table0%0/3
A || B
A= '' . IO::Prompt::prompt(' Web Auth Username: ', '-d', $obj->{'remote_user'})B= $obj->{'remote_user'}
ABresult
1X1
011
000
100 0 ▶ my $pass = ''.IO::Prompt::prompt(" Web Auth Password ($user): ", -e => '*') || throw "Cannot proceed without password";
Condition0%0/3
'' . IO::Prompt::prompt(" Web Auth Password ($user): ", '-e', '*') || throw('Cannot proceed without password')
l!l&&r!l&&!r
000
MC/DC0%0/2
'' . IO::Prompt::prompt(" Web Auth Password ($user): ", '-e', '*') || throw('Cannot proceed without password')
'' . IO::Prompt::prompt(" Web Auth Password ($user): ", '-e', '*') throw('Cannot proceed without password')
Truth table0%0/3
A || B
A= '' . IO::Prompt::prompt(" Web Auth Password ($user): ", '-e', '*')B= throw('Cannot proceed without password')
ABresult
1X1
011
000
101 my $key = !$obj->can('config') ? $config::config{'plaintext_public_key'}
102 0 ▶ : $obj->config(plaintext_public_key => sub { $obj->config(plaintext_public_key => sub { $obj->_configs->{'plaintext_public_key'} }, 'emp_auth') });
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
!$obj->can('config') ? : 0 0 0
103 0 ▶ if (!$key) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $key) { } 0 0 0
elsif (not eval { do { require Crypt::OpenSSL::RSA } }) { } 0 0 0
104 0 warn " Could not find plaintext_public_key in config - sending plaintext password\n";
105 0 } elsif (!eval { require Crypt::OpenSSL::RSA }) {
106 0 warn " (Crypt::OpenSSL::RSA is not installed - install to avoid sending plaintext password)\n";
107 } else {
108 0 my $c = Crypt::OpenSSL::RSA->new_public_key($key);
109 0 my $len = length($pass) + 1;
110 0 $pass = pack 'u*', $c->encrypt(pack "Z$len", $pass);
111 0 $pass = "RSA".length($pass).":$pass";
112 }
113 0 $obj->{'token'} = "$user/i:cmdline/$pass";
114 0 $ref = $run->(hello => {test_auth => 1});
115 0 ▶ $self->{'token'} = $obj->{'token'} = $ref->{'token'} || throw "Did not get a token back from successful test_auth", {data => $ref};
Condition0%0/3
$ref->{'token'} || throw('Did not get a token back from successful test_auth', {'data', $ref})
l!l&&r!l&&!r
000
MC/DC0%0/2
$ref->{'token'} || throw('Did not get a token back from successful test_auth', {'data', $ref})
$ref->{'token'} throw('Did not get a token back from successful test_auth', {'data', $ref})
Truth table0%0/3
A || B
A= $ref->{'token'}B= throw('Did not get a token back from successful test_auth', {'data', $ref})
ABresult
1X1
011
000
116 0 warn "\nexport ADMIN_Respite_TOKEN=$obj->{'token'}\n\n";
117 0 $ref = $run->($method, $args, $extra);
118 }
119 0 return $ref;
120 }
121  
122 0 ▶sub print_data {
Subroutine print_data: not called CC=26 SCAR=65.5
Pod undocumented
123 0 my ($self, $data, $args, $meta) = @_;
124 0 ▶ if ($ENV{'CSV'} and my @fields = grep {ref($data->{$_}) eq 'ARRAY' && ref($data->{$_}->[0]) eq 'HASH'} sort keys %$data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"CSV"} and my(@fields) = grep({ref $data->{$_} eq "ARRAY" and ref $data->{$_}[0] eq "HASH";} sort(keys %$data))) 0 0 0
Condition0%0/6
$ENV{"CSV"} and my(@fields) = grep({ref $data->{$_} eq "ARRAY" and ref $data->{$_}[0] eq "HASH";} sort(keys %$data))
!ll&&!rl&&r
000
ref $data->{$_} eq 'ARRAY' && ref $data->{$_}[0] eq 'HASH'
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"CSV"} and my(@fields) = grep({ref $data->{$_} eq "ARRAY" and ref $data->{$_}[0] eq "HASH";} sort(keys %$data))
$ENV{"CSV"} my(@fields) = grep({ref $data->{$_} eq "ARRAY" and ref $data->{$_}[0] eq "HASH";} sort(keys %$data))
MC/DC0%0/2
ref $data->{$_} eq 'ARRAY' && ref $data->{$_}[0] eq 'HASH'
ref $data->{$_} eq 'ARRAY' ref $data->{$_}[0] eq 'HASH'
Truth table0%0/3
A and B
A= $ENV{"CSV"}B= my(@fields) = grep({ref $data->{$_} eq "ARRAY" and ref $data->{$_}[0] eq "HASH";} sort(keys %$data))
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= ref $data->{$_} eq 'ARRAY'B= ref $data->{$_}[0] eq 'HASH'
ABresult
0X0
100
111
125 0 require Text::CSV_XS;
126 0 my $csv = Text::CSV_XS->new({eol => "\n"});
127 0 foreach my $field (@fields) {
128 0 ▶ print "----- $field -------------------------\n" if @fields > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @fields > 1 0 0 0
129 0 ▶ my @keys = sort {($a eq 'id') ? -1 : ($b eq 'id') ? 1 : $a cmp $b } keys %{ $data->{'rows'}->[0] };
Branch: 2 branches
BranchTrueFalseTotal
$a eq 'id' ? : 0 0 0
$b eq 'id' ? : 0 0 0
130 0 $csv->print(\*STDOUT, \@keys);
131 0 ▶ $csv->print(\*STDOUT, [map {ref($_) eq 'ARRAY' ? join(",",@$_) : ref($_) eq 'HASH' ? join(",",%$_) : $_} @$_{@keys}]) for @{ $data->{'rows'} };
Branch: 2 branches
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 0 0
ref $_ eq 'HASH' ? : 0 0 0
132 }
133 0 exit;
134 }
135 0 ▶ if ($ENV{'YAML'}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ENV{'YAML'}) { } 0 0 0
elsif ($ENV{'JSON'} or not eval { do { require Text::PrettyTable } }) { } 0 0 0
elsif ($ENV{'PERL'}) { } 0 0 0
136 0 ▶ eval { require YAML } || throw "Could not load YAML for output", {msg => $@};
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require YAML } } or throw("Could not load YAML for output", {"msg", $@}) 0 0 0
137 0 print YAML->new->Dump($data);
138 0 ▶ } elsif ($ENV{'JSON'} || ! eval { require Text::PrettyTable }) {
Condition0%0/3
$ENV{"JSON"} or not eval { do { require Text::PrettyTable } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{"JSON"} or not eval { do { require Text::PrettyTable } }
$ENV{"JSON"} not eval { do { require Text::PrettyTable } }
Truth table0%0/3
A or not(B)
A= $ENV{"JSON"}B= not eval { do { require Text::PrettyTable } }
ABresult
1X1
011
000
139 0 ▶ eval { require JSON } || throw "Could not load JSON for output", {msg => $@};
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require JSON } } or throw("Could not load JSON for output", {"msg", $@}) 0 0 0
140 0 my $json = JSON->new->utf8->allow_nonref->convert_blessed->pretty->canonical;
141 0 ▶ print "meta = ".$json->encode($meta) if $ENV{'SHOW_META'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SHOW_META"} 0 0 0
142 0 print "args = ".$json->encode($args);
143 0 print "data = ".$json->encode($data);
144 } elsif ($ENV{'PERL'}) {
145 0 ▶ if (eval { require Data::Debug }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Data::Debug } }) { } 0 0 0
146 0 Data::Debug::debug($args, $data);
147 } else {
148 0 require Data::Dumper;
149 0 ▶ print Data::Dumper::Dumper($_) for $ENV{'SHOW_META'} ? $meta : (), $args, $data;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'SHOW_META'} ? : 0 0 0
150 }
151 } else {
152 0 my $p = Text::PrettyTable->new({auto_collapse => 1});
153 0 ▶ if ($ENV{'SHOW_META'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"SHOW_META"}) 0 0 0
154 0 print "Meta:\n";
155 0 print $p->tablify($meta);
156 }
157 0 print "Arguments:\n";
158 0 print $p->tablify($args);
159 0 ▶ if ((scalar(keys %$data) == 1 || $data->{'n_pages'} && $data->{'n_pages'} == 1) && $data->{'rows'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$data == 1 || $data->{'n_pages'} && $data->{'n_pages'} == 1 and $data->{'rows'}) { } 0 0 0
Condition0%0/9
scalar keys %$data == 1 || $data->{"n_pages"} && $data->{"n_pages"} == 1 and $data->{"rows"}
!ll&&!rl&&r
000
scalar keys %$data == 1 or $data->{"n_pages"} and $data->{"n_pages"} == 1
l!l&&r!l&&!r
000
$data->{"n_pages"} and $data->{"n_pages"} == 1
!ll&&!rl&&r
000
MC/DC0%0/4
scalar keys %$data == 1 || $data->{"n_pages"} && $data->{"n_pages"} == 1 and $data->{"rows"}
scalar keys %$data == 1 $data->{"n_pages"} $data->{"n_pages"} == 1 $data->{"rows"}
Truth table0%0/6
A or B and C and D
A= scalar keys %$data == 1B= $data->{"n_pages"}C= $data->{"n_pages"} == 1D= $data->{"rows"}
ABCDresult
00XX0
010X0
1XX00
01100
1XX11
01111
160 0 print "Data Rows:\n";
161 0 print $p->tablify($data->{'rows'});
162 } else {
163 0 print "Data:\n";
164 0 print $p->tablify($data);
165 }
166 }
167 }
168  
169 0 ▶sub _false { require JSON; JSON::false() }
Subroutine _false: not called CC=1 SCAR=6.9
170 0 ▶sub _null { undef }
Subroutine _null: not called CC=1 SCAR=6.9
171 0 ▶sub _true { require JSON; JSON::true() }
Subroutine _true: not called CC=1 SCAR=6.9
172  
173 0 ▶sub _pod {
Subroutine _pod: not called CC=20 SCAR=60.4
174 0 my ($self, $obj, $args) = @_;
175 0 my $class = ref($obj);
176 0 ▶ my $script = $args->{'script'} || $0;
Condition0%0/3
$args->{'script'} || $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'script'} || $0
$args->{'script'} $0
Truth table0%0/3
A || B
A= $args->{'script'}B= $0
ABresult
1X1
011
000
177 0 ▶ my $meth = $args->{'method'} || 'methodname';
Condition0%0/2
$args->{'method'} || 'methodname'
l!l
00
MC/DC0%0/1
$args->{'method'} || 'methodname'
$args->{'method'}
Truth table0%0/2
A
A= $args->{'method'}
Aresult
11
00
178 0 my $out = "=head1 NAME\n\n"
179 ."$script - commandline interface to $class methods\n\n"
180 ."=head1 SYNOPSIS\n\n"
181 ." $script $meth\n\n"
182 ." $script $meth --help\n\n"
183 ." $script $meth methods # brief list of methods \n\n"
184 ." $script $meth key1 value1 key2 value2\n\n"
185 ." $script $meth key1:0 arrayvalue1 key1:1 arrayvalue2\n\n"
186 ." JSON=1 $script $meth key1 value1 key2 value2\n\n"
187 ." YAML=1 $script $meth key1 value1 key2 value2\n\n"
188 ." PERL=1 $script $meth key1 value1 key2 value2\n\n"
189 ." CSV=1 $script $meth key1 value1 key2 value2 (only works for fields that are arrays of hashes)\n\n"
190 ." SHOW_META=1 $script $meth key1 value1 key2 value2 (includes meta information for $meth)\n\n"
191 ."Arguments for the hashref should be passed on the commandline as"
192 ." simple key value pairs. If the arguments are more complex, you can"
193 ." pass values in any of the ways that L<Data::URIEncode> supports.\n\n"
194 ."=head1 METHODS\n\n";
195 0 ▶ if ($args->{'brief'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'brief'}) { } 0 0 0
196 0 $out .= join(", ", sort keys %{ $self->_run_method($obj, methods => {})->{'methods'} })."\n\n";
197 } else {
198 0 ▶ my $methods = ($_ = $args->{'method'}) ? {$_ => $self->_run_method($obj, "${_}__meta", {_flat => 1})} : $self->_run_method($obj, methods => {meta => 1, _flat => 1})->{'methods'};
Branch: 1 branch
BranchTrueFalseTotal
($_ = $args->{'method'}) ? : 0 0 0
199 0 foreach my $meth (sort keys %$methods) {
200 0 my $m = $methods->{$meth};
201 0 $out .= "=head2 C<$meth>\n\n";
202 0 ▶ $out .= "$m->{'desc'}\n\n" if $m->{'desc'};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"desc"} 0 0 0
203 0 $out .= "=over 4\n\n";
204 0 my $args = $m->{'args'}; my %uk;
205 0 ▶ foreach my $field (grep {!$uk{$_}++} (map {split /\s*,\s*/} ref($args->{'group order'}) ? @{$args->{'group order'}} : $args->{'group order'}||()), grep {!/^group /} sort keys %$args) {
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{'group order'} ? : 0 0 0
Condition0%0/3
$args->{"group order"} or ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"group order"} or ()
$args->{"group order"} ()
Truth table0%0/3
A or B
A= $args->{"group order"}B= ()
ABresult
1X1
011
000
206 0 $out .= "=item C<$field>\n\n";
207 0 ▶ Data::Debug::debug($meth, $field, $args->{$field}) if ! ref($args->{$field}) && eval {require Data::Debug};
Branch: 1 branch
BranchTrueFalseTotal
if not ref $args->{$field} and eval { do { require Data::Debug } } 0 0 0
Condition0%0/3
not ref $args->{$field} and eval { do { require Data::Debug } }
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $args->{$field} and eval { do { require Data::Debug } }
not ref $args->{$field} eval { do { require Data::Debug } }
Truth table0%0/3
not(A) and B
A= not ref $args->{$field}B= eval { do { require Data::Debug } }
ABresult
0X0
100
111
208 0 ▶ $out .= "(required)\n\n" if $args->{$field}->{'required'};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{$field}{"required"} 0 0 0
209 0 ▶ $out .= "$args->{$field}->{'desc'}\n\n" if $args->{$field}->{'desc'};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{$field}{"desc"} 0 0 0
210 }
211 0 $out .= "=back\n\n";
212 }
213 }
214 0 $out .= "=cut\n";
215 0 ▶ if (!$args->{'format'} || ($args->{'format'} && $args->{'format'} =~ /h/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args->{"format"} or $args->{"format"} and $args->{"format"} =~ /h/) 0 0 0
Condition0%0/6
not $args->{"format"} or $args->{"format"} and $args->{"format"} =~ /h/
l!l&&r!l&&!r
000
$args->{"format"} and $args->{"format"} =~ /h/
!ll&&!rl&&r
000
MC/DC0%0/3
not $args->{"format"} or $args->{"format"} and $args->{"format"} =~ /h/
not $args->{"format"} $args->{"format"} $args->{"format"} =~ /h/
Truth table0%0/4
not(A) or B and C
A= not $args->{"format"}B= $args->{"format"}C= $args->{"format"} =~ /h/
ABCresult
1XX1
0111
00X0
0100
216 0 require Pod::Text;
217 0 require IO::String;
218 0 ▶ my $cols = $ENV{'COLUMNS'} || eval {
Condition0%0/5
$ENV{'COLUMNS'} || eval { do { require IO::Interactive; die unless IO::Interactive::is_interactive(*STDOUT); require Term::ReadKey; (Term::ReadKey::GetTerminalSize(\*STDOUT))[0] } } || 80
l!l
00
$ENV{"COLUMNS"} or eval { do { require IO::Interactive; die unless IO::Interactive::is_interactive(*STDOUT); require Term::ReadKey; (Term::ReadKey::GetTerminalSize(\*STDOUT))[0] } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'COLUMNS'} || eval { do { require IO::Interactive; die unless IO::Interactive::is_interactive(*STDOUT); require Term::ReadKey; (Term::ReadKey::GetTerminalSize(\*STDOUT))[0] } } || 80
$ENV{"COLUMNS"} eval { do { require IO::Interactive; die unless IO::Interactive::is_interactive(*STDOUT); require Term::ReadKey; (Term::ReadKey::GetTerminalSize(\*STDOUT))[0] } }
Truth table0%0/3
A or B
A= $ENV{"COLUMNS"}B= eval { do { require IO::Interactive; die unless IO::Interactive::is_interactive(*STDOUT); require Term::ReadKey; (Term::ReadKey::GetTerminalSize(\*STDOUT))[0] } }
ABresult
1X1
011
000
219 0 require IO::Interactive;
220 0 ▶ die if ! IO::Interactive::is_interactive(*STDOUT);
Branch: 1 branch
BranchTrueFalseTotal
unless IO::Interactive::is_interactive(*STDOUT) 0 0 0
221 0 require Term::ReadKey; (Term::ReadKey::GetTerminalSize(\*STDOUT))[0]
222 } || 80;
223 0 Pod::Text->new(width => $cols)->parse_from_file(IO::String->new($out), IO::String->new(my $txt));
224 0 return $txt;
225 }
226 0 return $out;
227 }
228  
229 1 1;
« Respite/Server.pm ↑ Summary Respite/Base.pm »