ProgressMonitor/Stringify/Fields/Fixed.pm

filter: Statementstmt 77.5% 31 / 40 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.0% 9 / 10 Podpod 100% 2 / 2 totaltotal 76.3% 42 / 55 CC 2 SCAR 6.5
CC
2
Cov
74%
change_text
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« ProgressMonitor/Stringify/Fields/Spinner.pm ↑ Summary ProgressMonitor/Null.pm »
1 package ProgressMonitor::Stringify::Fields::Fixed;
2
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 5 require ProgressMonitor::Stringify::Fields::AbstractField if 0;
7
8 use classes
9 5 ▶ extends => 'ProgressMonitor::Stringify::Fields::AbstractField',
Subroutine BEGIN: called CC=1 SCAR=0.0
10 new => 'new',
11 5 ;
12
13 sub new
14 6 ▶{
Subroutine new: called CC=1 SCAR=0.0
15 6 my $class = shift;
16 6 my $cfg = shift;
17
18 6 my $self = $class->SUPER::_new($cfg, $CLASS);
19
20 6 $cfg = $self->_get_cfg;
21
22 6 $self->_set_width(length($cfg->get_text));
23
24 6 return $self;
25 }
26
27 sub render
28 318 ▶{
Subroutine render: called CC=1 SCAR=0.0
Pod documented
29 318 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 return $self->_get_cfg->get_text;
37 }
38
39 sub change_text
40 0 ▶{
Subroutine change_text: not called CC=2 SCAR=17.9
Pod documented
41 0 my $self = shift;
42 0 my $newText = shift;
43 0 ▶ my $filler = shift || ' ';
Condition0%0/2
shift() || ' '
l!l
00
MC/DC0%0/1
shift() || ' '
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
44
45 0 my $w = $self->get_width;
46 0 $newText = substr($newText . ($filler x $w), 0, $w);
47
48 0 my $cfg = $self->_get_cfg;
49 0 my $oldText = $cfg->get_text;
50
51 0 $cfg->set_text($newText);
52
53 0 return $oldText;
54 }
55
56 ###
57
58 package ProgressMonitor::Stringify::Fields::FixedConfiguration;
59
60 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
62
63 # Attributes
64 # text
65 # Set to any text that should be rendered
66 #
67 use classes
68 5 ▶ extends => 'ProgressMonitor::Stringify::Fields::AbstractFieldConfiguration',
Subroutine BEGIN: called CC=1 SCAR=0.0
69 attrs => ['text'],
70 5 ;
71
72 sub defaultAttributeValues
73 6 ▶{
Subroutine defaultAttributeValues: called CC=1 SCAR=0.0
74 6 my $self = shift;
75
76 6 return {%{$self->SUPER::defaultAttributeValues()}, text => ' '};
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<< <knth at cpan.org> >>
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<bug-progressmonitor at rt.cpan.org>, or through the web interface at
141 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ProgressMonitor>.
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 5 1; # End of ProgressMonitor::Stringify::Fields::Fixed
« ProgressMonitor/Stringify/Fields/Spinner.pm ↑ Summary ProgressMonitor/Null.pm »