Cme/Command/dump.pm

filter: Statementstmt 53.8% 28 / 52 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 64.2% 9 / 14 Podpod 100% 5 / 5 totaltotal 52.5% 42 / 80 CC 5 SCAR 22.3
CC
5
Cov
47%
execute
30.0
validate_args
2.0
opt_spec
2.0
CRAP 9.3
« Cme/Command/run.pm ↑ Summary Cme/Command/fusefs.pm »
1 #
2 # This file is part of App-Cme
3 #
4 # This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 # ABSTRACT: Dump the configuration of an application
11  
12 package App::Cme::Command::dump ;
13 1 $App::Cme::Command::dump::VERSION = '1.049';
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use App::Cme -command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use base qw/App::Cme::Common/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Config::Model::ObjTreeScanner;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use YAML::PP qw/Dump/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 0 ▶sub validate_args {
Subroutine validate_args: not called CC=1 SCAR=6.9
Pod documented
28 0 my ($self, $opt, $args) = @_;
29 0 $self->check_unknown_args($args);
30 0 $opt->{quiet} = 1; # don't want to mess up yaml output
31 0 $self->process_args($opt,$args);
32 0 return;
33 }
34  
35 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
36 0 my ( $class, $app ) = @_;
37 return (
38 [
39 0 "dumptype=s" => "Dump all values (full) or only customized values",
40 {
41 regex => qr/^(?:full|custom|non_upstream_default)$/,
42 default => 'custom'
43 }
44 ],
45 [
46 "format=s" => "dump using specified format (yaml json perl cml)",
47 {
48 regex => qr/^(?:json|ya?ml|perl|cml|cds)$/i,
49 default => 'yaml'
50 },
51 ],
52 $class->cme_global_options,
53 );
54 }
55  
56 0 ▶sub usage_desc {
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
57 0 my ($self) = @_;
58 0 my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
59 0 return "$desc [application] [ config_file ] [ -dumptype full|custom ] [ path ]";
60 }
61  
62 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
63 0 my ($self) = @_;
64 0 return $self->get_documentation;
65 }
66  
67 0 ▶sub execute {
Subroutine execute: not called CC=5 SCAR=34.0
Pod documented
68 0 my ($self, $opt, $args) = @_;
69  
70 0 my ($model, $inst, $root) = $self->init_cme($opt,$args);
71  
72 0 my $target_node = $root->grab(step => "@$args", type => 'node');
73  
74 0 my $dump_string;
75 0 my $format = $opt->{format};
76 0 ▶ my $mode = $opt->{dumptype} || 'custom';
Condition0%0/2
$opt->{'dumptype'} || 'custom'
l!l
00
MC/DC0%0/1
$opt->{'dumptype'} || 'custom'
$opt->{'dumptype'}
Truth table0%0/2
A
A= $opt->{'dumptype'}
Aresult
11
00
77  
78 0 ▶ if ($format =~ /cml|cds/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /cml|cds/i) { } 0 0 0
79 0 $dump_string = $target_node->dump_tree( mode => $mode );
80 }
81 else {
82 0 my $perl_data = $target_node->dump_as_data(
83 ordered_hash_as_list => 0,
84 mode => $mode
85 );
86 0 ▶ $dump_string
Branch: 2 branches
BranchTrueFalseTotal
$format =~ /ya?ml/i ? : 0 0 0
$format =~ /json/i ? : 0 0 0
87 = $format =~ /ya?ml/i ? Dump($perl_data)
88 : $format =~ /json/i ? encode_json($perl_data)
89 : Dumper($perl_data) ; # Perl data structure
90 }
91 0 print $dump_string ;
92 0 return;
93 }
94  
95 1 1;
96  
97 __END__
« Cme/Command/run.pm ↑ Summary Cme/Command/fusefs.pm »