| 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
Condition66%2/3
@$args or $opt->{"save"}
MC/DC0%0/2
@$args or $opt->{"save"}
@$args
$opt->{"save"}
Truth table66%2/3
A or B
A= @$argsB= $opt->{"save"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 6 | my $stashed; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | # stash pending work | ||||||||||||||||||||||||||||||||
| 70 | 6 | ▶ | if ($opt->{commit}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$opt->{"save"} and not @$args
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
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$inst->needs_save or $opt->{"save"}
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"}
| |||||||||||||||||||||||||||||||||
| 86 | 3 | $self->save($inst,$opt) ; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | if ($opt->{commit}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 97 | 0 | $self->pop_stash; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 4 | return; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 1 | 1; | |||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||||||||||||||