Dialog.pm

filter: Statementstmt 36.1% 55 / 152 Branchbran 33.3% 26 / 78 Conditioncond 27.0% 13 / 48 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 29.6% 8 / 27 Podpod 78.9% 15 / 19 totaltotal 33.2% 117 / 352 CC 61 SCAR 63.3
CC
61
Cov
34%
new
920.5
_has_variant
30.0
_debug
7.5
CRAP 563.4
↑ Summary Dialog/Console.pm »
1 package UI::Dialog;
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.14';
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=53 SCAR=68.2
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', 'gdialog', 'kdialog' ];
56 } else {
57 # we're running in a terminal
58 0 $cfg->{'order'} = [ 'zenity', 'xdialog', 'gdialog', 'kdialog', 'whiptail', 'cdialog', 'ascii' ];
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', 'ascii' ]);
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 3 ▶ if ($try =~ /^zenity$/i) {
Branch: 10 branches
BranchTrueFalseTotal
if ($try =~ /^zenity$/i) { } 0 3 3
elsif ($try =~ /^(?:gdialog|gdialog\.real)$/i) { } 0 3 3
elsif ($try =~ /^(?:xdialog|X)$/i) { } 0 3 3
elsif ($try =~ /^kdialog$/i) { } 0 3 3
elsif ($try =~ /^GNOME$/i) { } 0 3 3
elsif ($try =~ /^KDE$/i) { } 0 3 3
elsif ($try =~ /^CONSOLE$/i) { } 0 3 3
elsif ($try =~ /^(?:dialog|cdialog)$/i) { } 1 2 3
elsif ($try =~ /^whiptail$/i) { } 1 1 2
elsif ($try =~ /^(?:ascii|native)$/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 =~ /^(?:gdialog|gdialog\.real)$/i) {
93 0 $self->_debug("trying gdialog",2);
94 #: In Debian, gdialog is now being diverted to gdialog.real as zenity is the gnome2 replacement
95 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
96 $self->_has_variant('gdialog'))) {
97 0 require UI::Dialog::Backend::GDialog;
98 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::GDialog (@opts);
99 0 $self->_debug("using gdialog ",2);
100 0 last;
101 0 } else { next; }
102 } elsif ($try =~ /^(?:xdialog|X)$/i) {
103 0 $self->_debug("trying xdialog",2);
104 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
105 0 require UI::Dialog::Backend::XDialog;
106 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::XDialog (@opts,'XDIALOG_HIGH_DIALOG_COMPAT',1);
107 0 $self->_debug("using xdialog",2);
108 0 last;
109 0 } else { next; }
110 } elsif ($try =~ /^kdialog$/i) {
111 0 $self->_debug("trying kdialog",2);
112 0 ▶ if (eval "require UI::Dialog::Backend::KDialog; 1" && $self->_has_variant('kdialog')) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::KDialog; 1' and $self->_has_variant('kdialog')) { } 0 0 0
Condition0%0/3
eval "require UI::Dialog::Backend::KDialog; 1" and $self->_has_variant("kdialog")
!ll&&!rl&&r
000
MC/DC0%0/2
eval "require UI::Dialog::Backend::KDialog; 1" and $self->_has_variant("kdialog")
eval "require UI::Dialog::Backend::KDialog; 1" $self->_has_variant("kdialog")
Truth table0%0/3
A and B
A= eval "require UI::Dialog::Backend::KDialog; 1"B= $self->_has_variant("kdialog")
ABresult
0X0
100
111
113 0 require UI::Dialog::Backend::KDialog;
114 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::KDialog (@opts);
115 0 $self->_debug("using kdialog",2);
116 0 last;
117 0 } else { next; }
118 } elsif ($try =~ /^GNOME$/i) {
119 0 ▶ if (eval "require UI::Dialog::GNOME; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::GNOME; 1') { } 0 0 0
120 0 require UI::Dialog::GNOME;
121 0 $self->{'_ui_dialog'} = new UI::Dialog::GNOME (@opts);
122 0 last;
123 0 } else { next; }
124 } elsif ($try =~ /^KDE$/i) {
125 0 ▶ if (eval "require UI::Dialog::KDE; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::KDE; 1') { } 0 0 0
126 0 require UI::Dialog::KDE;
127 0 $self->{'_ui_dialog'} = new UI::Dialog::KDE (@opts);
128 0 last;
129 0 } else { next; }
130 } elsif ($try =~ /^CONSOLE$/i) {
131 0 ▶ if (eval "require UI::Dialog::Console; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Console; 1') { } 0 0 0
132 0 require UI::Dialog::Console;
133 0 $self->{'_ui_dialog'} = new UI::Dialog::Console (@opts);
134 0 last;
135 0 } else { next; }
136 } elsif ($try =~ /^(?:dialog|cdialog)$/i) {
137 1 $self->_debug("trying cdialog",2);
138 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
100
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
139 0 require UI::Dialog::Backend::CDialog;
140 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::CDialog (@opts);
141 0 $self->_debug("using cdialog",2);
142 0 last;
143 1 } else { next; }
144 } elsif ($try =~ /^whiptail$/i) {
145 1 $self->_debug("trying whiptail",2);
146 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
100
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
147 0 require UI::Dialog::Backend::Whiptail;
148 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::Whiptail (@opts);
149 0 $self->_debug("using whiptail",2);
150 0 last;
151 1 } else { next; }
152 } elsif ($try =~ /^(?:ascii|native)$/i) {
153 1 $self->_debug("trying ascii",2);
154 1 ▶ if (eval "require UI::Dialog::Backend::ASCII; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::ASCII; 1') { } 0 1 1
155 0 require UI::Dialog::Backend::ASCII;
156 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::ASCII (@opts);
157 0 $self->_debug("using ascii",2);
158 0 last;
159 1 } else { next; }
160 0 } else { next; }
161 }
162 } else {
163 0 ▶ if (eval "require UI::Dialog::Backend::ASCII; 1") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval 'require UI::Dialog::Backend::ASCII; 1') { } 0 0 0
164 0 require UI::Dialog::Backend::ASCII;
165 0 $self->{'_ui_dialog'} = new UI::Dialog::Backend::ASCII (@opts);
166 } else {
167 0 carp("Failed to load any suitable dialog variant backend.");
168 }
169 }
170  
171 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
172 0 return($self);
173 }
174  
175 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
176 #: Private Methods
177 #:
178  
179 #: purely internal usage
180 sub _debug {
181 6 ▶ my $self = $_[0];
Subroutine _debug: called CC=5 SCAR=20.2
182 6 ▶ my $mesg = $_[1] || 'null error message given!';
Condition50%1/2
$_[1] || 'null error message given!'
l!l
60
MC/DC0%0/1
$_[1] || 'null error message given!'
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
183 6 ▶ my $rate = $_[2] || 1;
Condition50%1/2
$_[2] || 1
l!l
60
MC/DC0%0/1
$_[2] || 1
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
184 6 ▶ return() unless $self->{'debug'} and $self->{'debug'} >= $rate;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug"} and $self->{"debug"} >= $rate 6 0 6
Condition33%1/3
$self->{"debug"} and $self->{"debug"} >= $rate
!ll&&!rl&&r
600
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
185 0 chomp($mesg);
186 0 print STDERR "Debug: ".$mesg."\n";
187 }
188  
189 sub _has_variant {
190 0 ▶ my $self = $_[0];
Subroutine _has_variant: not called CC=5 SCAR=34.0
191 0 my $variant = $_[1];
192 $self->{'PATHS'} = ((ref($self->{'PATHS'}) eq "ARRAY") ? $self->{'PATHS'} :
193 0 ▶ ($self->{'PATHS'}) ? [ $self->{'PATHS'} ] :
Branch: 2 branches
BranchTrueFalseTotal
ref $self->{'PATHS'} eq 'ARRAY' ? : 0 0 0
$self->{'PATHS'} ? : 0 0 0
194 [ '/bin', '/usr/bin', '/usr/local/bin', '/opt/bin' ]);
195 0 foreach my $PATH (@{$self->{'PATHS'}}) {
196 0 ▶ return($PATH . '/' . $variant)
Branch: 1 branch
BranchTrueFalseTotal
if -x $PATH . '/' . $variant 0 0 0
197 unless not -x $PATH . '/' . $variant;
198 }
199 0 return(0);
200 }
201  
202 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
203 #: Public Methods
204 #:
205  
206 #: dialog variant state methods:
207 0 ▶sub state { return(shift()->{'_ui_dialog'}->state(@_)); }
Subroutine state: not called CC=1 SCAR=6.9
Pod documented
208 0 ▶sub ra { return(shift()->{'_ui_dialog'}->ra(@_)); }
Subroutine ra: not called CC=1 SCAR=6.9
Pod documented
209 0 ▶sub rs { return(shift()->{'_ui_dialog'}->rs(@_)); }
Subroutine rs: not called CC=1 SCAR=6.9
Pod documented
210 0 ▶sub rv { return(shift()->{'_ui_dialog'}->rv(@_)); }
Subroutine rv: not called CC=1 SCAR=6.9
Pod documented
211  
212 #: Frills
213 #: all backends support nautilus scripts.
214 0 ▶sub nautilus { return(shift()->{'_ui_dialog'}->nautilus(@_)); }
Subroutine nautilus: not called CC=1 SCAR=6.9
Pod undocumented
215 #: same with osd_cat (aka: xosd).
216 0 ▶sub xosd { return(shift()->{'_ui_dialog'}->xosd(@_)); }
Subroutine xosd: not called CC=1 SCAR=6.9
Pod undocumented
217 #: Beep & Clear may have no affect when using GUI backends
218 0 ▶sub beep { return(shift()->{'_ui_dialog'}->beep(@_)); }
Subroutine beep: not called CC=1 SCAR=6.9
Pod undocumented
219 0 ▶sub clear { return(shift()->{'_ui_dialog'}->clear(@_)); }
Subroutine clear: not called CC=1 SCAR=6.9
Pod undocumented
220  
221 #: widget methods:
222 0 ▶sub yesno { return(shift()->{'_ui_dialog'}->yesno(@_)); }
Subroutine yesno: not called CC=1 SCAR=6.9
Pod documented
223 0 ▶sub msgbox { return(shift()->{'_ui_dialog'}->msgbox(@_)); }
Subroutine msgbox: not called CC=1 SCAR=6.9
Pod documented
224 0 ▶sub inputbox { return(shift()->{'_ui_dialog'}->inputbox(@_)); }
Subroutine inputbox: not called CC=1 SCAR=6.9
Pod documented
225 0 ▶sub password { return(shift()->{'_ui_dialog'}->password(@_)); }
Subroutine password: not called CC=1 SCAR=6.9
Pod documented
226 0 ▶sub textbox { return(shift()->{'_ui_dialog'}->textbox(@_)); }
Subroutine textbox: not called CC=1 SCAR=6.9
Pod documented
227 0 ▶sub menu { return(shift()->{'_ui_dialog'}->menu(@_)); }
Subroutine menu: not called CC=1 SCAR=6.9
Pod documented
228 0 ▶sub checklist { return(shift()->{'_ui_dialog'}->checklist(@_)); }
Subroutine checklist: not called CC=1 SCAR=6.9
Pod documented
229 0 ▶sub radiolist { return(shift()->{'_ui_dialog'}->radiolist(@_)); }
Subroutine radiolist: not called CC=1 SCAR=6.9
Pod documented
230 0 ▶sub fselect { return(shift()->{'_ui_dialog'}->fselect(@_)); }
Subroutine fselect: not called CC=1 SCAR=6.9
Pod documented
231 0 ▶sub dselect { return(shift()->{'_ui_dialog'}->dselect(@_)); }
Subroutine dselect: not called CC=1 SCAR=6.9
Pod documented
232  
233 1 1;
234  
235 =head1 NAME
236  
237 UI::Dialog - wrapper for various dialog applications.
238  
239 =head1 SYNOPSIS
240  
241 use UI::Dialog;
242 my $d = new UI::Dialog ( backtitle => 'Demo', title => 'Default',
243 height => 20, width => 65 , listheight => 5,
244 order => [ 'zenity', 'xdialog' ] );
245  
246 # Either a Zenity or Xdialog msgbox widget should popup,
247 # with a preference for Zenity.
248 $d->msgbox( title => 'Welcome!', text => 'Welcome one and all!' );
249  
250 =head1 ABSTRACT
251  
252 UI::Dialog is a OOPerl wrapper for the various dialog applications. These
253 dialog backends are currently supported: Zenity, XDialog, GDialog, KDialog,
254 CDialog, and Whiptail. There is also an ASCII backend provided as a last
255 resort interface for the console based dialog variants. UI::Dialog is a
256 class that provides a strict interface to these various backend modules.
257 By using UI:Dialog (with it's imposed limitations on the widgets) you can
258 ensure that your Perl program will function with any available interfaces.
259  
260 =head1 DESCRIPTION
261  
262 UI::Dialog supports priority ordering of the backend detection process. So
263 if you'd prefer that Xdialog should be used first if available, simply
264 designate the desired order when creating the new object. The default order
265 for detecting and utilization of the backends are as follows:
266 (with DISPLAY env): Zenity, GDialog, XDialog, KDialog
267 (without DISPLAY): CDialog, Whiptail, ASCII
268  
269 UI::Dialog is the result of a complete re-write of the UDPM CPAN module. This
270 was done to break away from the bad choice of name (UserDialogPerlModule) and
271 to implement a cleaner, more detached, OOPerl interface.
272  
273 =head1 EXPORT
274  
275 =over 2
276  
277 None
278  
279 =back
280  
281 =head1 INHERITS
282  
283 =over 2
284  
285 None
286  
287 =back
288  
289 =head1 CONSTRUCTOR
290  
291 =over 2
292  
293 =back
294  
295 =head2 new( @options )
296  
297 =over 4
298  
299 =item EXAMPLE
300  
301 =over 6
302  
303 my $d = new( title => 'Default Title', backtitle => 'Backtitle',
304 width => 65, height => 20, listheight => 5,
305 order => [ 'zenity', 'xdialog', 'gdialog' ] );
306  
307 =back
308  
309 =item DESCRIPTION
310  
311 =over 6
312  
313 This is the Class Constructor method. It accepts a list of key => value pairs
314 and uses them as the defaults when interacting with the various widgets.
315  
316 =back
317  
318 =item RETURNS
319  
320 =over 6
321  
322 A blessed object reference of the UI::Dialog class.
323  
324 =back
325  
326 =item OPTIONS
327  
328 The (...)'s after each option indicate the default for the option. An * denotes
329 support by all the widget methods on a per-use policy defaulting to the values
330 decided during object creation.
331  
332 =over 6
333  
334 =item B<debug = 0,1,2> (0)
335  
336 =item B<order = [ zenity, xdialog, gdialog, kdialog, cdialog, whiptail, ascii ]> (as indicated)
337  
338 =item B<PATH = [ /bin, /usr/bin, /usr/local/bin, /opt/bin ]> (as indicated)
339  
340 =item B<backtitle = "backtitle"> ('') *
341  
342 =item B<title = "title"> ('') *
343  
344 =item B<beepbefore = 0,1> (0) *
345  
346 =item B<beepafter = 0,1> (0) *
347  
348 =item B<height = \d+> (20) *
349  
350 =item B<width = \d+> (65) *
351  
352 =item B<listheight = \d+> (5) *
353  
354 =back
355  
356 =back
357  
358 =head1 STATE METHODS
359  
360 =over 2
361  
362 =back
363  
364 =head2 state( )
365  
366 =over 4
367  
368 =item EXAMPLE
369  
370 =over 6
371  
372 if ($d->state() eq "OK") {
373 $d->msgbox( text => "that went well" );
374 }
375  
376 =back
377  
378 =item DESCRIPTION
379  
380 =over 6
381  
382 Returns the state of the last dialog widget command. The value can be one of
383 "OK", "CANCEL", "ESC". The return data is based on the exit codes (return value) of the
384 last widget displayed.
385  
386 =back
387  
388 =item RETURNS
389  
390 =over 6
391  
392 a single SCALAR.
393  
394 =back
395  
396 =back
397  
398 =over 2
399  
400 =back
401  
402 =head2 ra( )
403  
404 =over 4
405  
406 =item EXAMPLE
407  
408 =over 6
409  
410 my @array = $d->ra();
411  
412 =back
413  
414 =item DESCRIPTION
415  
416 =over 6
417  
418 Returns the last widget's data as an array.
419  
420 =back
421  
422 =item RETURNS
423  
424 =over 6
425  
426 an ARRAY.
427  
428 =back
429  
430 =back
431  
432 =over 2
433  
434 =back
435  
436 =head2 rs( )
437  
438 =over 4
439  
440 =item EXAMPLE
441  
442 =over 6
443  
444 my $string = $d->rs();
445  
446 =back
447  
448 =item DESCRIPTION
449  
450 =over 6
451  
452 Returns the last widget's data as a (possibly multiline) string.
453  
454 =back
455  
456 =item RETURNS
457  
458 =over 6
459  
460 a SCALAR.
461  
462 =back
463  
464 =back
465  
466 =over 2
467  
468 =back
469  
470 =head2 rv( )
471  
472 =over 4
473  
474 =item EXAMPLE
475  
476 =over 6
477  
478 my $string = $d->rv();
479  
480 =back
481  
482 =item DESCRIPTION
483  
484 =over 6
485  
486 Returns the last widget's exit status, aka: return value.
487  
488 =back
489  
490 =item RETURNS
491  
492 =over 6
493  
494 a SCALAR.
495  
496 =back
497  
498 =back
499  
500 =head1 WIDGET METHODS
501  
502 =over 2
503  
504 =back
505  
506 =head2 yesno( )
507  
508 =over 4
509  
510 =item EXAMPLE
511  
512 =over 6
513  
514 if ($d->yesno( text => 'A binary type question?') ) {
515 # user pressed yes
516 } else {
517 # user pressed no or cancel
518 }
519  
520 =back
521  
522 =item DESCRIPTION
523  
524 =over 6
525  
526 Present the end user with a message box that has two buttons, yes and no.
527  
528 =back
529  
530 =item RETURNS
531  
532 =over 6
533  
534 TRUE (1) for a response of YES or FALSE (0) for anything else.
535  
536 =back
537  
538 =back
539  
540 =over 2
541  
542 =back
543  
544 =head2 msgbox( )
545  
546 =over 4
547  
548 =item EXAMPLE
549  
550 =over 6
551  
552 $d->msgbox( text => 'A simple message' );
553  
554 =back
555  
556 =item DESCRIPTION
557  
558 =over 6
559  
560 Pesent the end user with a message box that has an OK button.
561  
562 =back
563  
564 =item RETURNS
565  
566 =over 6
567  
568 TRUE (1) for a response of OK or FALSE (0) for anything else.
569  
570 =back
571  
572 =back
573  
574 =over 2
575  
576 =back
577  
578 =head2 inputbox( )
579  
580 =over 4
581  
582 =item EXAMPLE
583  
584 =over 6
585  
586 my $string = $d->inputbox( text => 'Please enter some text...',
587 entry => 'this is the input field' );
588  
589 =back
590  
591 =item DESCRIPTION
592  
593 =over 6
594  
595 Present the end user with a text input field and a message.
596  
597 =back
598  
599 =item RETURNS
600  
601 =over 6
602  
603 a SCALAR if the response is OK and FALSE (0) for anything else.
604  
605 =back
606  
607 =back
608  
609 =over 2
610  
611 =back
612  
613 =head2 password( )
614  
615 =over 4
616  
617 =item EXAMPLE
618  
619 =over 6
620  
621 my $string = $d->password( text => 'Enter some hidden text.' );
622  
623 =back
624  
625 =item DESCRIPTION
626  
627 =over 6
628  
629 Present the end user with a text input field, that has hidden input, and a message.
630  
631 Note that the GDialog backend will provide a regular inputbox instead of a password
632 box because gdialog doesn't support passwords. GDialog is on it's way to the proverbial
633 software heaven so this isn't a real problem. Use Zenity instead :)
634  
635 =back
636  
637 =item RETURNS
638  
639 =over 6
640  
641 a SCALAR if the response is OK and FALSE (0) for anything else.
642  
643 =back
644  
645 =back
646  
647 =over 2
648  
649 =back
650  
651 =head2 textbox( )
652  
653 =over 4
654  
655 =item EXAMPLE
656  
657 =over 6
658  
659 $d->textbox( path => '/path/to/a/text/file' );
660  
661 =back
662  
663 =item DESCRIPTION
664  
665 =over 6
666  
667 Present the end user with a simple scrolling box containing the contents
668 of the given text file.
669  
670 =back
671  
672 =item RETURNS
673  
674 =over 6
675  
676 TRUE (1) if the response is OK and FALSE (0) for anything else.
677  
678 =back
679  
680 =back
681  
682 =over 2
683  
684 =back
685  
686 =head2 menu( )
687  
688 =over 4
689  
690 =item EXAMPLE
691  
692 =over 6
693  
694 my $selection1 = $d->menu( text => 'Select one:',
695 list => [ 'tag1', 'item1',
696 'tag2', 'item2',
697 'tag3', 'item3' ] );
698  
699 =back
700  
701 =item DESCRIPTION
702  
703 =over 6
704  
705 Present the user with a selectable list.
706  
707 =back
708  
709 =item RETURNS
710  
711 =over 6
712  
713 a SCALAR of the chosen tag if the response is OK and FALSE (0) for
714 anything else.
715  
716 =back
717  
718 =back
719  
720 =over 2
721  
722 =back
723  
724 =head2 checklist( )
725  
726 =over 4
727  
728 =item EXAMPLE
729  
730 =over 6
731  
732 my @selection1 = $d->checklist( text => 'Select one:',
733 list => [ 'tag1', [ 'item1', 0 ],
734 'tag2', [ 'item2', 1 ],
735 'tag3', [ 'item3', 1 ] ]
736 );
737  
738 =back
739  
740 =item DESCRIPTION
741  
742 =over 6
743  
744 Present the user with a selectable checklist.
745  
746 =back
747  
748 =item RETURNS
749  
750 =over 6
751  
752 an ARRAY of the chosen tags if the response is OK and FALSE (0) for
753 anything else.
754  
755 =back
756  
757 =back
758  
759 =over 2
760  
761 =back
762  
763 =head2 radiolist( )
764  
765 =over 4
766  
767 =item EXAMPLE
768  
769 =over 6
770  
771 my $selection1 = $d->radiolist( text => 'Select one:',
772 list => [ 'tag1', [ 'item1', 0 ],
773 'tag2', [ 'item2', 1 ],
774 'tag3', [ 'item3', 0 ] ]
775 );
776  
777 =back
778  
779 =item DESCRIPTION
780  
781 =over 6
782  
783 Present the user with a selectable radiolist.
784  
785 =back
786  
787 =item RETURNS
788  
789 =over 6
790  
791 a SCALAR of the chosen tag if the response is OK and FALSE (0) for
792 anything else.
793  
794 =back
795  
796 =back
797  
798 =over 2
799  
800 =back
801  
802 =head2 fselect( )
803  
804 =over 4
805  
806 =item EXAMPLE
807  
808 =over 6
809  
810 my $text = $d->fselect( path => '/path/to/a/file/or/directory' );
811  
812 =back
813  
814 =item DESCRIPTION
815  
816 =over 6
817  
818 Present the user with a file selection widget preset with the given path.
819  
820 =back
821  
822 =item RETURNS
823  
824 =over 6
825  
826 a SCALAR if the response is OK and FALSE (0) for anything else.
827  
828 =back
829  
830 =back
831  
832 =over 2
833  
834 =back
835  
836 =head2 dselect( )
837  
838 =over 4
839  
840 =item EXAMPLE
841  
842 =over 6
843  
844 my $text = $d->dselect( path => '/path/to/a/file/or/directory' );
845  
846 =back
847  
848 =item DESCRIPTION
849  
850 =over 6
851  
852 Present the user with a file selection widget preset with the given path.
853 Unlike fselect() this widget will only return a directory selection.
854  
855 =back
856  
857 =item RETURNS
858  
859 =over 6
860  
861 a SCALAR if the response is OK and FALSE (0) for anything else.
862  
863 =back
864  
865 =back
866  
867 =head1 SEE ALSO
868  
869 =over 2
870  
871 =item PERLDOC
872  
873 UI::Dialog::GNOME
874 UI::Dialog::KDE
875 UI::Dialog::Console
876 UI::Dialog::Backend
877 UI::Dialog::Backend::ASCII
878 UI::Dialog::Backend::CDialog
879 UI::Dialog::Backend::GDialog
880 UI::Dialog::Backend::KDialog
881 UI::Dialog::Backend::Nautilus
882 UI::Dialog::Backend::Whiptail
883 UI::Dialog::Backend::XDialog
884 UI::Dialog::Backend::XOSD
885 UI::Dialog::Backend::Zenity
886  
887 =back
888  
889 =over 2
890  
891 =item MAN FILES
892  
893 dialog(1), whiptail(1), zenity(1), gdialog(1), Xdialog(1),
894 osd_cat(1), kdialog(1) and nautilus(1)
895  
896 =back
897  
898 =head1 BUGS
899  
900 Please email the author with any bug reports. Include the name of the
901 module in the subject line.
902  
903 =head1 AUTHOR
904  
905 Kevin C. Krinke, E<lt>kevin@krinke.caE<gt>
906  
907 =head1 COPYRIGHT AND LICENSE
908  
909 Copyright (C) 2004-2016 Kevin C. Krinke <kevin@krinke.ca>
910  
911 This library is free software; you can redistribute it and/or
912 modify it under the terms of the GNU Lesser General Public
913 License as published by the Free Software Foundation; either
914 version 2.1 of the License, or (at your option) any later version.
915  
916 This library is distributed in the hope that it will be useful,
917 but WITHOUT ANY WARRANTY; without even the implied warranty of
918 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
919 Lesser General Public License for more details.
920  
921 You should have received a copy of the GNU Lesser General Public
922 License along with this library; if not, write to the Free Software
923 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
924  
925 =cut
↑ Summary Dialog/Console.pm »