Cme/Command/edit.pm

filter: Statementstmt 30.6% 19 / 62 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 100% 5 / 5 totaltotal 30.6% 30 / 98 CC 11 SCAR 42.5
CC
11
Cov
23%
execute
132.0
validate_args
2.0
opt_spec
2.0
CRAP 69.8
↑ Summary Cme/Common.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: Edit the configuration of an application
11  
12 package App::Cme::Command::edit ;
13 1 $App::Cme::Command::edit::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  
24 0 ▶sub validate_args {
Subroutine validate_args: not called CC=1 SCAR=6.9
Pod documented
25 0 my ($self, $opt, $args) = @_;
26 0 $self->check_unknown_args($args);
27 0 $self->process_args($opt,$args);
28 0 return;
29 }
30  
31 0 ▶sub opt_spec {
Subroutine opt_spec: not called CC=1 SCAR=6.9
Pod documented
32 0 my ( $class, $app ) = @_;
33 return (
34 0 [ "ui|if=s" => "user interface type. Either tk, curses, shell" ],
35 [ "backup:s" => "Create a backup of configuration files before saving." ],
36 [ "open-item=s" => "open a specific item of the configuration" ],
37 $class->cme_global_options,
38 );
39 }
40  
41 0 ▶sub usage_desc {
Subroutine usage_desc: not called CC=1 SCAR=6.9
Pod documented
42 0 my ($self) = @_;
43 0 my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
44 0 return "$desc [application] [ file ] [ -ui tk|curses|shell ] [ -open-item xxx ] ";
45 }
46  
47 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
48 0 my ($self) = @_;
49 0 return $self->get_documentation;
50 }
51 0 ▶sub execute {
Subroutine execute: not called CC=11 SCAR=48.8
Pod documented
52 0 my ($self, $opt, $args) = @_;
53  
54 0 my ($model, $inst, $root) = $self->init_cme($opt,$args);
55  
56 0 my $has_tk = eval { require Config::Model::TkUI; 1; };
57  
58 0 my $has_curses = eval { require Config::Model::CursesUI; 1; };
59  
60 0 my $ui_type = $opt->{ui};
61  
62 0 ▶ if ( not defined $ui_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ui_type) 0 0 0
63 0 ▶ if ($has_tk) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_tk) { } 0 0 0
elsif ($has_curses) { } 0 0 0
64 0 $ui_type = 'tk';
65 }
66 elsif ($has_curses) {
67 0 warn "You should install Config::Model::TkUI for a ", "more friendly user interface\n";
68 0 $ui_type = 'curses';
69 }
70 else {
71 0 warn "You should install Config::Model::TkUI or ",
72 "Config::Model::CursesUI ",
73 "for a more friendly user interface\n";
74 0 $ui_type = 'shell';
75 }
76 }
77  
78 0 $root->deep_check;
79  
80 0 ▶ if ( $ui_type eq 'shell' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ui_type eq 'shell') { } 0 0 0
elsif ($ui_type eq 'curses') { } 0 0 0
elsif ($ui_type eq 'tk') { } 0 0 0
81 0 require Config::Model::TermUI;
82 0 $self->run_shell_ui('Config::Model::TermUI', $inst) ;
83 }
84 elsif ( $ui_type eq 'curses' ) {
85 0 ▶ die "cannot run curses interface: ",
Branch: 1 branch
BranchTrueFalseTotal
unless $has_curses 0 0 0
86 "Config::Model::CursesUI is not installed, please use shell or simple UI\n"
87 unless $has_curses;
88 0 my $err_file = '/tmp/cme-error.log';
89  
90 0 print "In case of error, check $err_file\n";
91  
92 0 ▶ open( my $fh, ">", $err_file ) || die "Can't open $err_file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $err_file or die "Can't open ${err_file}: $!\n" 0 0 0
93 0 ▶ open(STDERR, ">&", $fh)|| die "Can't open STDERR:$!\n";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $fh or die "Can't open STDERR:$!\n" 0 0 0
94  
95 0 my $dialog = Config::Model::CursesUI->new();
96  
97 # engage in user interaction
98 0 $dialog->start($model);
99  
100 0 close($fh);
101 }
102 elsif ( $ui_type eq 'tk' ) {
103 0 ▶ die "cannot run Tk interface: Config::Model::TkUI is not installed, please use curses or shell or simple ui\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $has_tk 0 0 0
104 unless $has_tk;
105 0 $self ->run_tk_ui ( $inst, $opt);
106 }
107 else {
108 0 die "Unsupported user interface: $ui_type\n";
109 }
110 0 return;
111 }
112  
113 1 1;
114  
115 __END__
↑ Summary Cme/Common.pm »