lib/TUI/StdDlg/DirListBox.pm

filter: Statementstmt 37.4% 79 / 211 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.7% 21 / 34 Podpod 81.8% 9 / 11 totaltotal 34.0% 109 / 320 CC 33 SCAR 42.5
CC
33
Cov
29%
__ANON__
210.0
__ANON__
132.0
DEMOLISH
20.0
CRAP 70.0
« lib/TUI/Gadgets/CalendarView.pm ↑ Summary lib/TUI/Menus/StatusLine.pm »
1 package TUI::StdDlg::DirListBox;
2 # ABSTRACT: TListBox subclass providing directory listing for TChDirDialog
3
4 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 6 our $VERSION = '2.000003';
10 6 $VERSION =~ tr/_//d;
11 6 our $AUTHORITY = 'cpan:BRICKPOOL';
12
13 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 6 our @EXPORT = qw(
16 TDirListBox
17 new_TDirListBox
18 );
19
20 6 ▶use Encode qw( encode );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 Maybe
25 :types
26 6 );
27
28 6 ▶use TUI::Const qw( EOS );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use TUI::Drivers::Const qw( evBroadcast );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use TUI::Dialogs::ListBox;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 6 ▶use TUI::StdDlg::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 cmChangeDir
34 FA_DIREC
35 6 );
36 6 ▶use TUI::StdDlg::Dos;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 6 ▶use TUI::StdDlg::Dir qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
38 findfirst
39 findnext
40 getdisk
41 6 );
42 6 ▶use TUI::StdDlg::DirEntry;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 6 ▶use TUI::StdDlg::DirCollection;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 6 ▶use TUI::StdDlg::Util qw( driveValid );
Subroutine BEGIN: called CC=1 SCAR=0.0
45 6 ▶use TUI::Views::Const qw( sfFocused );
Subroutine BEGIN: called CC=1 SCAR=0.0
46 6 ▶use TUI::Views::Util qw( message );
Subroutine BEGIN: called CC=1 SCAR=0.0
47
48 sub TDirListBox() { __PACKAGE__ }
49 sub name() { 'TDirListBox' }
50 0 ▶sub new_TDirListBox { __PACKAGE__->from( @_ ) }
Subroutine new_TDirListBox: not called CC=1 SCAR=6.9
Pod documented
51
52 6 extends TListBox;
53
54 # declare global variables
55 6 our $pathDir = encode( cp437 => "└─┬" );
56 6 our $firstDir = encode( cp437 => "└┬─" );
57 6 our $middleDir = encode( cp437 => " ├─" );
58 6 our $lastDir = encode( cp437 => " └─" );
59 6 our $drives = "Drives";
60 6 our $graphics = encode( cp437 => "└├─" );
61
62 # private attributes
63 6 has dir => ( is => 'bare', default => EOS );
64 6 has cur => ( is => 'bare', default => 0 );
65
66 # private methods
67 my (
68 6 $showDrives,
69 $showDirs,
70 );
71
72 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
73 0 state $sig = signature(
74 method => 1,
75 named => [
76 bounds => Object,
77 vScrollBar => Maybe[Object], { alias => 'aScrollBar' },
78 ],
79 caller_level => +1,
80 );
81 0 my ( $class, $args ) = $sig->( @_ );
82 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
83 return $class->SUPER::BUILDARGS(
84 bounds => $args->{bounds},
85 numCols => 1,
86 vScrollBar => $args->{vScrollBar},
87 0 );
88 }
89
90 0 ▶sub from { # $obj ($bounds, $aVScrollBar|undef)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
91 0 state $sig = signature(
92 method => 1,
93 pos => [Object, Maybe[Object]],
94 );
95 0 my ( $class, @args ) = $sig->( @_ );
96 0 return $class->new( bounds => $args[0], vScrollBar => $args[2] );
97 }
98
99 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=4 SCAR=30.0
Pod documented
100 0 my ( $self, $in_global_destruction ) = @_;
101 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
102 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_Object 0 0 0
103 0 alias: for my $list ( $self->{items} ) {
104 0 $self->destroy( $list );
105 0 return;
106 } #/ alias:
107 }
108
109 0 ▶sub getText { # void (\$text, $item, $maxChars)
Subroutine getText: not called CC=2 SCAR=17.9
Pod documented
110 0 state $sig = signature(
111 method => Object,
112 pos => [ScalarRef, Int, Int],
113 );
114 0 my ( $self, $text, $item, $maxChars ) = $sig->( @_ );
115 0 $$text = $self->list()->at( $item )->text();
116 0 ▶ substr( $$text, $maxChars ) = EOS if length $$text > $maxChars;
Branch: 1 branch
BranchTrueFalseTotal
if length $$text > $maxChars 0 0 0
117 0 return;
118 }
119
120 0 ▶sub isSelected { # $bool ($item)
Subroutine isSelected: not called CC=1 SCAR=6.9
Pod documented
121 0 state $sig = signature(
122 method => Object,
123 pos => [PositiveOrZeroInt],
124 );
125 0 my ( $self, $item ) = $sig->( @_ );
126 0 return $item == $self->{cur};
127 }
128
129 0 ▶sub selectItem { # void ($item)
Subroutine selectItem: not called CC=1 SCAR=6.9
Pod documented
130 0 state $sig = signature(
131 method => Object,
132 pos => [PositiveOrZeroInt],
133 );
134 0 my ( $self, $item ) = $sig->( @_ );
135 0 message( $self->{owner}, evBroadcast, cmChangeDir,
136 $self->list()->at( $item ) );
137 0 return;
138 }
139
140 0 ▶sub newDirectory { # void ($str)
Subroutine newDirectory: not called CC=2 SCAR=17.9
Pod documented
141 0 state $sig = signature(
142 method => Object,
143 pos => [Str],
144 );
145 0 my ( $self, $str ) = $sig->( @_ );
146 0 $self->{dir} = $str;
147 0 my $dirs = TDirCollection->new( limit => 5, delta => 5 );
148 0 $dirs->insert( TDirEntry->new(
149 displayText => $drives, directory => $drives )
150 );
151 0 ▶ if ( $self->{dir} eq $drives ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dir'} eq $TUI::StdDlg::DirListBox::drives) { } 0 0 0
152 0 $self->$showDrives( $dirs );
153 }
154 else {
155 0 $self->$showDirs( $dirs );
156 }
157 0 $self->newList( $dirs );
158 0 $self->focusItem( $self->{cur} );
159 0 return;
160 }
161
162 0 ▶sub setState { # void ($aState, $enable)
Subroutine setState: not called CC=2 SCAR=17.9
Pod documented
163 0 state $sig = signature(
164 method => Object,
165 pos => [PositiveOrZeroInt, Bool],
166 );
167 0 my ( $self, $aState, $enable ) = $sig->( @_ );
168
169 0 $self->SUPER::setState( $aState, $enable );
170 0 ▶ if ( $aState & sfFocused ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aState & 64) 0 0 0
171 message( $self->{owner}, evBroadcast, cmChangeDir,
172 0 $self->list()->at( $self->{cur} ) );
173 }
174 0 return;
175 }
176
177 0 ▶sub list { # $dirCollection ()
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
178 0 goto &TUI::Dialogs::ListBox::list;
179 }
180
181 0 ▶$showDrives = sub { # void ($dirs)
Subroutine __ANON__: not called CC=11 SCAR=48.8
182 0 my ( $self, $dirs ) = @_;
183 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
184 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_Object 0 0 0
185 0 ▶ assert ( is_Object $dirs );
Branch: 1 branch
BranchTrueFalseTotal
unless $dirs->is_Object 0 0 0
186
187 0 my $isFirst = true;
188 0 my $oldc = "0:\\";
189 0 for my $c ( 'A' .. 'Z' ) {
190 0 ▶ if ( $c lt 'C' || driveValid( $c ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c lt "C" or driveValid($c)) 0 0 0
Condition0%0/3
$c lt "C" or driveValid($c)
l!l&&r!l&&!r
000
MC/DC0%0/2
$c lt "C" or driveValid($c)
$c lt "C" driveValid($c)
Truth table0%0/3
A or B
A= $c lt "C"B= driveValid($c)
ABresult
1X1
011
000
191 0 ▶ if ( substr( $oldc, 0, 1 ) ne '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($oldc, 0, 1) ne 0) 0 0 0
192 0 my $s;
193 0 ▶ if ( $isFirst ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isFirst) { } 0 0 0
194 0 $s = $firstDir . substr( $oldc, 0, 1 );
195 0 $isFirst = false;
196 }
197 else {
198 0 $s = $middleDir . substr( $oldc, 0, 1 );
199 }
200 0 $dirs->insert(
201 TDirEntry->new( displayText => $s, directory => $oldc )
202 );
203 }
204 0 ▶ if ( ord( $c ) == getdisk() + ord( 'A' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $c == getdisk() + 65) 0 0 0
205 0 $self->{cur} = $dirs->getCount();
206 }
207 0 substr( $oldc, 0, 1 ) = $c;
208 } #/ if ( $c lt 'C' || driveValid...)
209 } #/ for my $c ( 'A' .. 'Z' )
210
211 0 ▶ if ( substr( $oldc, 0, 1 ) ne '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($oldc, 0, 1) ne 0) 0 0 0
212 0 my $s = $lastDir . substr( $oldc, 0, 1 );
213 0 $dirs->insert( TDirEntry->new( displayText => $s, directory => $oldc ) );
214 }
215 0 return;
216 6 };
217
218 0 ▶$showDirs = sub { # void ($dirs)
Subroutine __ANON__: not called CC=14 SCAR=53.5
219 0 my ( $self, $dirs ) = @_;
220 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
221 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_Object 0 0 0
222 0 ▶ assert ( is_Object $dirs );
Branch: 1 branch
BranchTrueFalseTotal
unless $dirs->is_Object 0 0 0
223
224 0 state $indentSize = 2;
225 0 my $indent = $indentSize;
226
227 0 my $org = $pathDir;
228 0 my $curDir = $self->{dir};
229
230 # Show root directory.
231 0 my $pos = index( $curDir, '\\' );
232 0 ▶ return if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
233 0 my $root = substr( $curDir, 0, $pos + 1 );
234 0 $dirs->insert( TDirEntry->new(
235 displayText => $org . $root,
236 directory => $root,
237 ));
238 0 $curDir = substr( $curDir, $pos + 1 );
239
240 # Show directories up to the current one.
241 0 my $partial = $root;
242 0 ▶ while ( ( my $pos = index( $curDir, '\\' ) ) != -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $pos = index($curDir, "\\")) != -1) 0 0 0
243 0 my $name = substr( $curDir, 0, $pos );
244 0 my $entryDir = $partial . $name;
245 0 $dirs->insert( TDirEntry->new(
246 displayText => ( ' ' x $indent ) . $org . $name,
247 directory => $entryDir,
248 ));
249 0 $partial .= $name . '\\';
250 0 $curDir = substr( $curDir, $pos + 1 );
251 0 $indent += $indentSize;
252 }
253
254 0 $self->{cur} = $dirs->getCount() - 1;
255
256 # Show subdirectories.
257 0 my $basePath = $self->{dir};
258 0 ▶ if ( substr( $basePath, -1, 1 ) ne '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($basePath, -1, 1) ne "\\") 0 0 0
259 0 $basePath =~ s/\\[^\\]*$//;
260 0 $basePath .= '\\';
261 }
262 0 my $path = $basePath . '*.*';
263
264 0 my $isFirst = true;
265 0 my $ff = ffblk->new();
266 0 my $res = findfirst( $path, $ff, FA_DIREC );
267 0 ▶ while ( $res == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 0) 0 0 0
268 0 ▶ if ( ( $ff->ff_attrib() & FA_DIREC )
Branch: 1 branch
BranchTrueFalseTotal
if ($ff->ff_attrib & 16 and substr($ff->ff_name, 0, 1) ne ".") 0 0 0
Condition0%0/3
$ff->ff_attrib & 16 and substr($ff->ff_name, 0, 1) ne "."
!ll&&!rl&&r
000
MC/DC0%0/2
$ff->ff_attrib & 16 and substr($ff->ff_name, 0, 1) ne "."
$ff->ff_attrib & 16 substr($ff->ff_name, 0, 1) ne "."
Truth table0%0/3
A and B
A= $ff->ff_attrib & 16B= substr($ff->ff_name, 0, 1) ne "."
ABresult
0X0
100
111
269 && substr( $ff->ff_name, 0, 1 ) ne '.' )
270 {
271 0 ▶ if ( $isFirst ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isFirst) { } 0 0 0
272 0 $org = $firstDir;
273 0 $isFirst = false;
274 }
275 else {
276 0 $org = $middleDir;
277 }
278 0 my $name = $ff->ff_name;
279 0 $path = $basePath . $name;
280 0 $dirs->insert( TDirEntry->new(
281 displayText => ( ' ' x $indent ) . $org . $name,
282 directory => $path,
283 ));
284 }
285 0 $res = findnext( $ff );
286 } #/ while ( $res == 0 )
287
288 0 alias: for my $p ( $dirs->at( $dirs->getCount() - 1 )->{displayText} ) {
289 0 my @graphics = split //, $graphics;
290 0 my $i = index( $p, $graphics[0] );
291 0 ▶ if ( $i < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 0) { } 0 0 0
292 0 $i = index( $p, $graphics[1] );
293 0 ▶ if ( $i >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 0 0 0
294 0 substr( $p, $i, 1 ) = $graphics[0];
295 }
296 }
297 else {
298 0 substr( $p, $i + 1, 1 ) = $graphics[2];
299 0 substr( $p, $i + 2, 1 ) = $graphics[2];
300 }
301 0 return;
302 } #/ alias:
303 6 };
304
305 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
306 0 my ( $class ) = @_;
307 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
308 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->is_Str 0 0 0
309 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
310 0 return $class->new(
311 bounds => TRect->new(),
312 vScrollBar => undef
313 );
314 }
315
316 6 1
317
318 __END__
« lib/TUI/Gadgets/CalendarView.pm ↑ Summary lib/TUI/Menus/StatusLine.pm »