File Coverage

blib/lib/ProgressMonitor/Stringify/Fields/Fixed.pm
Criterion Covered Total %
statement 29 38 76.3
branch n/a
condition 0 2 0.0
subroutine 9 10 90.0
pod 2 2 100.0
total 40 52 76.9


line stmt bran cond sub pod time code
1             package ProgressMonitor::Stringify::Fields::Fixed;
2            
3 5     5   25675 use warnings;
  5         12  
  5         136  
4 5     5   23 use strict;
  5         16  
  5         215  
5            
6             require ProgressMonitor::Stringify::Fields::AbstractField if 0;
7            
8             use classes
9 5         27 extends => 'ProgressMonitor::Stringify::Fields::AbstractField',
10             new => 'new',
11 5     5   23 ;
  5         11  
12            
13             sub new
14             {
15 6     6   1082 my $class = shift;
16 6         14 my $cfg = shift;
17            
18 6         63 my $self = $class->SUPER::_new($cfg, $CLASS);
19            
20 6         38 $cfg = $self->_get_cfg;
21            
22 6         23 $self->_set_width(length($cfg->get_text));
23            
24 6         73 return $self;
25             }
26            
27             sub render
28             {
29 318     318 1 371 my $self = shift;
30             # arguments not used...
31             # my $state = shift;
32             # my $tick = shift;
33             # my $totalTicks = shift;
34             # my $clean = shift;
35            
36 318         1137 return $self->_get_cfg->get_text;
37             }
38            
39             sub change_text
40             {
41 0     0 1 0 my $self = shift;
42 0         0 my $newText = shift;
43 0   0     0 my $filler = shift || ' ';
44            
45 0         0 my $w = $self->get_width;
46 0         0 $newText = substr($newText . ($filler x $w), 0, $w);
47            
48 0         0 my $cfg = $self->_get_cfg;
49 0         0 my $oldText = $cfg->get_text;
50            
51 0         0 $cfg->set_text($newText);
52            
53 0         0 return $oldText;
54             }
55            
56             ###
57            
58             package ProgressMonitor::Stringify::Fields::FixedConfiguration;
59            
60 5     5   1691 use strict;
  5         7  
  5         138  
61 5     5   24 use warnings;
  5         7  
  5         211  
62            
63             # Attributes
64             # text
65             # Set to any text that should be rendered
66             #
67             use classes
68 5         21 extends => 'ProgressMonitor::Stringify::Fields::AbstractFieldConfiguration',
69             attrs => ['text'],
70 5     5   26 ;
  5         9  
71            
72             sub defaultAttributeValues
73             {
74 6     6   11 my $self = shift;
75            
76 6         23 return {%{$self->SUPER::defaultAttributeValues()}, text => ' '};
  6         47  
77             }
78            
79             ############################
80            
81             =head1 NAME
82            
83             ProgressMonitor::Stringify::Field::Fixed - a field implementation that renders a
84             fixed value.
85            
86             =head1 SYNOPSIS
87            
88             # call someTask and give it a monitor to call us back
89             #
90             my $text = ProgressMonitor::Stringify::Fields::Fixed->new({text => 'Percent complete: '});
91             my $pct = ProgressMonitor::Stringify::Fields::Percentage->new;
92             someTask(ProgressMonitor::Stringify::ToStream->new({fields => [ $text, $pct ]});
93            
94             =head1 DESCRIPTION
95            
96             This is a fixed size field rendering a fixed value. Intended for use together with
97             other fields in order to provide explanatory text or similar.
98            
99             Inherits from ProgressMonitor::Stringify::Fields::AbstractField.
100            
101             =head1 METHODS
102            
103             =over 2
104            
105             =item new( $hashRef )
106            
107             Configuration data:
108            
109             =over 2
110            
111             =item text (default => ' ')
112            
113             The text to display.
114            
115             =back
116            
117             =back
118            
119             =over 2
120            
121             =item change_text( $newText, [$filler] )
122            
123             Change the text to display and returns the old text.
124            
125             The filler is optional, and defaults to ' ' (space), and will be used to pad the passed in text to the assigned width of the field if its shorter.
126             If it's too long, it will be cut.
127            
128             =back
129            
130             =head1 AUTHOR
131            
132             Kenneth Olwing, C<< >>
133            
134             =head1 BUGS
135            
136             I wouldn't be surprised! If you can come up with a minimal test that shows the
137             problem I might be able to take a look. Even better, send me a patch.
138            
139             Please report any bugs or feature requests to
140             C, or through the web interface at
141             L.
142             I will be notified, and then you'll automatically be notified of progress on
143             your bug as I make changes.
144            
145             =head1 SUPPORT
146            
147             You can find general documentation for this module with the perldoc command:
148            
149             perldoc ProgressMonitor
150            
151             =head1 ACKNOWLEDGEMENTS
152            
153             Thanks to my family. I'm deeply grateful for you!
154            
155             =head1 COPYRIGHT & LICENSE
156            
157             Copyright 2006,2007 Kenneth Olwing, all rights reserved.
158            
159             This program is free software; you can redistribute it and/or modify it
160             under the same terms as Perl itself.
161            
162             =cut
163            
164             1; # End of ProgressMonitor::Stringify::Fields::Fixed