Dialog/Gauged.pm

filter: Statementstmt 47.5% 59 / 124 Branchbran 37.0% 20 / 54 Conditioncond 33.3% 13 / 39 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 27.2% 9 / 33 Podpod 24.0% 6 / 25 totaltotal 35.9% 107 / 298 CC 46 SCAR 51.7
CC
46
Cov
42%
new
356.2
_debug
7.5
_has_variant
5.7
CRAP 175.1
« Dialog/Backend/XOSD.pm ↑ Summary Dialog/Screen/Druid.pm »
1 package UI::Dialog::Gauged;
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  
24 BEGIN {
25 1 ▶ use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶ $VERSION = '1.20';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 }
28  
29 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
30 #: Constructor Method
31 #:
32  
33 sub new {
34 1 ▶ my $proto = shift();
Subroutine new: called CC=38 SCAR=58.8
Pod documented
35 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
36 1 ▶ my $cfg = {@_} || {};
Condition50%1/2
{@_} || {}
l!l
10
MC/DC0%0/1
{@_} || {}
{@_}
Truth table50%1/2
A
A= {@_}
Aresult
11
00
37 1 my $self = {};
38 1 bless($self, $class);
39  
40 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
41  
42 #: Dynamic path discovery...
43 1 my $CFG_PATH = $cfg->{'PATH'};
44 1 ▶ if ($CFG_PATH) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CFG_PATH) { } 0 1 1
elsif ($ENV{'PATH'}) { } 1 0 1
45 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
46 0 elsif ($CFG_PATH =~ m!:!) { $self->{'PATHS'} = [ split(/:/,$CFG_PATH) ]; }
47 0 elsif (-d $CFG_PATH) { $self->{'PATHS'} = [ $CFG_PATH ]; }
48 1 } elsif ($ENV{'PATH'}) { $self->{'PATHS'} = [ split(/:/,$ENV{'PATH'}) ]; }
49 0 else { $self->{'PATHS'} = ''; }
50  
51 1 ▶ if (not $cfg->{'order'} and ($ENV{'DISPLAY'} && length($ENV{'DISPLAY'}) > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $cfg->{"order"} and ($ENV{"DISPLAY"} and length $ENV{"DISPLAY"} > 0)) 0 1 1
Condition33%2/6
not $cfg->{"order"} and ($ENV{"DISPLAY"} and length $ENV{"DISPLAY"} > 0)
!ll&&!rl&&r
010
$ENV{"DISPLAY"} and length $ENV{"DISPLAY"} > 0
!ll&&!rl&&r
100
MC/DC0%0/3
not $cfg->{"order"} and ($ENV{"DISPLAY"} and length $ENV{"DISPLAY"} > 0)
not $cfg->{"order"} $ENV{"DISPLAY"} length $ENV{"DISPLAY"} > 0
Truth table0%0/4
not(A) and B and C
A= not $cfg->{"order"}B= $ENV{"DISPLAY"}C= length $ENV{"DISPLAY"} > 0
ABCresult
0XX0
10X0
1100
1111
52 #: Pick a GUI mode 'cause a DISPLAY was detected
53 0 ▶ if ($ENV{'TERM'} =~ /^dumb$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'TERM'} =~ /^dumb$/i) { } 0 0 0
54 # we're running free of a terminal
55 0 $cfg->{'order'} = [ 'zenity', 'xdialog' ];
56 } else {
57 # we're running in a terminal
58 0 $cfg->{'order'} = [ 'zenity', 'xdialog', 'cdialog', 'whiptail' ];
59 }
60 }
61 # verify and repair the order
62 $cfg->{'order'} = ((ref($cfg->{'order'}) eq "ARRAY") ? $cfg->{'order'} :
63 1 ▶ ($cfg->{'order'}) ? [ $cfg->{'order'} ] :
Branch: 2 branches
BranchTrueFalseTotal
ref $cfg->{'order'} eq 'ARRAY' ? : 0 1 1
$cfg->{'order'} ? : 0 1 1
64 [ 'cdialog', 'whiptail' ]);
65  
66 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
67 1 ▶ $cfg->{'order'} = [ split(/\:/,$ENV{'UI_DIALOGS'}) ] if $ENV{'UI_DIALOGS'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"UI_DIALOGS"} 0 1 1
68  
69 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
70 1 ▶ unshift(@{$cfg->{'order'}},$ENV{'UI_DIALOG'}) if $ENV{'UI_DIALOG'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"UI_DIALOG"} 0 1 1
71  
72 $cfg->{'trust-input'} =
73 ( exists $cfg->{'trust-input'}
74 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
75 ) ? 1 : 0;
76  
77 1 my @opts = ();
78 1 foreach my $opt (keys(%$cfg)) { push(@opts,$opt,$cfg->{$opt}); }
79  
80 1 $self->_debug("order: @{$cfg->{'order'}}",2);
81  
82 1 ▶ if (ref($cfg->{'order'}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cfg->{'order'} eq 'ARRAY') { } 1 0 1
83 1 foreach my $try (@{$cfg->{'order'}}) {
84 2 ▶ if ($try =~ /^zenity$/i) {
Branch: 4 branches
BranchTrueFalseTotal
if ($try =~ /^zenity$/i) { } 0 2 2
elsif ($try =~ /^(?:xdialog|X)$/i) { } 0 2 2
elsif ($try =~ /^(?:dialog|cdialog)$/i) { } 1 1 2
elsif ($try =~ /^whiptail$/i) { } 1 0 1
85 0 $self->_debug("trying zenity",2);
86 0 ▶ if (eval "require UI::Dialog::Backend::Zenity; 1" && $self->_has_variant('zenity')) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::Zenity; 1' and $self->_has_variant('zenity')) { } 0 0 0
Condition0%0/3
eval "require UI::Dialog::Backend::Zenity; 1" and $self->_has_variant("zenity")
!ll&&!rl&&r
000
MC/DC0%0/2
eval "require UI::Dialog::Backend::Zenity; 1" and $self->_has_variant("zenity")
eval "require UI::Dialog::Backend::Zenity; 1" $self->_has_variant("zenity")
Truth table0%0/3
A and B
A= eval "require UI::Dialog::Backend::Zenity; 1"B= $self->_has_variant("zenity")
ABresult
0X0
100
111
87 0 require UI::Dialog::Backend::Zenity;
88 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::Zenity (@opts);
89 0 $self->_debug("using zenity",2);
90 0 last;
91 0 } else { next; }
92 } elsif ($try =~ /^(?:xdialog|X)$/i) {
93 0 $self->_debug("trying xdialog",2);
94 0 ▶ if (eval "require UI::Dialog::Backend::XDialog; 1" && $self->_has_variant('Xdialog')) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::XDialog; 1' and $self->_has_variant('Xdialog')) { } 0 0 0
Condition0%0/3
eval "require UI::Dialog::Backend::XDialog; 1" and $self->_has_variant("Xdialog")
!ll&&!rl&&r
000
MC/DC0%0/2
eval "require UI::Dialog::Backend::XDialog; 1" and $self->_has_variant("Xdialog")
eval "require UI::Dialog::Backend::XDialog; 1" $self->_has_variant("Xdialog")
Truth table0%0/3
A and B
A= eval "require UI::Dialog::Backend::XDialog; 1"B= $self->_has_variant("Xdialog")
ABresult
0X0
100
111
95 0 require UI::Dialog::Backend::XDialog;
96 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::XDialog (@opts,'XDIALOG_HIGH_DIALOG_COMPAT',1);
97 0 $self->_debug("using xdialog",2);
98 0 last;
99 0 } else { next; }
100 } elsif ($try =~ /^(?:dialog|cdialog)$/i) {
101 1 $self->_debug("trying cdialog",2);
102 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
103 0 require UI::Dialog::Backend::CDialog;
104 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::CDialog (@opts);
105 0 $self->_debug("using cdialog",2);
106 0 last;
107 1 } else { next; }
108 } elsif ($try =~ /^whiptail$/i) {
109 1 $self->_debug("trying whiptail",2);
110 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
111 0 require UI::Dialog::Backend::Whiptail;
112 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::Whiptail (@opts);
113 0 $self->_debug("using whiptail",2);
114 0 last;
115 1 } else { next; }
116 } else {
117 # we don't know what they're asking for... try UI::Dialog...
118 0 ▶ if (eval "require UI::Dialog; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog; 1') { } 0 0 0
119 0 require UI::Dialog;
120 0 $self->{'_ui_dialog'} = new UI::Dialog (@opts);
121 0 $self->_debug(ref($self)." unknown backend: '".$try."', using UI::Dialog instead.",2);
122 0 last;
123 0 } else { next; }
124 }
125 }
126 } else {
127 0 carp("Failed to load any suitable dialog variant backend.");
128 }
129  
130 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.") 1 0 1
131 0 return($self);
132 }
133  
134 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
135 #: Private Methods
136 #:
137  
138 #: purely internal usage
139 sub _debug {
140 5 ▶ my $self = $_[0];
Subroutine _debug: called CC=5 SCAR=20.2
141 5 ▶ my $mesg = $_[1] || 'null error message given!';
Condition50%1/2
$_[1] || 'null error message given!'
l!l
50
MC/DC0%0/1
$_[1] || 'null error message given!'
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
142 5 ▶ my $rate = $_[2] || 1;
Condition50%1/2
$_[2] || 1
l!l
50
MC/DC0%0/1
$_[2] || 1
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
143 5 ▶ return() unless $self->{'debug'} and $self->{'debug'} >= $rate;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug"} and $self->{"debug"} >= $rate 5 0 5
Condition33%1/3
$self->{"debug"} and $self->{"debug"} >= $rate
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"debug"} and $self->{"debug"} >= $rate
$self->{"debug"} $self->{"debug"} >= $rate
Truth table33%1/3
A and B
A= $self->{"debug"}B= $self->{"debug"} >= $rate
ABresult
0X0
100
111
144 0 chomp($mesg);
145 0 print STDERR "Debug: ".$mesg."\n";
146 }
147  
148 sub _has_variant {
149 2 ▶ my $self = $_[0];
Subroutine _has_variant: called CC=5 SCAR=17.5
150 2 my $variant = $_[1];
151 $self->{'PATHS'} = ((ref($self->{'PATHS'}) eq "ARRAY") ? $self->{'PATHS'} :
152 2 ▶ ($self->{'PATHS'}) ? [ $self->{'PATHS'} ] :
Branch: 2 branches
BranchTrueFalseTotal
ref $self->{'PATHS'} eq 'ARRAY' ? : 2 0 2
$self->{'PATHS'} ? : 0 0 0
153 [ '/bin', '/usr/bin', '/usr/local/bin', '/opt/bin' ]);
154 2 foreach my $PATH (@{$self->{'PATHS'}}) {
155 18 ▶ return($PATH . '/' . $variant)
Branch: 1 branch
BranchTrueFalseTotal
if -x $PATH . '/' . $variant 0 18 18
156 unless not -x $PATH . '/' . $variant;
157 }
158 2 return(0);
159 }
160  
161 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
162 #: Public Methods
163 #:
164  
165 #: dialog variant state methods:
166 0 ▶sub state { return(shift()->{'_ui_dialog'}->state(@_)); }
Subroutine state: not called CC=1 SCAR=6.9
Pod undocumented
167 0 ▶sub ra { return(shift()->{'_ui_dialog'}->ra(@_)); }
Subroutine ra: not called CC=1 SCAR=6.9
Pod undocumented
168 0 ▶sub rs { return(shift()->{'_ui_dialog'}->rs(@_)); }
Subroutine rs: not called CC=1 SCAR=6.9
Pod undocumented
169 0 ▶sub rv { return(shift()->{'_ui_dialog'}->rv(@_)); }
Subroutine rv: not called CC=1 SCAR=6.9
Pod undocumented
170  
171 #: Frills
172 #: all backends support nautilus scripts.
173 0 ▶sub nautilus { return(shift()->{'_ui_dialog'}->nautilus(@_)); }
Subroutine nautilus: not called CC=1 SCAR=6.9
Pod undocumented
174 #: same with osd_cat (aka: xosd).
175 0 ▶sub xosd { return(shift()->{'_ui_dialog'}->xosd(@_)); }
Subroutine xosd: not called CC=1 SCAR=6.9
Pod undocumented
176 #: Beep & Clear may have no affect when using GUI backends
177 0 ▶sub beep { return(shift()->{'_ui_dialog'}->beep(@_)); }
Subroutine beep: not called CC=1 SCAR=6.9
Pod undocumented
178 0 ▶sub clear { return(shift()->{'_ui_dialog'}->clear(@_)); }
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
179  
180 #: widget methods:
181 0 ▶sub yesno { return(shift()->{'_ui_dialog'}->yesno(@_)); }
Subroutine yesno: not called CC=1 SCAR=6.9
Pod undocumented
182 0 ▶sub msgbox { return(shift()->{'_ui_dialog'}->msgbox(@_)); }
Subroutine msgbox: not called CC=1 SCAR=6.9
Pod undocumented
183 0 ▶sub inputbox { return(shift()->{'_ui_dialog'}->inputbox(@_)); }
Subroutine inputbox: not called CC=1 SCAR=6.9
Pod undocumented
184 0 ▶sub password { return(shift()->{'_ui_dialog'}->password(@_)); }
Subroutine password: not called CC=1 SCAR=6.9
Pod undocumented
185 0 ▶sub textbox { return(shift()->{'_ui_dialog'}->textbox(@_)); }
Subroutine textbox: not called CC=1 SCAR=6.9
Pod undocumented
186 0 ▶sub menu { return(shift()->{'_ui_dialog'}->menu(@_)); }
Subroutine menu: not called CC=1 SCAR=6.9
Pod undocumented
187 0 ▶sub checklist { return(shift()->{'_ui_dialog'}->checklist(@_)); }
Subroutine checklist: not called CC=1 SCAR=6.9
Pod undocumented
188 0 ▶sub radiolist { return(shift()->{'_ui_dialog'}->radiolist(@_)); }
Subroutine radiolist: not called CC=1 SCAR=6.9
Pod undocumented
189 0 ▶sub fselect { return(shift()->{'_ui_dialog'}->fselect(@_)); }
Subroutine fselect: not called CC=1 SCAR=6.9
Pod undocumented
190 0 ▶sub dselect { return(shift()->{'_ui_dialog'}->dselect(@_)); }
Subroutine dselect: not called CC=1 SCAR=6.9
Pod undocumented
191  
192 # gauge methods
193 0 ▶sub gauge_start { return(shift()->{'_ui_dialog'}->gauge_start(@_)); }
Subroutine gauge_start: not called CC=1 SCAR=6.9
Pod documented
194 0 ▶sub gauge_stop { return(shift()->{'_ui_dialog'}->gauge_stop(@_)); }
Subroutine gauge_stop: not called CC=1 SCAR=6.9
Pod documented
195 0 ▶sub gauge_inc { return(shift()->{'_ui_dialog'}->gauge_inc(@_)); }
Subroutine gauge_inc: not called CC=1 SCAR=6.9
Pod documented
196 0 ▶sub gauge_dec { return(shift()->{'_ui_dialog'}->gauge_dec(@_)); }
Subroutine gauge_dec: not called CC=1 SCAR=6.9
Pod undocumented
197 0 ▶sub gauge_set { return(shift()->{'_ui_dialog'}->gauge_set(@_)); }
Subroutine gauge_set: not called CC=1 SCAR=6.9
Pod documented
198 0 ▶sub gauge_text { return(shift()->{'_ui_dialog'}->gauge_text(@_)); }
Subroutine gauge_text: not called CC=1 SCAR=6.9
Pod documented
199  
200  
201 1 1;
« Dialog/Backend/XOSD.pm ↑ Summary Dialog/Screen/Druid.pm »