Cme/Command/modify.pm

filter: Statementstmt 88.3% 53 / 60 Branchbran 61.1% 11 / 18 Conditioncond 88.8% 8 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 86.6% 13 / 15 Podpod 83.3% 5 / 6 totaltotal 82.4% 94 / 114 CC 13 SCAR 16.5
CC
13
Cov
83%
execute
10.6
commit
6.0
validate_args
3.1
CRAP 5.2
« Cme/Command/fusefs.pm ↑ Summary Cme/Command/check.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: Modify the configuration of an application
11  
12 package App::Cme::Command::modify ;
13 1 $App::Cme::Command::modify::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 v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use feature qw/postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶no warnings qw/experimental::postderef experimental::signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use App::Cme -command ;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use base qw/App::Cme::Common/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use Config::Model::ObjTreeScanner;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Config::Model qw/initialize_log4perl/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 6 ▶sub validate_args {
Subroutine validate_args: called CC=3 SCAR=11.2
Pod documented
28 6 my ($self, $opt, $args) = @_;
29 6 $self->check_unknown_args($args);
30 6 $self->process_args($opt,$args);
31 $self->usage_error("No modification instructions given on command line")
32 6 ▶ unless @$args or $opt->{save};
Branch: 1 branch
BranchTrueFalseTotal
unless @$args or $opt->{"save"} 0 6 6
Condition66%2/3
@$args or $opt->{"save"}
l!l&&r!l&&!r
510
MC/DC0%0/2
@$args or $opt->{"save"}
@$args $opt->{"save"}
Truth table66%2/3
A or B
A= @$argsB= $opt->{"save"}
ABresult
1X1
011
000
33 6 return;
34 }
35  
36 6 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
37 6 my ( $class, $app ) = @_;
38 return (
39 6 [ "backup:s" => "Create a backup of configuration files before saving." ],
40 [ "commit|c:s" => "commit change with message passed as argument" ],
41 $class->cme_global_options,
42 );
43 }
44  
45 6 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
46 6 my ($self) = @_;
47 6 my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
48 6 return "$desc [application] [file ] instructions";
49 }
50  
51 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
52 0 my ($self) = @_;
53 0 return $self->get_documentation;
54 }
55  
56 0 ▶sub commit ($self, $msg) {
Subroutine commit: not called CC=2 SCAR=17.9
Pod undocumented
57 0 ▶ system(qw/git commit -a -m/, $msg) == 0
Branch: 1 branch
BranchTrueFalseTotal
system(("git", "commit", "-a", "-m"), $msg) == 0 or die "git commit failed: $?\n" 0 0 0
58 or die "git commit failed: $?\n";
59 0 return;
60 }
61  
62 6 ▶sub execute {
Subroutine execute: called CC=10 SCAR=23.6
Pod documented
63 6 my ($self, $opt, $args) = @_;
64  
65 6 ▶ $opt->{_verbose} = 'Loader' if $opt->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"verbose"} 1 5 6
66  
67 6 my $stashed;
68  
69 # stash pending work
70 6 ▶ if ($opt->{commit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"commit"}) 0 6 6
71 0 $stashed = $self->autostash;
72 }
73  
74 6 my ($model, $inst, $root) = $self->init_cme($opt,$args);
75  
76 # needed to create write_back subs
77 6 ▶ if ($opt->{save} and not @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"save"} and not @$args) 1 5 6
Condition100%3/3
$opt->{"save"} and not @$args
!ll&&!rl&&r
411
MC/DC100%2/2
$opt->{"save"} and not @$args
$opt->{"save"} not @$args
Truth table100%3/3
A and not(B)
A= $opt->{"save"}B= not @$args
ABresult
0X0
100
111
78 1 $root->dump_tree();
79 }
80  
81 6 $root->load("@$args");
82  
83 4 $root->deep_check; # consistency check
84  
85 4 ▶ if ($inst->needs_save or $opt->{save}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inst->needs_save or $opt->{'save'}) { } 3 1 4
elsif (not $opt->{'quiet'}) { } 1 0 1
Condition100%3/3
$inst->needs_save or $opt->{"save"}
l!l&&r!l&&!r
121
MC/DC100%2/2
$inst->needs_save or $opt->{"save"}
$inst->needs_save $opt->{"save"}
Truth table100%3/3
A or B
A= $inst->needs_saveB= $opt->{"save"}
ABresult
1X1
011
000
86 3 $self->save($inst,$opt) ;
87  
88 3 ▶ if ($opt->{commit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"commit"}) 0 3 3
89 0 $self->commit($opt->{commit});
90 }
91 }
92 elsif (not $opt->{quiet}) {
93 1 say "No change were applied";
94 }
95  
96 4 ▶ if ($stashed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stashed) 0 4 4
97 0 $self->pop_stash;
98 }
99  
100 4 return;
101 }
102  
103 1 1;
104  
105 __END__
« Cme/Command/fusefs.pm ↑ Summary Cme/Command/check.pm »