| 1 | package ProgressMonitor::Stringify::Fields::Spinner; | ||||||||||
| 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 | # Attributes: | ||||||||||
| 9 | # index | ||||||||||
| 10 | # Keeps track of which part of the spinner should be rendered this iteration | ||||||||||
| 11 | # | ||||||||||
| 12 | use classes | ||||||||||
| 13 | 2 | ▶ | extends => 'ProgressMonitor::Stringify::Fields::AbstractField', | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | new => 'new', | ||||||||||
| 15 | 2 | attrs_pr => ['index',]; | |||||||||
| 16 | |||||||||||
| 17 | sub new | ||||||||||
| 18 | 1 | ▶ | { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | my $class = shift; | |||||||||
| 20 | 1 | my $cfg = shift; | |||||||||
| 21 | |||||||||||
| 22 | 1 | my $self = $class->SUPER::_new($cfg, $CLASS); | |||||||||
| 23 | |||||||||||
| 24 | 1 | $cfg = $self->_get_cfg; | |||||||||
| 25 | |||||||||||
| 26 | 1 | $self->{$ATTR_index} = 0; | |||||||||
| 27 | 1 | $self->_set_width(length($cfg->get_sequence->[0])); | |||||||||
| 28 | |||||||||||
| 29 | 1 | return $self; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | sub render | ||||||||||
| 33 | 13 | ▶ | { | ||||||||
|
Subroutine
render: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | 13 | my $self = shift; | |||||||||
| 35 | # arguments not used... | ||||||||||
| 36 | # my $state = shift; | ||||||||||
| 37 | # my $ticks = shift; | ||||||||||
| 38 | # my $totalTicks = shift; | ||||||||||
| 39 | # my $clean = shift; | ||||||||||
| 40 | |||||||||||
| 41 | 13 | my $seq = $self->_get_cfg->get_sequence; | |||||||||
| 42 | 13 | return $seq->[$self->{$ATTR_index}++ % @$seq]; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | ### | ||||||||||
| 46 | |||||||||||
| 47 | package ProgressMonitor::Stringify::Fields::SpinnerConfiguration; | ||||||||||
| 48 | |||||||||||
| 49 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | |||||||||||
| 52 | # Attributes | ||||||||||
| 53 | # sequence (array ref with strings) | ||||||||||
| 54 | # For every rendition the next string will be printed in a round-robin | ||||||||||
| 55 | # fashion. Note that all strings must be of equal length. Default is a single | ||||||||||
| 56 | # character spinner, but consider ['OOO', 'XXX'] or | ||||||||||
| 57 | # ['>....', '.>...', '..>..', '...>.', '....>'] as fun variations. I'm sure you | ||||||||||
| 58 | # can come up with others :-). And of course, ['Hello'] just devolves to | ||||||||||
| 59 | # the same effect as the Fixed field... | ||||||||||
| 60 | # | ||||||||||
| 61 | use classes | ||||||||||
| 62 | 2 | ▶ | extends => 'ProgressMonitor::Stringify::Fields::AbstractFieldConfiguration', | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 63 | attrs => ['sequence'], | ||||||||||
| 64 | 2 | ; | |||||||||
| 65 | |||||||||||
| 66 | sub defaultAttributeValues | ||||||||||
| 67 | 1 | ▶ | { | ||||||||
|
Subroutine
defaultAttributeValues: called CC=1 SCAR=0.0
| |||||||||||
| 68 | 1 | my $self = shift; | |||||||||
| 69 | |||||||||||
| 70 | 1 | return {%{$self->SUPER::defaultAttributeValues()}, sequence => ['-', '\\', '|', '/']}; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub checkAttributeValues | ||||||||||
| 74 | 1 | ▶ | { | ||||||||
|
Subroutine
checkAttributeValues: called CC=4 SCAR=14.0
| |||||||||||
| 75 | 1 | my $self = shift; | |||||||||
| 76 | |||||||||||
| 77 | 1 | $self->SUPER::checkAttributeValues; | |||||||||
| 78 | |||||||||||
| 79 | 1 | my $seq = $self->get_sequence; | |||||||||
| 80 | 1 | ▶ | X::Usage->throw("sequence must be an array") unless ref($seq) eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | my $len = length($seq->[0]); | |||||||||
| 82 | 1 | for (@$seq) | |||||||||
| 83 | { | ||||||||||
| 84 | 4 | ▶ | X::Usage->throw("all sequence elements must have same length") if length($_) != $len; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 1 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | ############################ | ||||||||||
| 91 | |||||||||||
| 92 | =head1 NAME | ||||||||||
| 93 | |||||||||||
| 94 | ProgressMonitor::Stringify::Field::Spinner - a field implementation that renders progress | ||||||||||
| 95 | as a spinner. | ||||||||||
| 96 | |||||||||||
| 97 | =head1 SYNOPSIS | ||||||||||
| 98 | |||||||||||
| 99 | # call someTask and give it a monitor to call us back | ||||||||||
| 100 | # | ||||||||||
| 101 | my $spinner = ProgressMonitor::Stringify::Fields::Spinner->new; | ||||||||||
| 102 | someTask(ProgressMonitor::Stringify::ToStream->new({fields => [ $spinner ]}); | ||||||||||
| 103 | |||||||||||
| 104 | =head1 DESCRIPTION | ||||||||||
| 105 | |||||||||||
| 106 | This is a fixed size field representing progress as sequence of strings to display while work | ||||||||||
| 107 | is progressing. | ||||||||||
| 108 | |||||||||||
| 109 | Inherits from ProgressMonitor::Stringify::Fields::AbstractField. | ||||||||||
| 110 | |||||||||||
| 111 | =head1 METHODS | ||||||||||
| 112 | |||||||||||
| 113 | =over 2 | ||||||||||
| 114 | |||||||||||
| 115 | =item new( $hashRef ) | ||||||||||
| 116 | |||||||||||
| 117 | Configuration data: | ||||||||||
| 118 | |||||||||||
| 119 | =over 2 | ||||||||||
| 120 | |||||||||||
| 121 | =item sequence (default => ['-', '\\', '|', '/']) | ||||||||||
| 122 | |||||||||||
| 123 | The sequence of strings to alternate between. All strings must be of the same length. | ||||||||||
| 124 | |||||||||||
| 125 | =back | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | =head1 AUTHOR | ||||||||||
| 130 | |||||||||||
| 131 | Kenneth Olwing, C<< <knth at cpan.org> >> | ||||||||||
| 132 | |||||||||||
| 133 | =head1 BUGS | ||||||||||
| 134 | |||||||||||
| 135 | I wouldn't be surprised! If you can come up with a minimal test that shows the | ||||||||||
| 136 | problem I might be able to take a look. Even better, send me a patch. | ||||||||||
| 137 | |||||||||||
| 138 | Please report any bugs or feature requests to | ||||||||||
| 139 | C<bug-progressmonitor at rt.cpan.org>, or through the web interface at | ||||||||||
| 140 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ProgressMonitor>. | ||||||||||
| 141 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||
| 142 | your bug as I make changes. | ||||||||||
| 143 | |||||||||||
| 144 | =head1 SUPPORT | ||||||||||
| 145 | |||||||||||
| 146 | You can find general documentation for this module with the perldoc command: | ||||||||||
| 147 | |||||||||||
| 148 | perldoc ProgressMonitor | ||||||||||
| 149 | |||||||||||
| 150 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 151 | |||||||||||
| 152 | Thanks to my family. I'm deeply grateful for you! | ||||||||||
| 153 | |||||||||||
| 154 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 155 | |||||||||||
| 156 | Copyright 2006,2007 Kenneth Olwing, all rights reserved. | ||||||||||
| 157 | |||||||||||
| 158 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 159 | under the same terms as Perl itself. | ||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||
| 163 | 2 | 1; # End of ProgressMonitor::Stringify::Fields::Spinner | |||||||||