ProgressMonitor/Stringify/Fields/AbstractField.pm

filter: Statementstmt 100% 39 / 39 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 100% 51 / 51 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« ProgressMonitor/State.pm ↑ Summary
1 package ProgressMonitor::Stringify::Fields::AbstractField;
2
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 # Attributes:
7 # width
8 # The width the field will use at this point. Note that dynamic fields will
9 # adjust this value as they get more width
10 # cfg
11 # The configuration object
12 #
13 use classes
14 10 ▶ new => 'ABSTRACT',
Subroutine BEGIN: called CC=1 SCAR=0.0
15 class_methods => ['_new'],
16 methods => {
17 isDynamic => 'isDynamic',
18 render => 'ABSTRACT',
19 },
20 attrs_ro => ['width',],
21 attrs_pr => ['cfg'],
22 10 ;
23
24 sub isDynamic
25 10 ▶{
Subroutine isDynamic: called CC=1 SCAR=0.0
26 # by default, fields are fixed
27 #
28 10 return 0;
29 }
30
31 ### PROTECTED
32
33 sub _set_width
34 11 ▶{
Subroutine _set_width: called CC=1 SCAR=0.0
35 11 my $self = shift;
36 11 my $w = shift;
37
38 11 $self->{$ATTR_width} = $w;
39
40 11 return;
41 }
42
43 # protected ctor
44 #
45 sub _new
46 11 ▶{
Subroutine _new: called CC=1 SCAR=0.0
47 11 my $self = classes::new_only(shift);
48 11 my $cfg = shift;
49 11 my $cfgPkg = shift;
50
51 # make sure we have a cfg object
52 #
53 11 $self->{$ATTR_cfg} = ProgressMonitor::AbstractConfiguration::ensureCfgObject($cfg, $cfgPkg);
54
55 # initialize the rest
56 #
57 11 $self->{$ATTR_width} = 0;
58
59 11 return $self;
60 }
61
62 sub _get_cfg
63 413 ▶{
Subroutine _get_cfg: called CC=1 SCAR=0.0
64 413 my $self = shift;
65
66 413 return $self->{$ATTR_cfg};
67 }
68
69 ###
70
71 package ProgressMonitor::Stringify::Fields::AbstractFieldConfiguration;
72
73 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
75
76 10 require ProgressMonitor::AbstractConfiguration if 0;
77
78 # declare the configuration class for the above class, this is just a starting
79 # point to derive from as needed
80 #
81 use classes
82 10 ▶ extends => 'ProgressMonitor::AbstractConfiguration',
Subroutine BEGIN: called CC=1 SCAR=0.0
83 10 ;
84
85 sub defaultAttributeValues
86 11 ▶{
Subroutine defaultAttributeValues: called CC=1 SCAR=0.0
87 11 my $self = shift;
88
89 11 return {%{$self->SUPER::defaultAttributeValues()},};
90 }
91
92 sub checkAttributeValues
93 11 ▶{
Subroutine checkAttributeValues: called CC=1 SCAR=0.0
94 11 my $self = shift;
95
96 11 $self->SUPER::checkAttributeValues;
97
98 11 return;
99 }
100
101 ############################
102
103 =head1 NAME
104
105 ProgressMonitor::Stringify::Fields::AbstractField - A reusable/abstract field
106 implementation for stringify progress.
107
108 =head1 SYNOPSIS
109
110 ...
111 use classes
112 extends => 'ProgressMonitor::Stringify::Fields::AbstractField',
113 new => 'new',
114 ...
115 ;
116
117 sub new
118 {
119 my $class = shift;
120 my $cfg = shift;
121
122 my $self = $class->SUPER::_new($cfg, $CLASS);
123
124 ...
125 }
126
127 sub render
128 {
129 my $self = shift;
130
131 ...
132 }
133
134 =head1 DESCRIPTION
135
136 This class is a base class for fields for stringified feedback.
137
138 When extended it provides some accessors for 'protected' data, i.e. only for
139 the use of subclasses. These accessors are prefixed with '_'.
140
141 Subclassing this normally entails only defining the render method.
142
143 =head1 METHODS
144
145 =over 2
146
147 =item render( $ticks, $totalTicks )
148
149 Called with the current tick count, and the total tick count. Should return
150 with an appropriate string corresponding to the tick vs totalTick values.
151
152 This implementation is abstract, must be reimplemented.
153
154 =item isDynamic
155
156 Should return true if the field is dynamic. Automatically handled by inheriting
157 from the AbstractDynamicField.
158
159 =back
160
161 =head1 PROTECTED METHODS
162
163 =over 2
164
165 =item _new( $hashRef, $package )
166
167 The constructor, needs to be called by subclasses.
168
169 Configuration data:
170 (none)
171
172 =item _get_cfg
173
174 Returns the configuration object.
175
176 =item _set_width
177
178 Set the width of the field.
179
180 =back
181
182 =head1 AUTHOR
183
184 Kenneth Olwing, C<< <knth at cpan.org> >>
185
186 =head1 BUGS
187
188 I wouldn't be surprised! If you can come up with a minimal test that shows the
189 problem I might be able to take a look. Even better, send me a patch.
190
191 Please report any bugs or feature requests to
192 C<bug-progressmonitor at rt.cpan.org>, or through the web interface at
193 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ProgressMonitor>.
194 I will be notified, and then you'll automatically be notified of progress on
195 your bug as I make changes.
196
197 =head1 SUPPORT
198
199 You can find general documentation for this module with the perldoc command:
200
201 perldoc ProgressMonitor
202
203 =head1 ACKNOWLEDGEMENTS
204
205 Thanks to my family. I'm deeply grateful for you!
206
207 =head1 COPYRIGHT & LICENSE
208
209 Copyright 2006,2007 Kenneth Olwing, all rights reserved.
210
211 This program is free software; you can redistribute it and/or modify it
212 under the same terms as Perl itself.
213
214 =cut
215
216 10 1; # End of ProgressMonitor::Stringify::Fields::AbstractField
« ProgressMonitor/State.pm ↑ Summary