Footprintless/App/Command/config.pm

filter: Statementstmt 59.6% 34 / 57 Branchbran 28.5% 8 / 28 Conditioncond 35.7% 5 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 88.8% 8 / 9 Podpod 100% 4 / 4 totaltotal 49.5% 59 / 119 CC 22 SCAR 38.7
CC
22
Cov
47%
_entity_to_properties
110.0
execute
25.5
BEGIN
1.0
CRAP 48.0
« Footprintless/Tunnel.pm ↑ Summary Footprintless/CommandRunner/IPCRun.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::App::Command::config;
5 5 $Footprintless::App::Command::config::VERSION = '1.29';
6 # ABSTRACT: Prints the config at the coordinate.
7 # PODNAME: Footprintless::App::Command::config
8  
9 5 ▶use Footprintless::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 my $logger = Log::Any->get_logger();
13  
14 0 ▶sub _entity_to_properties {
Subroutine _entity_to_properties: not called CC=10 SCAR=47.0
15 0 my ( $entity, $properties, $prefix ) = @_;
16  
17 0 ▶ $properties = {} unless $properties;
Branch: 1 branch
BranchTrueFalseTotal
unless $properties 0 0 0
18  
19 0 my $ref = ref($entity);
20 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
21 0 ▶ if ( $ref eq 'SCALAR' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref eq 'SCALAR') { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
elsif ($ref =~ /^CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|Regexp$/) { } 0 0 0
22 0 $properties->{$prefix} = $$entity;
23 }
24 elsif ( $ref eq 'ARRAY' ) {
25 0 my $index = 0;
26 0 foreach my $array_entity ( @{$entity} ) {
27 0 ▶ _entity_to_properties( $array_entity, $properties,
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
28 ( $prefix ? "$prefix\[$index\]" : "[$index]" ) );
29 0 $index++;
30 }
31 }
32 elsif ( $ref =~ /^CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|Regexp$/ ) {
33 0 croak("unsupported ref type '$ref'");
34 }
35 else { # HASH or blessed ref
36 0 foreach my $key ( keys( %{$entity} ) ) {
37 0 ▶ _entity_to_properties( $entity->{$key}, $properties,
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
38 ( $prefix ? "$prefix.$key" : $key ) );
39 }
40 }
41 }
42 else {
43 0 $properties->{$prefix} = $entity;
44 }
45  
46 0 return $properties;
47 }
48  
49 3 ▶sub execute {
Subroutine execute: called CC=13 SCAR=32.4
Pod documented
50 3 my ( $self, $opts, $args ) = @_;
51  
52 3 ▶ my $config =
Branch: 1 branch
BranchTrueFalseTotal
@$args ? : 3 0 3
53 @$args
54 ? $self->app()->footprintless()->entities()->get_entity( $args->[0] )
55 : $self->app()->footprintless()->entities()->as_hashref();
56  
57 3 my $string;
58 3 ▶ my $format = $opts->{format} || 'dumper1';
Condition50%1/2
$opts->{'format'} || 'dumper1'
l!l
30
MC/DC0%0/1
$opts->{'format'} || 'dumper1'
$opts->{'format'}
Truth table50%1/2
A
A= $opts->{'format'}
Aresult
11
00
59 3 $logger->tracef( 'format=%s,config=%s', $format, $config );
60 3 ▶ if ( $format =~ /^dumper([0-3])?$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($format =~ /^dumper([0-3])?$/) { } 2 1 3
elsif ($format eq 'properties') { } 0 1 1
elsif ($format =~ /^json([0-3])?$/) { } 1 0 1
61 2 require Data::Dumper;
62 2 ▶ my $indent = defined($1) ? $1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 2 0 2
63 2 $string = Data::Dumper->new( [$config] )->Indent($indent)->Sortkeys(1)->Dump();
64 }
65 elsif ( $format eq 'properties' ) {
66 0 my $properties = _entity_to_properties($config);
67 0 $string = join( "\n", map {"$_=$properties->{$_}"} sort keys( %{$properties} ) );
68 }
69 elsif ( $format =~ /^json([0-3])?$/ ) {
70 1 require JSON;
71 1 my $json = JSON->new();
72 1 ▶ if ( !defined($1) || $1 == 1 || $1 == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $1 or $1 == 1 or $1 == 3) 0 1 1
Condition33%2/6
not defined $1 or $1 == 1 or $1 == 3
l!l&&r!l&&!r
001
not defined $1 or $1 == 1
l!l&&r!l&&!r
001
MC/DC0%0/3
not defined $1 or $1 == 1 or $1 == 3
not defined $1 $1 == 1 $1 == 3
Truth table25%1/4
not(A) or B or C
A= not defined $1B= $1 == 1C= $1 == 3
ABCresult
1XX1
01X1
0011
0000
73 0 $json->pretty();
74 }
75 1 ▶ if ( !defined($1) || $1 == 2 || $1 == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $1 or $1 == 2 or $1 == 3) 1 0 1
Condition33%2/6
not defined $1 or $1 == 2 or $1 == 3
l!l&&r!l&&!r
100
not defined $1 or $1 == 2
l!l&&r!l&&!r
010
MC/DC0%0/3
not defined $1 or $1 == 2 or $1 == 3
not defined $1 $1 == 2 $1 == 3
Truth table25%1/4
not(A) or B or C
A= not defined $1B= $1 == 2C= $1 == 3
ABCresult
1XX1
01X1
0011
0000
76 1 $json->canonical(1);
77 }
78 1 $string = $json->encode($config);
79 }
80 else {
81 0 $self->usage_error("unsupported format [$format]");
82 }
83  
84 3 print($string);
85 }
86  
87 3 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
88 3 return ( [ "format|f=s", "format to print", { default => 'dumper1' } ], );
89 }
90  
91 3 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
92 3 return "fpl config [COORDINATE] %o";
93 }
94  
95 3 ▶sub validate_args {
Subroutine validate_args: called CC=1 SCAR=0.0
Pod documented
96 3 my ( $self, $opt, $args ) = @_;
97 }
98  
99 5 1;
100  
101 __END__
« Footprintless/Tunnel.pm ↑ Summary Footprintless/CommandRunner/IPCRun.pm »