lib/TUI/Editors/EditWindow.pm

filter: Statementstmt 46.3% 63 / 136 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.0% 18 / 29 Podpod 63.6% 7 / 11 totaltotal 43.7% 88 / 201 CC 14 SCAR 19.9
CC
14
Cov
40%
handleEvent
20.0
build
20.0
BUILD
12.0
CRAP 7.3
« lib/TUI/Help/HelpTopic.pm ↑ Summary lib/TUI/Gadgets/FileWindow.pm »
1 package TUI::Editors::EditWindow;
2 # ABSTRACT: TEditWindow is a window that hosts a file editor.
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 TEditWindow
15 new_TEditWindow
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_Object
24 is_Str
25 :types
26 5 );
27
28 5 ▶use TUI::Drivers::Const qw( :evXXXX );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use TUI::Drivers::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use TUI::Editors::Const qw( :cmXXXX );
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use TUI::Editors::FileEditor;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use TUI::Editors::Indicator;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use TUI::Objects::Point;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use TUI::Views::Const qw( ofTileable );
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use TUI::Views::ScrollBar;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use TUI::Views::Window;
Subroutine BEGIN: called CC=1 SCAR=0.0
38
39 sub TEditWindow() { __PACKAGE__ }
40 sub name() { 'TEditWindow' }
41 0 ▶sub new_TEditWindow { __PACKAGE__->from(@_) }
Subroutine new_TEditWindow: not called CC=1 SCAR=6.9
Pod documented
42
43 5 extends TWindow;
44
45 # declare global variables
46 5 our $clipboardTitle = 'Clipboard';
47 5 our $untitled = 'Untitled';
48
49 # public attributes
50 5 has editor => ( is => 'rw' );
51
52 # declare local variables
53 5 my $minEditWinSize = TPoint->new( x => 24, y => 6 );
54
55 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
56 0 state $sig = signature(
57 method => 1,
58 named => [
59 bounds => Object,
60 fileName => Maybe[Str], { alias => 'aFileName' },
61 number => Int, { alias => 'aNumber' },
62 ],
63 caller_level => +1,
64 );
65 0 my ( $class, $args1 ) = $sig->( @_ );
66 0 local $Carp::CarpLevel = $Carp::CarpLevel + 1;
67 my $args2 = $class->SUPER::BUILDARGS(
68 bounds => $args1->{bounds},
69 title => '',
70 number => $args1->{number},
71 0 );
72 0 return { %$args1, %$args2 };
73 }
74
75 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
76 0 my ( $self, $args ) = @_;
77 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
78 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
79 0 $self->{options} |= ofTileable;
80
81 0 my $size = $self->{size};
82 my $hScrollBar = TScrollBar->new(
83 bounds => TRect->new(
84 ax => 18,
85 ay => $size->{y} - 1,
86 bx => $size->{x} - 2,
87 by => $size->{y},
88 0 ),
89 );
90 0 $hScrollBar->hide();
91 0 $self->insert( $hScrollBar );
92
93 my $vScrollBar = TScrollBar->new(
94 bounds => TRect->new(
95 ax => $size->{x} - 1,
96 ay => 1,
97 bx => $size->{x},
98 0 by => $size->{y} - 1,
99 ),
100 );
101 0 $vScrollBar->hide();
102 0 $self->insert( $vScrollBar );
103
104 my $indicator = TIndicator->new(
105 bounds => TRect->new(
106 ax => 2,
107 ay => $size->{y} - 1,
108 bx => 16,
109 by => $size->{y},
110 0 ),
111 );
112 0 $indicator->hide();
113 0 $self->insert( $indicator );
114
115 0 my $r = $self->getExtent();
116 0 $r->grow( -1, -1 );
117 $self->{editor} = TFileEditor->new(
118 bounds => $r,
119 hScrollBar => $hScrollBar,
120 vScrollBar => $vScrollBar,
121 indicator => $indicator,
122 fileName => $args->{fileName},
123 0 );
124 0 $self->insert( $self->{editor} );
125 0 return;
126 }
127
128 0 ▶sub from { # $obj ($bounds, $aFileName|undef, $aNumber)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
129 0 state $sig = signature(
130 method => 1,
131 pos => [Object, Maybe[Str], Int],
132 );
133 0 my ( $class, @args ) = $sig->( @_ );
134 0 return $class->new( bounds => $args[0], fileName => $args[1],
135 number => $args[2] );
136 }
137
138 0 ▶sub close { # void ()
Subroutine close: not called CC=2 SCAR=17.9
Pod documented
139 0 state $sig = signature(
140 method => Object,
141 pos => [],
142 );
143 0 my ( $self ) = $sig->( @_ );
144 0 ▶ if ( $self->{editor}->isClipboard() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'editor'}->isClipboard) { } 0 0 0
145 0 $self->hide();
146 }
147 else {
148 0 $self->SUPER::close();
149 }
150 0 return;
151 }
152
153 0 ▶sub getTitle { # $str ($maxSize)
Subroutine getTitle: not called CC=3 SCAR=24.8
Pod documented
154 0 state $sig = signature(
155 method => Object,
156 pos => [Int],
157 );
158 0 my ( $self, $maxSize ) = $sig->( @_ );
159 return $clipboardTitle
160 0 ▶ if $self->{editor}->isClipboard();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"editor"}->isClipboard 0 0 0
161 0 my $fileName = $self->{editor}{fileName};
162 0 ▶ return length $fileName ? $fileName : $untitled;
Branch: 1 branch
BranchTrueFalseTotal
length $fileName ? : 0 0 0
163 }
164
165 0 ▶sub handleEvent { # void ($event)
Subroutine handleEvent: not called CC=4 SCAR=30.0
Pod documented
166 0 state $sig = signature(
167 method => Object,
168 pos => [Object],
169 );
170 0 my ( $self, $event ) = $sig->( @_ );
171 0 $self->SUPER::handleEvent( $event );
172 0 ▶ if ( $event->{what} == evBroadcast
Branch: 1 branch
BranchTrueFalseTotal
if ($event->{"what"} == 512 and $event->{"message"}{"command"} == 523) 0 0 0
Condition0%0/3
$event->{"what"} == 512 and $event->{"message"}{"command"} == 523
!ll&&!rl&&r
000
MC/DC0%0/2
$event->{"what"} == 512 and $event->{"message"}{"command"} == 523
$event->{"what"} == 512 $event->{"message"}{"command"} == 523
Truth table0%0/3
A and B
A= $event->{"what"} == 512B= $event->{"message"}{"command"} == 523
ABresult
0X0
100
111
173 && $event->{message}{command} == cmUpdateTitle
174 ) {
175 0 ▶ $self->{frame}->drawView() if $self->{frame};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"frame"} 0 0 0
176 0 $self->clearEvent( $event );
177 }
178 0 return;
179 }
180
181 0 ▶sub sizeLimits { # void ($min, $max)
Subroutine sizeLimits: not called CC=3 SCAR=24.8
Pod documented
182 0 state $sig = signature(
183 method => Object,
184 pos => [Object, Object],
185 );
186 0 my ( $self, $min, $max ) = $sig->( @_ );
187 0 alias: for $min ( $_[1] ) {
188 0 alias: for $max ( $_[2] ) {
189 0 $self->SUPER::sizeLimits( $min, $max );
190 0 $min = $minEditWinSize->clone();
191 0 return;
192 }} #/ alias:
193 }
194
195 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
196 0 state $sig = signature(
197 method => Object,
198 pos => [Object],
199 );
200 0 my ( $self, $os ) = $sig->( @_ );
201 0 $self->SUPER::write( $os );
202 0 $os->put( $self->{editor} );
203 0 return;
204 }
205
206 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
207 0 state $sig = signature(
208 method => Object,
209 pos => [Object],
210 );
211 0 my ( $self, $is ) = $sig->( @_ );
212 0 $self->SUPER::read( $is );
213 0 $self->{editor} = $is->get();
214 0 return $self;
215 }
216
217 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
218 0 my ( $class ) = @_;
219 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
220 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($class) 0 0 0
221 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
222 0 return $class->new(
223 bounds => TRect->new(),
224 fileName => '',
225 number => 0,
226 );
227 }
228
229 5 1
230
231 __END__
« lib/TUI/Help/HelpTopic.pm ↑ Summary lib/TUI/Gadgets/FileWindow.pm »