« ProgressMonitor/AbstractConfiguration.pm
↑ Summary
ProgressMonitor/Stringify/Fields/Percentage.pm »
| 1 | package ProgressMonitor::Stringify::Fields::AbstractDynamicField; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | require ProgressMonitor::Stringify::Fields::AbstractField if 0; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | use classes | ||||||||||||||||||||||||||||
| 9 | 2 | ▶ | extends => 'ProgressMonitor::Stringify::Fields::AbstractField', | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | methods => {grabExtraWidth => 'grabExtraWidth', widthChange => 'ABSTRACT'}, | ||||||||||||||||||||||||||||
| 11 | 2 | ; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub isDynamic | ||||||||||||||||||||||||||||
| 14 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
isDynamic: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # we're only dynamic if the stated maxWidth is greater than our current width | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | 1 | return $self->get_width < $self->_get_cfg->get_maxWidth; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub grabExtraWidth | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
grabExtraWidth: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | 0 | my $extraWidth = shift; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $cfg = $self->_get_cfg; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # take as much width we can from the given one, but respect the max | ||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||
| 31 | 0 | my $width = $self->get_width; | |||||||||||||||||||||||||||
| 32 | 0 | my $maxWidth = $cfg->get_maxWidth; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | while ($extraWidth && $width < $maxWidth) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$extraWidth and $width < $maxWidth
MC/DC0%0/2
$extraWidth and $width < $maxWidth
$extraWidth
$width < $maxWidth
Truth table0%0/3
A and B
A= $extraWidthB= $width < $maxWidth
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 0 | $width++; | |||||||||||||||||||||||||||
| 36 | 0 | $extraWidth--; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | $self->_set_width($width); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | return $extraWidth; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ### PROTECTED | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # override the width setter, and notify that the width has been changed | ||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||
| 48 | sub _set_width | ||||||||||||||||||||||||||||
| 49 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_set_width: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | $self->SUPER::_set_width(@_); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | $self->widthChange; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | ### | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | package ProgressMonitor::Stringify::Fields::AbstractDynamicFieldConfiguration; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # Attributes: | ||||||||||||||||||||||||||||
| 67 | # minWidth | ||||||||||||||||||||||||||||
| 68 | # The minimum width the field should use. This may however be too small | ||||||||||||||||||||||||||||
| 69 | # for the fields 'minimum computed width' which can depend on many other | ||||||||||||||||||||||||||||
| 70 | # settings and thus this value is raised as needed. | ||||||||||||||||||||||||||||
| 71 | # maxWidth | ||||||||||||||||||||||||||||
| 72 | # The maximum width the field should use, regardless if it is given more. | ||||||||||||||||||||||||||||
| 73 | # Defaults to a very large value | ||||||||||||||||||||||||||||
| 74 | # | ||||||||||||||||||||||||||||
| 75 | use classes | ||||||||||||||||||||||||||||
| 76 | 2 | ▶ | extends => 'ProgressMonitor::Stringify::Fields::AbstractFieldConfiguration', | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | attrs => ['minWidth', 'maxWidth',], | ||||||||||||||||||||||||||||
| 78 | 2 | ; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub defaultAttributeValues | ||||||||||||||||||||||||||||
| 81 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
defaultAttributeValues: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | return { | ||||||||||||||||||||||||||||
| 85 | 1 | %{$self->SUPER::defaultAttributeValues()}, | |||||||||||||||||||||||||||
| 86 | minWidth => 0, | ||||||||||||||||||||||||||||
| 87 | maxWidth => 1 << 31, | ||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub checkAttributeValues | ||||||||||||||||||||||||||||
| 92 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
checkAttributeValues: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 93 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | $self->SUPER::checkAttributeValues; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | my $minWidth = $self->get_minWidth; | |||||||||||||||||||||||||||
| 98 | 1 | ▶ | X::Usage->throw("minWidth must be positive") if $minWidth < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 1 | ▶ | X::Usage->throw("maxWidth must be greater or equal to minWidth") if $self->get_maxWidth < $minWidth; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | return; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | ############################ | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 NAME | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | ProgressMonitor::Stringify::Fields::AbstractDynamicField - A reusable/abstract | ||||||||||||||||||||||||||||
| 109 | dynamic field implementation for stringify progress. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Inherits from ProgressMonitor::Stringify::Fields::AbstractField. See that for more | ||||||||||||||||||||||||||||
| 114 | information; this class signals participation in the dynamic width negotiation | ||||||||||||||||||||||||||||
| 115 | protocol as utilized by ProgressMonitor::Stringify::AbstractMonitor and subclasses. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Inherit from this class if you wish to dynamically adjust your field width to grab | ||||||||||||||||||||||||||||
| 118 | as much as possible. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =head1 METHODS | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =over 2 | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item grabExtraWidth( $extraWidth ) | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | Called with extra width available. Consume all or part of this by updating the | ||||||||||||||||||||||||||||
| 127 | inherited width attribute and return the width not used. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | This method may be called multiple times in order to fairly distribute extra width | ||||||||||||||||||||||||||||
| 130 | across several dynamic fields | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =item isDynamic | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Returns true as long as the current width is less than maxWidth. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item widthChange | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Notification that the width has changed, thus giving the field a chance to recompute | ||||||||||||||||||||||||||||
| 139 | some of its attributes as needed. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =back | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head1 PROTECTED METHODS | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =over 2 | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item _new( $hashRef, $package ) | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | The constructor, needs to be called by subclasses. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | Configuration data: | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =over 2 | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item minWidth (default => 0) | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | The minimum width this field should use. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item maxWidth | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | The maximum width this field should use. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =back | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =item _set_width( $newWidth ) | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | Calls SUPER and then widthChange. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =back | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Kenneth Olwing, C<< <knth at cpan.org> >> | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 BUGS | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | I wouldn't be surprised! If you can come up with a minimal test that shows the | ||||||||||||||||||||||||||||
| 178 | problem I might be able to take a look. Even better, send me a patch. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 181 | C<bug-progressmonitor at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 182 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ProgressMonitor>. | ||||||||||||||||||||||||||||
| 183 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 184 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | You can find general documentation for this module with the perldoc command: | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | perldoc ProgressMonitor | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | Thanks to my family. I'm deeply grateful for you! | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | Copyright 2006,2007 Kenneth Olwing, all rights reserved. | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 201 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =cut | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 2 | 1; # End of ProgressMonitor::Stringify::Fields::AbstractDynamicField | |||||||||||||||||||||||||||