| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $ref = ref($entity); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if ($ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if ( $ref eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$opts->{'format'} || 'dumper1'
$opts->{'format'}
Truth table50%1/2
A
A= $opts->{'format'}
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | $logger->tracef( 'format=%s,config=%s', $format, $config ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | if ( $format =~ /^dumper([0-3])?$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | my $indent = defined($1) ? $1 : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not defined $1 or $1 == 1 or $1 == 3
not defined $1 or $1 == 1
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
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $json->pretty(); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | if ( !defined($1) || $1 == 2 || $1 == 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $1 or $1 == 2 or $1 == 3
not defined $1 or $1 == 2
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||