lib/Kubernetes/REST/CLI.pm

filter: Statementstmt 52.9% 27 / 51 Branchbran 15.0% 3 / 20 Conditioncond 7.1% 1 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 88.8% 8 / 9 Podpod 100% 2 / 2 totaltotal 39.0% 41 / 105 CC 17 SCAR 47.7
CC
17
Cov
36%
format_output
173.3
execute
2.0
BEGIN
1.0
CRAP 118.2
↑ Summary lib/Kubernetes/REST/LWPIO.pm »
1 package Kubernetes::REST::CLI;
2 # ABSTRACT: CLI base class for Kubernetes::REST command-line tools
3 2 our $VERSION = '1.110';
4 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use MooX::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 with 'Kubernetes::REST::CLI::Role::Connection';
10  
11  
12 option namespace => (
13 is => 'ro',
14 format => 's',
15 short => 'n',
16 9 ▶ default => sub { 'default' },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 2 doc => 'Namespace for namespaced resources',
18 );
19  
20  
21 option output => (
22 is => 'ro',
23 format => 's',
24 short => 'o',
25 9 ▶ default => sub { 'json' },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 2 doc => 'Output format: json, yaml, name',
27 );
28  
29  
30 has json => (
31 is => 'ro',
32 9 ▶ default => sub { JSON::MaybeXS->new->pretty->canonical->utf8 },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 2 );
34  
35  
36 6 ▶sub format_output {
Subroutine format_output: called CC=17 SCAR=51.6
Pod documented
37 6 my ($self, $result) = @_;
38 6 ▶ return unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 6 6
39  
40 6 my $format = $self->output;
41  
42 6 ▶ if ($format eq 'json') {
Branch: 3 branches
BranchTrueFalseTotal
if ($format eq 'json') { } 6 0 6
elsif ($format eq 'yaml') { } 0 0 0
elsif ($format eq 'name') { } 0 0 0
43 6 ▶ my $data = ref($result) && $result->can('TO_JSON') ? $result->TO_JSON : $result;
Branch: 1 branch
BranchTrueFalseTotal
ref $result && $result->can('TO_JSON') ? : 6 0 6
Condition33%1/3
ref $result and $result->can("TO_JSON")
!ll&&!rl&&r
006
MC/DC0%0/2
ref $result and $result->can("TO_JSON")
ref $result $result->can("TO_JSON")
Truth table33%1/3
A and B
A= ref $resultB= $result->can("TO_JSON")
ABresult
0X0
100
111
44 6 print $self->json->encode($data);
45 } elsif ($format eq 'yaml') {
46 0 require YAML::XS;
47 0 ▶ my $data = ref($result) && $result->can('TO_JSON') ? $result->TO_JSON : $result;
Branch: 1 branch
BranchTrueFalseTotal
ref $result && $result->can('TO_JSON') ? : 0 0 0
Condition0%0/3
ref $result and $result->can("TO_JSON")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $result and $result->can("TO_JSON")
ref $result $result->can("TO_JSON")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("TO_JSON")
ABresult
0X0
100
111
48 0 print YAML::XS::Dump($data);
49 } elsif ($format eq 'name') {
50 0 ▶ if (ref($result) && $result->can('items')) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $result and $result->can('items')) { } 0 0 0
elsif (ref $result and $result->can('metadata')) { } 0 0 0
Condition0%0/3
ref $result and $result->can("items")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $result and $result->can("items")
ref $result $result->can("items")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("items")
ABresult
0X0
100
111
51 0 ▶ for my $item (@{$result->items // []}) {
Condition0%0/2
$result->items // []
l!l
00
MC/DC0%0/1
$result->items // []
$result->items
Truth table0%0/2
A
A= $result->items
Aresult
11
00
52 0 my $meta = $item->metadata;
53 0 ▶ my $ns = $meta->namespace ? $meta->namespace . '/' : '';
Branch: 1 branch
BranchTrueFalseTotal
$meta->namespace ? : 0 0 0
54 0 print $ns, $meta->name, "\n";
55 }
56 ▶ } elsif (ref($result) && $result->can('metadata')) {
Condition0%0/3
ref $result and $result->can("metadata")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $result and $result->can("metadata")
ref $result $result->can("metadata")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("metadata")
ABresult
0X0
100
111
57 0 my $meta = $result->metadata;
58 0 ▶ my $ns = $meta->namespace ? $meta->namespace . '/' : '';
Branch: 1 branch
BranchTrueFalseTotal
$meta->namespace ? : 0 0 0
59 0 print $ns, $meta->name, "\n";
60 }
61 } else {
62 0 require Data::Dumper;
63 0 print Data::Dumper::Dumper($result);
64 }
65 }
66  
67  
68 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
Pod documented
69 0 my ($self, $args, $chain) = @_;
70 0 print "Usage: kube_client <command> [options]\n\n";
71 0 print "Commands:\n";
72 0 print " get <Kind> [name] Get resource(s)\n";
73 0 print " create -f <file> Create resource from file\n";
74 0 print " delete <Kind> <name> Delete resource\n";
75 0 print " raw <Group> <Method> Raw API call\n";
76 0 print "\nRun 'kube_client --help' for options.\n";
77 0 print "See also: kube_watch <Kind> for live event streaming.\n";
78 0 return 0;
79 }
80  
81  
82  
83 2 1;
84  
85 __END__
↑ Summary lib/Kubernetes/REST/LWPIO.pm »