lib/TUI/Dialogs/ListBox.pm

filter: Statementstmt 37.3% 43 / 115 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 48.0% 12 / 25 Podpod 69.2% 9 / 13 totaltotal 37.4% 64 / 171 CC 10 SCAR 18.6
CC
10
Cov
32%
build
20.0
BUILD
12.0
getText
12.0
CRAP 6.4
« lib/TUI/Gadgets/Calculator.pm ↑ Summary lib/TUI/Gadgets/CalendarWindow.pm »
1 package TUI::Dialogs::ListBox;
2 # ABSTRACT: Provides a list box dialog with selection handling
3
4 13 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 13 our $VERSION = '2.000003';
9 13 $VERSION =~ tr/_//d;
10 13 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 13 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 13 our @EXPORT = qw(
15 TListBox
16 new_TListBox
17 );
18
19 13 ▶use Class::Struct;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 13 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
23 Maybe
24 is_Object
25 :types
26 13 );
27
28 13 ▶use TUI::Const qw( EOS );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 13 ▶use TUI::Objects::NSCollection;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 13 ▶use TUI::Objects::Rect;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 13 ▶use TUI::Views::ListViewer;
Subroutine BEGIN: called CC=1 SCAR=0.0
32
33 13 struct TListBoxRec => [
34 items => TNSCollection,
35 selection => '$',
36 ];
37
38 sub TListBox() { __PACKAGE__ }
39 sub name() { 'TListBox' }
40 0 ▶sub new_TListBox { __PACKAGE__->from( @_ ) }
Subroutine new_TListBox: not called CC=1 SCAR=6.9
Pod documented
41
42 13 extends TListViewer;
43
44 # protected attributes
45 13 has items => ( is => 'ro' );
46
47 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
48 0 state $sig = signature(
49 method => 1,
50 named => [
51 bounds => Object,
52 numCols => PositiveOrZeroInt, { alias => 'aNumCols' },
53 vScrollBar => Maybe[Object], { alias => 'aScrollBar' },
54 ],
55 caller_level => +1,
56 );
57 0 my ( $class, $args ) = $sig->( @_ );
58 0 return { %$args };
59 }
60
61 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod documented
62 0 my ( $self, $args ) = @_;
63 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
64 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
65 0 $self->setRange( 0 );
66 0 return;
67 }
68
69 0 ▶sub from { # $obj ($bounds, $aNumCols, $aVScrollBar|undef)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
70 0 state $sig = signature(
71 method => 1,
72 pos => [Object, PositiveOrZeroInt, Maybe[Object]],
73 );
74 0 my ( $class, @args ) = $sig->( @_ );
75 0 return $class->new( bounds => $args[0], numCols => $args[1],
76 vScrollBar => $args[2] );
77 }
78
79 0 ▶sub list { # $collection ()
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
80 0 state $sig = signature(
81 method => Object,
82 pos => [],
83 );
84 0 my ( $self ) = $sig->( @_ );
85 0 return $self->{items};
86 }
87
88 0 ▶sub dataSize { # $size ()
Subroutine dataSize: not called CC=1 SCAR=6.9
Pod documented
89 0 state $sig = signature(
90 method => Object,
91 pos => [],
92 );
93 0 $sig->( @_ );
94 0 state $size = @{ TListBoxRec->new() };
95 0 return $size;
96 }
97
98 0 ▶sub getData { # void (\@rec)
Subroutine getData: not called CC=1 SCAR=6.9
Pod documented
99 0 state $sig = signature(
100 method => Object,
101 pos => [ArrayLike],
102 );
103 0 my ( $self, $rec ) = $sig->( @_ );
104 my $p = TListBoxRec->new(
105 items => $self->{items},
106 selection => $self->{focused},
107 0 );
108 0 @$rec[ 0 .. $#$p ] = @$p;
109 0 return;
110 } #/ sub getData
111
112 0 ▶sub getText { # void (\$dest, $item, $maxChars)
Subroutine getText: not called CC=3 SCAR=24.8
Pod documented
113 0 state $sig = signature(
114 method => Object,
115 pos => [ScalarRef, Int, Int],
116 );
117 0 my ( $self, $dest, $item, $maxChars ) = $sig->( @_ );
118 0 ▶ if ( $self->{items} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'items'}) { } 0 0 0
119 0 my $src = $self->{items}->at( $item );
120 0 ▶ $src = '' unless defined $src;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $src 0 0 0
121 0 $$dest = substr( $src, 0, $maxChars );
122 }
123 else {
124 0 $$dest = EOS;
125 }
126 0 return;
127 }
128
129 0 ▶sub newList { # void ($aList)
Subroutine newList: not called CC=3 SCAR=24.8
Pod documented
130 0 state $sig = signature(
131 method => Object,
132 pos => [Object],
133 );
134 0 my ( $self, $aList ) = $sig->( @_ );
135 0 $self->destroy( $self->{items} );
136 0 $self->{items} = $aList;
137 0 ▶ if ( $aList ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aList) { } 0 0 0
138 0 $self->setRange( $aList->getCount() );
139 }
140 else {
141 0 $self->setRange( 0 );
142 }
143 0 ▶ if ( $self->{range} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"range"} > 0) 0 0 0
144 0 $self->focusItem( 0 );
145 }
146 0 $self->drawView();
147 0 return;
148 } #/ sub newList
149
150 0 ▶sub setData { # void (\@rec)
Subroutine setData: not called CC=1 SCAR=6.9
Pod documented
151 0 state $sig = signature(
152 method => Object,
153 pos => [ArrayLike],
154 );
155 0 my ( $self, $rec ) = $sig->( @_ );
156 0 my $p = TListBoxRec->new();
157 0 @$p = @$rec[ 0 .. $#$p ];
158 0 $self->newList( $p->items );
159 0 $self->focusItem( $p->selection );
160 0 $self->drawView();
161 0 return;
162 } #/ sub setData
163
164 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
165 0 state $sig = signature(
166 method => Object,
167 pos => [Object],
168 );
169 0 my ( $self, $os ) = $sig->( @_ );
170 0 $self->SUPER::write( $os );
171 0 $os->put( $self->{items} );
172 0 return;
173 }
174
175 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
176 0 state $sig = signature(
177 method => Object,
178 pos => [Object],
179 );
180 0 my ( $self, $is ) = $sig->( @_ );
181 0 $self->SUPER::read( $is );
182 0 $self->{items} = $is->get();
183 0 return $self;
184 }
185
186 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
187 0 my ( $class ) = @_;
188 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
189 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->is_Str 0 0 0
190 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
191 0 return $class->new(
192 bounds => TRect->new(),
193 numCols => 0,
194 vScrollBar => undef
195 );
196 }
197
198 13 1
199
200 __END__
« lib/TUI/Gadgets/Calculator.pm ↑ Summary lib/TUI/Gadgets/CalendarWindow.pm »