Dialog/Console.pm

filter: Statementstmt 66.2% 55 / 83 Branchbran 41.6% 15 / 36 Conditioncond 32.1% 9 / 28 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 51.1% 88 / 172 CC 32 SCAR 50.5
CC
32
Cov
54%
new
189.2
BEGIN
1.0
BEGIN
1.0
CRAP 155.4
« Dialog/Screen/Druid.pm ↑ Summary Dialog/Backend/Whiptail.pm »
1 package UI::Dialog::Console;
2 ###############################################################################
3 # Copyright (C) 2004-2016 Kevin C. Krinke <kevin@krinke.ca>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ###############################################################################
19 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use UI::Dialog;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 BEGIN {
26 1 ▶ use vars qw( $VERSION @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶ @ISA = qw( UI::Dialog );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 $VERSION = '1.20';
29 }
30  
31 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
32 #: Constructor Method
33 #:
34  
35 sub new {
36 1 ▶ my $proto = shift();
Subroutine new: called CC=32 SCAR=52.4
Pod documented
37 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
38 1 ▶ my $cfg = {@_} || {};
Condition50%1/2
{@_} || {}
l!l
10
MC/DC0%0/1
{@_} || {}
{@_}
Truth table50%1/2
A
A= {@_}
Aresult
11
00
39 1 my $self = {};
40 1 bless($self, $class);
41  
42 1 ▶ $self->{'debug'} = $cfg->{'debug'} || 0;
Condition50%1/2
$cfg->{'debug'} || 0
l!l
01
MC/DC0%0/1
$cfg->{'debug'} || 0
$cfg->{'debug'}
Truth table50%1/2
A
A= $cfg->{'debug'}
Aresult
11
00
43  
44 #: Dynamic path discovery...
45 1 my $CFG_PATH = $cfg->{'PATH'};
46 1 ▶ if ($CFG_PATH) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CFG_PATH) { } 0 1 1
elsif ($ENV{'PATH'}) { } 1 0 1
47 0 ▶ if (ref($CFG_PATH) eq "ARRAY") { $self->{'PATHS'} = $CFG_PATH; }
Branch: 3 branches
BranchTrueFalseTotal
if (ref $CFG_PATH eq 'ARRAY') { } 0 0 0
elsif ($CFG_PATH =~ /:/) { } 0 0 0
elsif (-d $CFG_PATH) { } 0 0 0
48 0 elsif ($CFG_PATH =~ m!:!) { $self->{'PATHS'} = [ split(/:/,$CFG_PATH) ]; }
49 0 elsif (-d $CFG_PATH) { $self->{'PATHS'} = [ $CFG_PATH ]; }
50 1 } elsif ($ENV{'PATH'}) { $self->{'PATHS'} = [ split(/:/,$ENV{'PATH'}) ]; }
51 0 else { $self->{'PATHS'} = ''; }
52  
53 1 ▶ $cfg->{'order'} ||= [ 'dialog', 'whiptail', 'ascii' ];
Condition50%1/2
$cfg->{"order"} ||= ["dialog", "whiptail", "ascii"]
l!l
01
MC/DC0%0/1
$cfg->{"order"} ||= ["dialog", "whiptail", "ascii"]
$cfg->{"order"}
Truth table50%1/2
A
A= $cfg->{"order"}
Aresult
11
00
54  
55 1 ▶ $self->_debug("ENV->UI_DIALOGS: ".($ENV{'UI_DIALOGS'}||'NULL'),2);
Condition50%1/2
$ENV{'UI_DIALOGS'} || 'NULL'
l!l
01
MC/DC0%0/1
$ENV{'UI_DIALOGS'} || 'NULL'
$ENV{'UI_DIALOGS'}
Truth table50%1/2
A
A= $ENV{'UI_DIALOGS'}
Aresult
11
00
56 1 ▶ $cfg->{'order'} = [ split(/\:/,$ENV{'UI_DIALOGS'}) ] if $ENV{'UI_DIALOGS'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"UI_DIALOGS"} 0 1 1
57  
58 1 ▶ $self->_debug("ENV->UI_DIALOG: ".($ENV{'UI_DIALOG'}||'NULL'),2);
Condition50%1/2
$ENV{'UI_DIALOG'} || 'NULL'
l!l
01
MC/DC0%0/1
$ENV{'UI_DIALOG'} || 'NULL'
$ENV{'UI_DIALOG'}
Truth table50%1/2
A
A= $ENV{'UI_DIALOG'}
Aresult
11
00
59 1 ▶ unshift(@{$cfg->{'order'}},$ENV{'UI_DIALOG'}) if $ENV{'UI_DIALOG'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"UI_DIALOG"} 0 1 1
60  
61 $cfg->{'trust-input'} =
62 ( exists $cfg->{'trust-input'}
63 1 ▶ && $cfg->{'trust-input'}==1
Branch: 1 branch
BranchTrueFalseTotal
exists $cfg->{'trust-input'} && $cfg->{'trust-input'} == 1 ? : 0 1 1
Condition33%1/3
exists $cfg->{"trust-input"} and $cfg->{"trust-input"} == 1
!ll&&!rl&&r
100
MC/DC0%0/2
exists $cfg->{"trust-input"} and $cfg->{"trust-input"} == 1
exists $cfg->{"trust-input"} $cfg->{"trust-input"} == 1
Truth table33%1/3
A and B
A= exists $cfg->{"trust-input"}B= $cfg->{"trust-input"} == 1
ABresult
0X0
100
111
64 ) ? 1 : 0;
65  
66 1 my @opts = ();
67 1 foreach my $opt (keys(%$cfg)) { push(@opts,$opt,$cfg->{$opt}); }
68  
69 1 foreach my $try (@{$cfg->{'order'}}) {
70 3 ▶ if ($try =~ /^(?:cdialog||dialog)$/i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($try =~ /^(?:cdialog||dialog)$/i) { } 1 2 3
elsif ($try =~ /^(?:gdialog||gdialog\.real)$/i) { } 0 2 2
elsif ($try =~ /^whiptail$/i) { } 1 1 2
elsif ($try =~ /^(?:ascii||native)$/i) { } 1 0 1
71 1 $self->_debug("trying cdialog",2);
72 1 ▶ if (eval "require UI::Dialog::Backend::CDialog; 1" && $self->_has_variant('dialog')) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::CDialog; 1' and $self->_has_variant('dialog')) { } 0 1 1
Condition33%1/3
eval "require UI::Dialog::Backend::CDialog; 1" and $self->_has_variant("dialog")
!ll&&!rl&&r
010
MC/DC0%0/2
eval "require UI::Dialog::Backend::CDialog; 1" and $self->_has_variant("dialog")
eval "require UI::Dialog::Backend::CDialog; 1" $self->_has_variant("dialog")
Truth table33%1/3
A and B
A= eval "require UI::Dialog::Backend::CDialog; 1"B= $self->_has_variant("dialog")
ABresult
0X0
100
111
73 0 require UI::Dialog::Backend::CDialog;
74 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::CDialog (@opts);
75 0 $self->_debug("using cdialog",2);
76 0 last;
77 1 } else { next; }
78 } elsif ($try =~ /^(?:gdialog||gdialog\.real)$/i) {
79 0 $self->_debug("trying gdialog",2);
80 0 ▶ if (eval "require UI::Dialog::Backend::GDialog; 1" && ($self->_has_variant('gdialog.real') ||
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::GDialog; 1' and $self->_has_variant('gdialog.real') || $self->_has_variant('gdialog')) { } 0 0 0
Condition0%0/6
eval "require UI::Dialog::Backend::GDialog; 1" and $self->_has_variant("gdialog.real") || $self->_has_variant("gdialog")
!ll&&!rl&&r
000
$self->_has_variant("gdialog.real") or $self->_has_variant("gdialog")
l!l&&r!l&&!r
000
MC/DC0%0/3
eval "require UI::Dialog::Backend::GDialog; 1" and $self->_has_variant("gdialog.real") || $self->_has_variant("gdialog")
eval "require UI::Dialog::Backend::GDialog; 1" $self->_has_variant("gdialog.real") $self->_has_variant("gdialog")
Truth table0%0/4
A and B or C
A= eval "require UI::Dialog::Backend::GDialog; 1"B= $self->_has_variant("gdialog.real")C= $self->_has_variant("gdialog")
ABCresult
0XX0
1000
11X1
1011
81 $self->_has_variant('gdialog'))) {
82 0 require UI::Dialog::Backend::GDialog;
83 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::GDialog (@opts);
84 0 $self->_debug("using gdialog",2);
85 0 last;
86 0 } else { next; }
87 } elsif ($try =~ /^whiptail$/i) {
88 1 $self->_debug("trying whiptail",2);
89 1 ▶ if (eval "require UI::Dialog::Backend::Whiptail; 1" && $self->_has_variant('Whiptail')) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::Whiptail; 1' and $self->_has_variant('Whiptail')) { } 0 1 1
Condition33%1/3
eval "require UI::Dialog::Backend::Whiptail; 1" and $self->_has_variant("Whiptail")
!ll&&!rl&&r
010
MC/DC0%0/2
eval "require UI::Dialog::Backend::Whiptail; 1" and $self->_has_variant("Whiptail")
eval "require UI::Dialog::Backend::Whiptail; 1" $self->_has_variant("Whiptail")
Truth table33%1/3
A and B
A= eval "require UI::Dialog::Backend::Whiptail; 1"B= $self->_has_variant("Whiptail")
ABresult
0X0
100
111
90 0 require UI::Dialog::Backend::Whiptail;
91 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::Whiptail (@opts);
92 0 $self->_debug("using whiptail",2);
93 0 last;
94 1 } else { next; }
95 } elsif ($try =~ /^(?:ascii||native)$/i) {
96 1 $self->_debug("trying ascii",2);
97 1 ▶ if (eval "require UI::Dialog::Backend::ASCII; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::ASCII; 1') { } 1 0 1
98 1 require UI::Dialog::Backend::ASCII;
99 1 $self->{'_ui_dialog'} = new UI::Dialog::Backend::ASCII (@opts);
100 1 $self->_debug("using ascii",2);
101 1 last;
102 0 } else { next; }
103 } else {
104 # we don't know what they're asking for... try UI::Dialog...
105 0 ▶ if (eval "require UI::Dialog; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog; 1') { } 0 0 0
106 0 require UI::Dialog;
107 0 $self->{'_ui_dialog'} = new UI::Dialog (@opts);
108 0 $self->_debug(ref($self)." unknown backend: '".$try."', using UI::Dialog instead.",2);
109 0 last;
110 0 } else { next; }
111 }
112 }
113  
114 1 ▶ ref($self->{'_ui_dialog'}) or croak("unable to load suitable backend.");
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"_ui_dialog"} or croak("unable to load suitable backend.") 0 1 1
115  
116 1 return($self);
117 }
118  
119 1 1;
« Dialog/Screen/Druid.pm ↑ Summary Dialog/Backend/Whiptail.pm »