lib/TUI/MsgBox/MsgBoxText.pm

filter: Statementstmt 53.2% 73 / 137 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 20 / 24 Podpod 100% 4 / 4 totaltotal 51.6% 97 / 188 CC 11 SCAR 29.1
CC
11
Cov
46%
messageBoxRect
72.0
inputBox
6.0
inputBoxRect
6.0
CRAP 18.4
« lib/TUI/Views/View/Exposed.pm ↑ Summary lib/TUI/StdDlg/Util.pm »
1 package TUI::MsgBox::MsgBoxText;
2 # ABSTRACT: Message Box and Input Box functions for the framework
3
4 19 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 19 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 19 our @EXPORT_OK = qw(
11 messageBox
12 messageBoxRect
13 inputBox
14 inputBoxRect
15 );
16
17 19 our %EXPORT_TAGS = (
18 all => \@EXPORT_OK,
19 );
20
21 19 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 19 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 19 ▶use TUI::toolkit qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 :boolean
25 :utils
26 19 );
27 19 ▶use TUI::toolkit::Types qw( :types );
Subroutine BEGIN: called CC=1 SCAR=0.0
28
29 19 ▶use TUI::App::Program qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 $application
31 $deskTop
32 19 );
33 19 ▶use TUI::Dialogs::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
34 bfDefault
35 bfNormal
36 19 );
37 19 ▶use TUI::Dialogs::Button;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 19 ▶use TUI::Dialogs::Dialog;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 19 ▶use TUI::Dialogs::InputLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 19 ▶use TUI::Dialogs::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 19 ▶use TUI::Dialogs::StaticText;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 19 ▶use TUI::MsgBox::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
43 :mfXXXX
44 19 );
45 19 ▶use TUI::Objects::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 19 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 19 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
48 cmYes
49 cmNo
50 cmOK
51 cmCancel
52 19 );
53
54 # declare global variables
55 19 our $yesText = "~Y~es";
56 19 our $noText = "~N~o";
57 19 our $okText = "O~K~";
58 19 our $cancelText = "Cancel";
59 19 our $warningText = "Warning";
60 19 our $errorText = "Error";
61 19 our $informationText = "Information";
62 19 our $confirmText = "Confirm";
63
64 # Button caption texts
65 19 my @buttonName = (
66 $yesText,
67 $noText,
68 $okText,
69 $cancelText,
70 );
71
72 # Commands for each button
73 19 my @commands = (
74 cmYes,
75 cmNo,
76 cmOK,
77 cmCancel,
78 );
79
80 # Titles for different message box types
81 19 my @Titles = (
82 $warningText,
83 $errorText,
84 $informationText,
85 $confirmText,
86 );
87
88 0 ▶sub messageBox { # $command ($msg|$aOptions, $aOptions|$fmt, @list)
Subroutine messageBox: not called CC=2 SCAR=12.2
Pod documented
89 0 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
90 0 ▶ assert ( @_ >= 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 0 0 0
91 0 my $r = TRect->new( ax => 0, ay => 0, bx => 40, by => 9 );
92 $r->move(
93 int( ( $deskTop->{size}{x} - $r->{b}{x} ) / 2 ),
94 0 int( ( $deskTop->{size}{y} - $r->{b}{y} ) / 2 ),
95 );
96 0 return messageBoxRect( $r, @_ );
97 }
98
99 0 ▶sub messageBoxRect { # $command ($r, $msg|$aOptions, $aOptions|$fmt, @list)
Subroutine messageBoxRect: not called CC=8 SCAR=42.8
Pod documented
100 0 my ( $r, $msg, $aOptions );
101 0 ▶ if ( looks_like_number $_[2] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($_[2])) { } 0 0 0
102 0 state $sig = signature(
103 pos => [Object, Str, PositiveOrZeroInt],
104 );
105 0 ( $r, $msg, $aOptions ) = $sig->( @_ );
106 }
107 else {
108 0 state $sig = signature(
109 pos => [Object, PositiveOrZeroInt, Str, ArrayRef, { slurpy => 1 }],
110 );
111 0 my ( $fmt, $list );
112 0 ( $r, $aOptions, $fmt, $list ) = $sig->( @_ );
113 0 ▶ assert ( defined $fmt and !ref $fmt );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt and not ref $fmt 0 0 0
Condition0%0/3
defined $fmt and not ref $fmt
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fmt and not ref $fmt
defined $fmt not ref $fmt
Truth table0%0/3
A and not(B)
A= defined $fmtB= not ref $fmt
ABresult
0X0
100
111
114 0 $msg = sprintf( $fmt, @$list );
115 }
116
117 0 my $dialog;
118 0 my ( $i, $x, $buttonCount );
119 0 my @buttonList;
120 0 my $ccode;
121
122 0 $dialog = TDialog->new( bounds => $r, title => $Titles[ $aOptions & 0x3 ] );
123
124 $dialog->insert(
125 TStaticText->new(
126 bounds => TRect->new(
127 ax => 3,
128 ay => 2,
129 bx => $dialog->{size}{x} - 2,
130 0 by => $dialog->{size}{y} - 3,
131 ),
132 text => $msg,
133 )
134 );
135 0 ▶ for ( $i = 0, $x = -2, $buttonCount = 0 ; $i < 4 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 0 0 0
136 0 ▶ if ( $aOptions & ( 0x0100 << $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aOptions & 256 << $i) 0 0 0
137 0 $buttonList[$buttonCount] = TButton->new(
138 bounds => TRect->new( ax => 0, ay => 0, bx => 10, by => 2 ),
139 title => $buttonName[$i],
140 command => $commands[$i],
141 flags => bfNormal,
142 );
143 0 $x += $buttonList[$buttonCount++]->{size}{x} + 2;
144 } #/ if ( ( $aOptions & ( 0x0100...)))
145 } #/ for ( $i = 0, $x = -2, ...)
146
147 0 $x = int( ( $dialog->{size}{x} - $x ) / 2 );
148
149 0 ▶ for ( $i = 0 ; $i < $buttonCount ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $buttonCount) 0 0 0
150 0 $dialog->insert( $buttonList[$i] );
151 0 $buttonList[$i]->moveTo( $x, $dialog->{size}{y} - 3 );
152 0 $x += $buttonList[$i]->{size}{x} + 2;
153 }
154
155 0 $dialog->selectNext( false );
156
157 0 ▶ $ccode = $application ? $application->execView( $dialog ) : cmCancel;
Branch: 1 branch
BranchTrueFalseTotal
$TUI::MsgBox::MsgBoxText::application ? : 0 0 0
158
159 0 TObject->destroy( $dialog );
160
161 0 return $ccode;
162 }; #/ sub messageBoxRect
163
164 0 ▶sub inputBox { # $command ($Title, $aLabel, $s, $limit)
Subroutine inputBox: not called CC=2 SCAR=17.9
Pod documented
165 0 ▶ assert ( @_ == 4 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 0 0 0
166 0 my $r = TRect->new( ax => 0, ay => 0, bx => 60, by => 8 );
167 $r->move(
168 int( ( $deskTop->{size}{x} - $r->{b}{x} ) / 2 ),
169 0 int( ( $deskTop->{size}{y} - $r->{b}{y} ) / 2 ),
170 );
171 0 return inputBoxRect( $r, @_ );
172 }
173
174 0 ▶sub inputBoxRect { # $command ($bounds, $Title, $aLabel, \@s, $limit)
Subroutine inputBoxRect: not called CC=2 SCAR=17.9
Pod documented
175 0 state $sig = signature(
176 pos => [Object, Str, Str, ArrayLike, PositiveOrZeroInt],
177 );
178 0 my ( $bounds, $Title, $aLabel, $s, $limit ) = $sig->( @_ );
179
180 0 my $dialog;
181 my $control;
182 0 my $r;
183 0 my $c;
184
185 0 $dialog = TDialog->new( bounds => $bounds, title => $Title );
186 $r = TRect->new(
187 ax => 4 + length( $aLabel ), ay => 2,
188 0 bx => $dialog->{size}{x} - 3, by => 3,
189 );
190 0 $control = TInputLine->new( bounds => $r, maxLen => $limit );
191 0 $dialog->insert( $control );
192
193 0 $r = TRect->new( ax => 2, ay => 2, bx => 3 + length( $aLabel ), by => 3 );
194 0 $dialog->insert(
195 TLabel->new( bounds => $r, text => $aLabel, link => $control )
196 );
197
198 $r = TRect->new(
199 ax => $dialog->{size}{x} - 24, ay => $dialog->{size}{y} - 4,
200 0 bx => $dialog->{size}{x} - 14, by => $dialog->{size}{y} - 2,
201 );
202 0 $dialog->insert(
203 TButton->new(
204 bounds => $r,
205 title => $okText,
206 command => cmOK,
207 flags => bfDefault,
208 )
209 );
210
211 0 $r->{a}{x} += 12;
212 0 $r->{b}{x} += 12;
213 0 $dialog->insert(
214 TButton->new(
215 bounds => $r,
216 title => $cancelText,
217 command => cmCancel,
218 flags => bfNormal,
219 )
220 );
221
222 0 $r->{a}{x} += 12;
223 0 $r->{b}{x} += 12;
224 0 $dialog->selectNext( false );
225 0 $dialog->setData( $s );
226 0 $c = $application->execView( $dialog );
227 0 ▶ if ( $c != cmCancel ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c != 11) 0 0 0
228 0 $dialog->getData( $s );
229 }
230 0 TObject->destroy( $dialog );
231 0 return $c;
232 } #/ sub inputBoxRect
233
234 19 1
235
236 __END__
« lib/TUI/Views/View/Exposed.pm ↑ Summary lib/TUI/StdDlg/Util.pm »