lib/TUI/StdDlg/ChDirDialog.pm

filter: Statementstmt 39.1% 96 / 245 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 62.5% 25 / 40 Podpod 69.2% 9 / 13 totaltotal 33.9% 130 / 383 CC 37 SCAR 37.7
CC
37
Cov
30%
handleEvent
156.0
valid
56.0
__ANON__
56.0
CRAP 43.2
« lib/TUI/Dialogs/Dialog.pm ↑ Summary lib/TUI/TextView/Terminal.pm »
1 package TUI::StdDlg::ChDirDialog;
2 # ABSTRACT: Common dialog box for selecting a directory
3
4 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 5 our $VERSION = '2.000003';
9 5 $VERSION =~ tr/_//d;
10 5 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 our @EXPORT = qw(
14 TChDirDialog
15 new_TChDirDialog
16 );
17
18 5 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 Maybe
23 :is
24 :types
25 5 );
26
27 5 ▶use TUI::Const qw( EOS );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use TUI::Dialogs::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 bfDefault
30 bfNormal
31 5 );
32 5 ▶use TUI::Dialogs::Button;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use TUI::Dialogs::Dialog;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use TUI::Dialogs::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use TUI::Dialogs::InputLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use TUI::Dialogs::History;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use TUI::Drivers::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
38 evBroadcast
39 evCommand
40 5 );
41 5 ▶use TUI::MsgBox::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
42 mfError
43 mfOKButton
44 5 );
45 5 ▶use TUI::MsgBox::MsgBoxText qw( messageBox );
Subroutine BEGIN: called CC=1 SCAR=0.0
46 5 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 5 ▶use TUI::StdDlg::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
48 :cmXXXX
49 cdHelpButton
50 cdNoLoadDir
51 5 );
52 5 ▶use TUI::StdDlg::Dir qw( setdisk );
Subroutine BEGIN: called CC=1 SCAR=0.0
53 5 ▶use TUI::StdDlg::DirListBox;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 5 ▶use TUI::StdDlg::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
55 driveValid
56 fexpand
57 getCurDir
58 5 );
59 5 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
60 cmHelp
61 cmOK
62 ofCentered
63 5 );
64 5 ▶use TUI::Views::ScrollBar;
Subroutine BEGIN: called CC=1 SCAR=0.0
65
66 sub TChDirDialog() { __PACKAGE__ }
67 sub name() { 'TChDirDialog' }
68 0 ▶sub new_TChDirDialog { __PACKAGE__->from(@_) }
Subroutine new_TChDirDialog: not called CC=1 SCAR=6.9
Pod documented
69
70 5 extends TDialog;
71
72 # declare global variables
73 5 our $changeDirTitle = "Change Directory";
74 5 our $dirNameText = "Directory ~n~ame";
75 5 our $dirTreeText = "Directory ~t~ree";
76 5 our $okText = "O~K~";
77 5 our $chdirText = "~C~hdir";
78 5 our $revertText = "~R~evert";
79 5 our $helpText = "Help";
80 5 our $drivesText = "Drives";
81 5 our $invalidText = "Invalid directory";
82
83 # private attributes
84 5 has dirInput => ( is => 'bare' );
85 5 has dirList => ( is => 'bare' );
86 5 has okButton => ( is => 'bare' );
87 5 has chDirButton => ( is => 'bare' );
88
89 # predeclare private methods
90 my (
91 5 $setUpDialog,
92 );
93
94 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
95 0 state $sig = signature(
96 method => 1,
97 named => [
98 options => PositiveOrZeroInt, { alias => 'aOptions' },
99 histId => PositiveOrZeroInt,
100 ],
101 caller_level => +1,
102 );
103 0 my ( $class, $args1 ) = $sig->( @_ );
104 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
105 0 my $args2 = $class->SUPER::BUILDARGS(
106 bounds => TRect->new( ax => 16, ay => 2, bx => 64, by => 20 ),
107 title => $changeDirTitle,
108 );
109 0 return { %$args1, %$args2 };
110 }
111
112 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod documented
113 0 my ( $self, $args ) = @_;
114 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
115 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
116 0 ▶ assert ( is_HashRef $args );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_HashRef($args) 0 0 0
117 0 $self->{options} |= ofCentered;
118
119 0 $self->{dirInput} = TInputLine->new(
120 bounds => TRect->new( ax => 3, ay => 3, bx => 30, by => 4 ),
121 maxLen => 68,
122 );
123 0 $self->insert( $self->{dirInput} );
124 $self->insert( TLabel->new(
125 bounds => TRect->new( ax => 2, ay => 2, bx => 17, by => 3 ),
126 text => $dirNameText,
127 link => $self->{dirInput},
128 0 ));
129 $self->insert( THistory->new(
130 bounds => TRect->new( ax => 30, ay => 3, bx => 33, by => 4 ),
131 link => $self->{dirInput},
132 historyId => $args->{histId},
133 0 ));
134
135 0 my $sb = TScrollBar->new(
136 bounds => TRect->new( ax => 32, ay => 6, bx => 33, by => 16 )
137 );
138 0 $self->insert( $sb );
139 0 $self->{dirList} = TDirListBox->new(
140 bounds => TRect->new( ax => 3, ay => 6, bx => 32, by => 16 ),
141 vScrollBar => $sb,
142 );
143 0 $self->insert( $self->{dirList} );
144 $self->insert( TLabel->new(
145 bounds => TRect->new( ax => 2, ay => 5, bx => 17, by => 6 ),
146 text => $dirTreeText,
147 link => $self->{dirList},
148 0 ));
149
150 0 $self->{okButton} = TButton->new(
151 bounds => TRect->new( ax => 35, ay => 3, bx => 46, by => 5 ),
152 title => $okText,
153 command => cmOK,
154 flags => bfDefault,
155 );
156 0 $self->insert( $self->{okButton} );
157 0 $self->{chDirButton} = TButton->new(
158 bounds => TRect->new( ax => 35, ay => 9, bx => 45, by => 11 ),
159 title => $chdirText,
160 command => cmChangeDir,
161 flags => bfNormal,
162 );
163 0 $self->insert( $self->{chDirButton} );
164 0 $self->insert( TButton->new(
165 bounds => TRect->new( ax => 35, ay => 12, bx => 45, by => 14 ),
166 title => $revertText,
167 command => cmRevert,
168 flags => bfNormal,
169 ));
170 0 ▶ if ( $args->{options} & cdHelpButton ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"options"} & 2) 0 0 0
171 0 $self->insert( TButton->new(
172 bounds => TRect->new( ax => 35, ay => 15, bx => 45, by => 17 ),
173 title => $helpText,
174 command => cmHelp,
175 flags => bfNormal,
176 ));
177 }
178 $self->$setUpDialog()
179 0 ▶ unless $args->{options} & cdNoLoadDir;
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"options"} & 1 0 0 0
180 0 $self->selectNext( false );
181
182 0 return;
183 }
184
185 0 ▶sub from { # $obj ($aOptions, $histId)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
186 0 state $sig = signature(
187 method => 1,
188 pos => [PositiveOrZeroInt, PositiveOrZeroInt],
189 );
190 0 my ( $class, @args ) = $sig->( @_ );
191 0 return $class->new( options => $args[0], histId => $args[1] );
192 }
193
194 0 ▶sub dataSize { # $dSize ()
Subroutine dataSize: not called CC=1 SCAR=6.9
Pod documented
195 0 state $sig = signature(
196 method => Object,
197 pos => [],
198 );
199 0 $sig->( @_ );
200 0 return 0;
201 }
202
203 0 ▶sub getData { # void (\@rec)
Subroutine getData: not called CC=1 SCAR=6.9
Pod documented
204 0 state $sig = signature(
205 method => Object,
206 pos => [ArrayLike],
207 );
208 0 $sig->( @_ );
209 0 return;
210 }
211
212 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=12 SCAR=50.5
Pod documented
213 0 state $sig = signature(
214 method => Object,
215 pos => [Object],
216 );
217 0 my ( $self, $event ) = $sig->( @_ );
218 0 $self->SUPER::handleEvent( $event );
219 0 ▶ if ( $event->{what} == evCommand ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 256) 0 0 0
220 0 my $curDir = '';
221 0 SWITCH: for ( $event->{message}{command} ) {
222 0 ▶ cmRevert == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1006 == $_ and do { getCurDir($curDir); last } 0 0 0
223 0 getCurDir( $curDir );
224 0 last;
225 };
226 0 ▶ cmChangeDir == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1005 == $_ and do { my $p = $self->{"dirList"}->list->at($self->{"dirList"}{"focused"}); $curDir = $p->dir; if ($curDir eq $TUI::StdDlg::ChDirDialog::drivesText) { last; } elsif (length $curDir and driveValid(substr($curDir, 0, 1))) { $curDir .= '\\' if substr($curDir, -1, 1) ne "\\"; } else { return; } ; last } 0 0 0
227 0 my $p = $self->{dirList}->list()->at( $self->{dirList}{focused} );
228 0 $curDir = $p->dir();
229 0 ▶ if ( $curDir eq $drivesText ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($curDir eq $TUI::StdDlg::ChDirDialog::drivesText) { } 0 0 0
elsif (length $curDir and driveValid(substr($curDir, 0, 1))) { } 0 0 0
230 0 last;
231 }
232 ▶ elsif ( length( $curDir ) && driveValid( substr( $curDir, 0, 1 ) ) ) {
Condition0%0/3
length $curDir and driveValid(substr($curDir, 0, 1))
!ll&&!rl&&r
000
MC/DC0%0/2
length $curDir and driveValid(substr($curDir, 0, 1))
length $curDir driveValid(substr($curDir, 0, 1))
Truth table0%0/3
A and B
A= length $curDirB= driveValid(substr($curDir, 0, 1))
ABresult
0X0
100
111
233 0 ▶ $curDir .= "\\"
Branch: 1 branch
BranchTrueFalseTotal
if substr($curDir, -1, 1) ne "\\" 0 0 0
234 if substr( $curDir, -1, 1 ) ne '\\';
235 }
236 else {
237 0 return;
238 }
239 0 last;
240 };
241 # Handle directory selection.
242 0 ▶ cmDirSelection == $_ and do {
Branch: 1 branch
BranchTrueFalseTotal
1007 == $_ and do { $self->{"chDirButton"}->makeDefault(!!$event->{"message"}{"infoPtr"}); return } 0 0 0
243 0 $self->{chDirButton}->makeDefault( !!$event->{message}{infoPtr} );
244 0 return; # Note: return (not last) like in the original code
245 };
246 DEFAULT: {
247 0 return;
248 };
249 }
250 0 $self->{dirList}->newDirectory( $curDir );
251 0 my $len = length( $curDir );
252 0 ▶ if ( $len > 3 && substr( $curDir, -1, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 3 and substr($curDir, -1, 1) eq "\\") 0 0 0
Condition0%0/3
$len > 3 and substr($curDir, -1, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 3 and substr($curDir, -1, 1) eq "\\"
$len > 3 substr($curDir, -1, 1) eq "\\"
Truth table0%0/3
A and B
A= $len > 3B= substr($curDir, -1, 1) eq "\\"
ABresult
0X0
100
111
253 0 substr( $curDir, $len - 1 ) = EOS;
254 }
255 0 $self->{dirInput}{data} = $curDir;
256 0 $self->{dirInput}->drawView();
257 0 $self->{dirList}->select();
258 0 $self->clearEvent( $event );
259 }
260
261 0 return;
262 } #/ sub handleEvent
263
264 0 ▶sub setData { # void (\@rec)
Subroutine setData: not called CC=1 SCAR=6.9
Pod documented
265 0 state $sig = signature(
266 method => Object,
267 pos => [ArrayLike],
268 );
269 0 $sig->( @_ );
270 0 return;
271 }
272
273 0 ▶my $changeDir = sub { # $int ($path)
Subroutine __ANON__: not called CC=6 SCAR=37.4
274 0 my ( $path ) = @_;
275 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
276 0 ▶ assert ( is_Str $path );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($path) 0 0 0
277 0 ▶ if ( length( $path ) && substr( $path, 1, 1 ) eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $path and substr($path, 1, 1) eq ":") 0 0 0
Condition0%0/3
length $path and substr($path, 1, 1) eq ":"
!ll&&!rl&&r
000
MC/DC0%0/2
length $path and substr($path, 1, 1) eq ":"
length $path substr($path, 1, 1) eq ":"
Truth table0%0/3
A and B
A= length $pathB= substr($path, 1, 1) eq ":"
ABresult
0X0
100
111
278 0 setdisk( ord( uc substr( $path, 0, 1 ) ) - ord( 'A' ) );
279 }
280 0 ▶ return chdir( $path ) ? 0 : -1;
Branch: 1 branch
BranchTrueFalseTotal
chdir $path ? : 0 0 0
281 5 };
282
283 0 ▶sub valid { # $bool ($command)
Subroutine valid: not called CC=7 SCAR=40.3
Pod documented
284 0 state $sig = signature(
285 method => Object,
286 pos => [PositiveOrZeroInt],
287 );
288 0 my ( $self, $command ) = $sig->( @_ );
289
290 0 ▶ return true
Branch: 1 branch
BranchTrueFalseTotal
if $command != 10 0 0 0
291 if $command != cmOK;
292
293 0 my $path = $self->{dirInput}{data};
294
295 # BUG FIX - EFW - Tue 05/16/95
296 # Ignore "Drives" line if switching drives.
297 0 ▶ $path = ''
Branch: 1 branch
BranchTrueFalseTotal
if $path eq $TUI::StdDlg::ChDirDialog::drivesText 0 0 0
298 if $path eq $drivesText;
299
300 # If it was "Drives" or the input line was blank, issue a
301 # cmChangeDir event to select the current drive/directory.
302 0 ▶ if ( $path eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "") 0 0 0
303 0 my $event = TEvent->new();
304 0 $event->{what} = evCommand;
305 0 $event->{message}{command} = cmChangeDir;
306 0 $self->putEvent( $event );
307 0 return false;
308 }
309
310 # Otherwise, expand and check the path.
311 0 fexpand( $path );
312
313 0 my $len = length( $path );
314 0 ▶ if ( $len > 3 && substr( $path, -1, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 3 and substr($path, -1, 1) eq "\\") 0 0 0
Condition0%0/3
$len > 3 and substr($path, -1, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 3 and substr($path, -1, 1) eq "\\"
$len > 3 substr($path, -1, 1) eq "\\"
Truth table0%0/3
A and B
A= $len > 3B= substr($path, -1, 1) eq "\\"
ABresult
0X0
100
111
315 0 substr( $path, $len - 1 ) = EOS;
316 }
317
318 0 ▶ if ( &$changeDir( $path ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$changeDir($path) != 0) 0 0 0
319 0 messageBox( $invalidText, mfError | mfOKButton );
320 0 return false;
321 }
322 0 return true;
323 }
324
325 0 ▶sub shutDown { # void ($self)
Subroutine shutDown: not called CC=1 SCAR=6.9
Pod documented
326 0 state $sig = signature(
327 method => Object,
328 pos => [],
329 );
330 0 my ( $self ) = $sig->( @_ );
331 0 $self->{dirList} = undef;
332 0 $self->{dirInput} = undef;
333 0 $self->{okButton} = undef;
334 0 $self->{chDirButton} = undef;
335 0 $self->SUPER::shutDown();
336 0 return;
337 }
338
339 0 ▶$setUpDialog = sub { # void ()
Subroutine __ANON__: not called CC=7 SCAR=40.3
340 0 my ( $self ) = @_;
341 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
342 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
343
344 0 ▶ if ( $self->{dirList} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dirList"}) 0 0 0
345 0 my $curDir = '';
346 0 getCurDir( $curDir );
347 0 $self->{dirList}->newDirectory( $curDir );
348 0 ▶ if ( $self->{dirInput} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dirInput"}) 0 0 0
349 0 my $len = length $curDir;
350 0 ▶ if ( $len > 3 && substr( $curDir, $len - 1, 1 ) eq '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 3 and substr($curDir, $len - 1, 1) eq "\\") 0 0 0
Condition0%0/3
$len > 3 and substr($curDir, $len - 1, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$len > 3 and substr($curDir, $len - 1, 1) eq "\\"
$len > 3 substr($curDir, $len - 1, 1) eq "\\"
Truth table0%0/3
A and B
A= $len > 3B= substr($curDir, $len - 1, 1) eq "\\"
ABresult
0X0
100
111
351 0 substr( $curDir, $len - 1 ) = EOS;
352 }
353 0 $self->{dirInput}{data} = $curDir;
354 0 $self->{dirInput}->drawView();
355 }
356 }
357
358 0 return;
359 5 }; #/ $setUpDialog = sub
360
361 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
362 0 state $sig = signature(
363 method => Object,
364 pos => [Object],
365 );
366 0 my ( $self, $os ) = $sig->( @_ );
367 0 $self->SUPER::write( $os );
368 $os->put(
369 $self->{dirList},
370 $self->{dirInput},
371 $self->{okButton},
372 $self->{chDirButton},
373 0 );
374 0 return;
375 }
376
377 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
378 0 state $sig = signature(
379 method => Object,
380 pos => [Object],
381 );
382 0 my ( $self, $is ) = $sig->( @_ );
383 0 $self->SUPER::read( $is );
384 0 $self->{dirList} = $is->get();
385 0 $self->{dirInput} = $is->get();
386 0 $self->{okButton} = $is->get();
387 0 $self->{chDirButton} = $is->get();
388 0 $self->$setUpDialog();
389 0 return $self;
390 }
391
392 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
393 0 my ( $class ) = @_;
394 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
395 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($class) 0 0 0
396 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
397 0 return $class->new(
398 options => cdNoLoadDir,
399 histId => 0,
400 );
401 }
402
403 5 1
404
405 __END__
« lib/TUI/Dialogs/Dialog.pm ↑ Summary lib/TUI/TextView/Terminal.pm »