lib/TUI/Gadgets/FileViewer.pm

filter: Statementstmt 43.3% 62 / 143 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 62.0% 18 / 29 Podpod 90.0% 9 / 10 totaltotal 39.2% 89 / 227 CC 18 SCAR 26.1
CC
18
Cov
34%
draw
42.0
readFile
30.0
BUILD
20.0
CRAP 13.6
« lib/TUI/Drivers/Util.pm ↑ Summary lib/TUI/ColorSel/ColorItemList.pm »
1 package TUI::Gadgets::FileViewer;
2 # ABSTRACT: File viewer gadget for TUI::Vision applications
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.000002';
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 TFileViewer
15 new_TFileViewer
16 );
17
18 5 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use List::Util qw( max );
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 :is
25 :types
26 5 );
27
28 5 ▶use TUI::Const qw( EOS );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use TUI::Gadgets::Const qw( maxLineLength );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use TUI::Gadgets::LineCollection;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use TUI::Memory qw( lowMemory );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use TUI::MsgBox::Const qw( :mfXXXX );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use TUI::MsgBox::MsgBoxText qw( messageBox );
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use TUI::Views::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
35 gfGrowHiX
36 gfGrowHiY
37 sfExposed
38 5 );
39 5 ▶use TUI::Views::DrawBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 5 ▶use TUI::Views::Scroller;
Subroutine BEGIN: called CC=1 SCAR=0.0
41
42 sub TFileViewer() { __PACKAGE__ }
43 sub name() { 'TFileViewer' }
44 0 ▶sub new_TFileViewer { __PACKAGE__->from(@_) }
Subroutine new_TFileViewer: not called CC=1 SCAR=6.9
Pod documented
45
46 5 extends TScroller;
47
48 # public attributes
49 0 ▶has fileName => ( is => 'rw', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
50 5 has fileLines => ( is => 'rw' );
51 5 has isValid => ( is => 'rw', default => !!0 );
52
53 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
54 0 state $sig = signature(
55 method => 1,
56 named => [
57 bounds => Object,
58 hScrollBar => Maybe[Object], { alias => 'aHScrollBar' },
59 vScrollBar => Maybe[Object], { alias => 'aVScrollBar' },
60 fileName => Str, { alias => 'aFileName' },
61 ],
62 caller_level => +1,
63 );
64 0 my ( $class, $args1 ) = $sig->( @_ );
65 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
66 my $args2 = $class->SUPER::BUILDARGS(
67 bounds => $args1->{bounds},
68 hScrollBar => $args1->{hScrollBar},
69 vScrollBar => $args1->{vScrollBar},
70 0 );
71 0 return { %$args1, %$args2 };
72 }
73
74 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=4 SCAR=30.0
Pod documented
75 0 my ( $self, $args ) = @_;
76 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
77 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
78 0 ▶ assert ( is_HashRef $args );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_HashRef($args) 0 0 0
79 0 $self->{growMode} |= gfGrowHiX | gfGrowHiY;
80 0 $self->{isValid} = true;
81 0 $self->{fileName} = '';
82 0 $self->readFile( $args->{fileName} );
83 0 return;
84 }
85
86 0 ▶sub from { # $fileView ($bounds, $aHScrollBar|undef, $aVScrollBar|undef, $aFileName)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
87 0 state $sig = signature(
88 method => 1,
89 pos => [Object, Maybe[Object], Maybe[Object], Str],
90 );
91 0 my ( $class, @args ) = $sig->( @_ );
92 0 return $class->new( bounds => $args[0], hScrollBar => $args[1],
93 vScrollBar => $args[2], fileName => $args[3] );
94 }
95
96 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=4 SCAR=30.0
Pod documented
97 0 my ( $self, $in_global_destruction ) = @_;
98 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
99 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
100 0 ▶ assert ( is_Bool $in_global_destruction );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Bool($in_global_destruction) 0 0 0
101 0 undef $self->{fileName};
102 0 $self->destroy( $self->{fileLines} );
103 0 return;
104 }
105
106 0 ▶sub draw { # void ()
Subroutine draw: not called CC=6 SCAR=37.4
Pod documented
107 0 state $sig = signature(
108 method => Object,
109 pos => [],
110 );
111 0 my ( $self ) = $sig->( @_ );
112 0 my $p;
113
114 0 my $c = $self->getColor( 0x0301 );
115 0 ▶ for ( my $i = 0 ; $i < $self->{size}{y} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"size"}{"y"}) 0 0 0
116 0 my $b = TDrawBuffer->new();
117 0 $b->moveChar( 0, ' ', $c, $self->{size}{x} );
118 0 ▶ if ( $self->{delta}{y} + $i < $self->{fileLines}->getCount() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"delta"}{"y"} + $i < $self->{"fileLines"}->getCount) 0 0 0
119 0 my $s;
120 0 $p = $self->{fileLines}->at( $self->{delta}{y} + $i );
121 0 ▶ if ( !$p || length( $p ) < $self->{delta}{x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $p or length $p < $self->{'delta'}{'x'}) { } 0 0 0
Condition0%0/3
not $p or length $p < $self->{"delta"}{"x"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $p or length $p < $self->{"delta"}{"x"}
not $p length $p < $self->{"delta"}{"x"}
Truth table0%0/3
not(A) or B
A= not $pB= length $p < $self->{"delta"}{"x"}
ABresult
1X1
011
000
122 0 $s = EOS;
123 }
124 else {
125 0 $s = substr( $p, $self->{delta}{x}, $self->{size}{x} );
126 0 ▶ if ( length( substr( $p, $self->{delta}{x} ) ) > $self->{size}{x} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length substr($p, $self->{"delta"}{"x"}) > $self->{"size"}{"x"}) 0 0 0
127 0 substr( $s, 0, $self->{size}{x} ) = EOS;
128 }
129 }
130 0 $b->moveStr( 0, substr( $s, 0, maxLineLength ), $c );
131 }
132 0 $self->writeBuf( 0, $i, $self->{size}{x}, 1, $b );
133 }
134 0 return;
135 }
136
137 0 ▶sub readFile { # void ($fName)
Subroutine readFile: not called CC=5 SCAR=34.0
Pod documented
138 0 state $sig = signature(
139 method => 1,
140 pos => [Str],
141 );
142 0 my ( $self, $fName ) = $sig->( @_ );
143 0 $self->{limit}{x} = 0;
144 0 $self->{fileName} = $fName;
145 0 $self->{fileLines} = TLineCollection->new( limit => 5, delta => 5 );
146 0 my $fileToView = IO::File->new( $fName, 'r' );
147 0 ▶ if ( !defined $fileToView ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fileToView) { } 0 0 0
148 0 messageBox( "Invalid drive or directory", mfError | mfOKButton );
149 0 $self->{isValid} = false;
150 }
151 else {
152 0 my $line;
153 0 ▶ while ( !lowMemory()
Branch: 1 branch
BranchTrueFalseTotal
if (not &lowMemory() || $fileToView->eof and defined($line = $fileToView->getline)) 0 0 0
Condition0%0/6
not &lowMemory() || $fileToView->eof and defined($line = $fileToView->getline)
!ll&&!rl&&r
000
&lowMemory() || $fileToView->eof
l!l&&r!l&&!r
000
MC/DC0%0/3
not &lowMemory() || $fileToView->eof and defined($line = $fileToView->getline)
&lowMemory() $fileToView->eof defined($line = $fileToView->getline)
Truth table0%0/4
not(A || B) and C
A= &lowMemory()B= $fileToView->eofC= defined($line = $fileToView->getline)
ABCresult
1XX0
01X0
0000
0011
154 && !$fileToView->eof()
155 && defined( $line = $fileToView->getline() )
156 ) {
157 0 $line =~ s/\r?\n$//; # truncate trailing newline
158 0 $self->{limit}{x} = max( $self->{limit}{x}, length( $line ) );
159 0 $self->{fileLines}->insert( $line );
160 }
161 0 $self->{isValid} = true;
162 }
163 0 $self->{limit}{y} = $self->{fileLines}->getCount();
164 0 return;
165 }
166
167 0 ▶sub setState { # void ($aState, $enable)
Subroutine setState: not called CC=3 SCAR=24.8
Pod documented
168 0 state $sig = signature(
169 method => Object,
170 pos => [PositiveOrZeroInt, Bool],
171 );
172 0 my ( $self, $aState, $enable ) = $sig->( @_ );
173 0 $self->SUPER::setState( $aState, $enable );
174 0 ▶ if ( $enable && ( $aState & sfExposed ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enable and $aState & 2048) 0 0 0
Condition0%0/3
$enable and $aState & 2048
!ll&&!rl&&r
000
MC/DC0%0/2
$enable and $aState & 2048
$enable $aState & 2048
Truth table0%0/3
A and B
A= $enableB= $aState & 2048
ABresult
0X0
100
111
175 0 $self->setLimit( $self->{limit}{x}, $self->{limit}{y} );
176 }
177 0 return;
178 }
179
180 0 ▶sub scrollDraw { # void ()
Subroutine scrollDraw: not called CC=1 SCAR=6.9
Pod documented
181 0 state $sig = signature(
182 method => Object,
183 pos => [],
184 );
185 0 my ( $self ) = $sig->( @_ );
186 0 $self->SUPER::scrollDraw();
187 0 $self->draw();
188 0 return;
189 }
190
191 0 ▶sub valid { # $bool ($command)
Subroutine valid: not called CC=1 SCAR=6.9
Pod documented
192 0 state $sig = signature(
193 method => Object,
194 pos => [PositiveOrZeroInt],
195 );
196 0 my ( $self, undef ) = $sig->( @_ );
197 return $self->{isValid}
198 0 }
199
200 5 1
201
202 __END__
« lib/TUI/Drivers/Util.pm ↑ Summary lib/TUI/ColorSel/ColorItemList.pm »