lib/TUI/StdDlg/DirListBox.pm

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