Progress-Any-0.20/0000775000175000017500000000000012461643144011427 5ustar u1u1Progress-Any-0.20/Changes0000644000175000017500000001124312461643144012721 0ustar u1u1Revision history for Progress-Any 0.20 2015-01-27 (PERLANCAR) - Merge Progress::Any::Output back from separate distribution Progress-Any-Output to Progress-Any (similar to what is done with Log-Any vs Log-Any-Adapter). 0.19 2015-01-22 (PERLANCAR) - Allow message to be coderef for delaying costly calculation, will be converted to string when sent to output. 0.18 2014-10-14 (PERLANCAR) - No functional changes. - Work around Pod::Weaver's quirks (the screenshots HTML ended up in the Status section). 0.17 2014-10-14 (PERLANCAR) - No functional changes. - Include screenshots. 0.16 2014-10-14 (PERLANCAR) - No functional changes. - Show usage example with Perinci::CmdLine. 0.15 2014-07-29 (SHARYANTO) - No functional changes. - Fix Synopsis [RT#97563]. 0.14 2014-05-01 (SHARYANTO) - No functional changes. - Temporarily make template test release testing only due to being timing-related and fail on some CT machines [CT]. 0.13 2014-02-26 (SHARYANTO) - Add frequency limiting for updating outputs. Currently set at (at most per) 0.5s. Will be configurable in the future. 0.12 2013-09-11 (SHARYANTO) - No functional changes. Temporarily put some tests (elapsed, etc) on RELEASE_TESTING due to fragility of timing/sleep. Will need to use time mocking in the future [CT]. 0.11 2013-09-08 (SHARYANTO) - No functional changes. Increase granularity of elapsed tests from 0.05s to 1s due to faliure in many systems [CT]. 0.10 2013-09-03 (SHARYANTO) - Rework internals and some API. This is the second API revision. [ENHANCEMENTS] - Allow reinitializing 'pos' and 'target' (and all other rw attributes) at subsequent get_indicator() for the same task. This is to make program more predictable, instead of silently ignoring parameters. - Allow indicator to be start()'ed and stop()'ed at any time. - Add task title (in addition to its name). - Allow specifying estimated remaining of a task when creating an indicator, via passing 'remaining'. - New fill templates: %r (remaining time), %R (remaining time or elapsed time). [INCOMPATIBLE CHANGES] - The $progress export is now set to the root ('') indicator instead of 'main', so it includes all indicators. - fill_template(): re-rationalize template names: %a (elapsed time) becomes %e, %c (pos) becomes %P, %C (target) becomes %T, %t (task name) becomes %n. [REMOVED FEATURES] - Remove 'status' in update() because it is unneeded (concerning outputs can use 'message' instead). 0.09 2013-05-18 (SHARYANTO) - Bugfix: double counting of children's targets. 0.08 2013-05-18 (SHARYANTO) - Bugfix: update() didn't recognize 'finished' parameter. - Maintain a root-level indicator (task='') to capture updates from all progress indicators. 0.07 2013-05-18 (SHARYANTO) [ENHANCEMENTS] - Add total_target(). 0.06 2013-05-18 (SHARYANTO) [INCOMPATIBLE CHANGES] - Change default task in get_indicator() to be caller's package, not subroutine. 0.05 2013-05-18 (SHARYANTO) - Happy birthday, bro! [INCOMPATIBLE CHANGES] - Revise API, now more resembles Log::Any and incompatible with previous version of Progress::Any. Split output to Progress-Any-Output (like Log-Any-Adapter is split from Log-Any), remove set_output(). Remove init() and replace it with pos() and target() because we might need to reinit (reset pos and target) any time. Remove 'inc' argument in update() to make things more orthogonal (you can always do update(pos => $progress->pos + $x). Check task syntax in get_indicator(). [ENHANCEMENTS] - API: parent indicators now get update()'d also whenever we do update()/pos($val)/target($val) on an indicator. - Progress::Any is now the one which is responsible for calculating elapsed time/ETA/% completion. Output now just displays stuffs. This makes output simpler and reduce duplicated code. 0.04 2013-01-10 (SHARYANTO) - No functional changes. More POD tweaks/fixes. 0.03 2013-01-10 (SHARYANTO) - No functional changes. Update/fix Synopsis. 0.02 2012-10-24 (SHARYANTO) - Some tweaks/fixes: don't pre-init $progress, give default message to reset() and finish(). 0.01 2012-10-24 (SHARYANTO) - First, early release. Progress-Any-0.20/LICENSE0000644000175000017500000004367712461643144012453 0ustar u1u1This software is copyright (c) 2015 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2015 by perlancar@cpan.org. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2015 by perlancar@cpan.org. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Progress-Any-0.20/MANIFEST0000644000175000017500000000052212461643144012555 0ustar u1u1# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.029. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Progress/Any.pm lib/Progress/Any/Output.pm lib/Progress/Any/Output/Null.pm t/00-compile.t t/01-basics.t t/release-pod-coverage.t t/release-pod-syntax.t t/release-rinci.t weaver.ini Progress-Any-0.20/lib/0000775000175000017500000000000012461643144012175 5ustar u1u1Progress-Any-0.20/lib/Progress/0000775000175000017500000000000012461643144014001 5ustar u1u1Progress-Any-0.20/lib/Progress/Any/0000775000175000017500000000000012461643144014530 5ustar u1u1Progress-Any-0.20/lib/Progress/Any/Output/0000775000175000017500000000000012461643144016030 5ustar u1u1Progress-Any-0.20/lib/Progress/Any/Output/Null.pm0000644000175000017500000000236012461643144017277 0ustar u1u1package Progress::Any::Output::Null; use 5.010; use strict; use warnings; our $VERSION = '0.20'; # VERSION sub new { my ($class, %args) = @_; bless \%args, $class; } sub update { 1; } 1; # ABSTRACT: Null output __END__ =pod =encoding UTF-8 =head1 NAME Progress::Any::Output::Null - Null output =head1 VERSION This document describes version 0.20 of Progress::Any::Output::Null (from Perl distribution Progress-Any), released on 2015-01-27. =for Pod::Coverage ^(new|update)$ =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2015 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Progress-Any-0.20/lib/Progress/Any/Output.pm0000644000175000017500000000670012461643144016367 0ustar u1u1package Progress::Any::Output; our $DATE = '2015-01-27'; # DATE our $VERSION = '0.20'; # VERSION use 5.010001; use strict; use warnings; require Progress::Any; sub import { my $self = shift; __PACKAGE__->set(@_) if @_; } sub _set_or_add { my $class = shift; my $which = shift; my $opts; if (@_ && ref($_[0]) eq 'HASH') { $opts = shift; } else { $opts = {}; } my $output = shift or die "Please specify output name"; $output =~ /\A(?:\w+(::\w+)*)?\z/ or die "Invalid output syntax '$output'"; my $task = $opts->{task} // ""; my $outputo; unless (ref $outputo) { my $outputpm = $output; $outputpm =~ s!::!/!g; $outputpm .= ".pm"; require "Progress/Any/Output/$outputpm"; no strict 'refs'; $outputo = "Progress::Any::Output::$output"->new(@_); } if ($which eq 'set') { $Progress::Any::outputs{$task} = [$outputo]; } else { $Progress::Any::outputs{$task} //= []; push @{ $Progress::Any::outputs{$task} }, $outputo; } $outputo; } sub set { my $class = shift; $class->_set_or_add('set', @_); } sub add { my $class = shift; $class->_set_or_add('add', @_); } 1; # ABSTRACT: Assign output to progress indicators __END__ =pod =encoding UTF-8 =head1 NAME Progress::Any::Output - Assign output to progress indicators =head1 VERSION This document describes version 0.20 of Progress::Any::Output (from Perl distribution Progress-Any), released on 2015-01-27. =head1 SYNOPSIS In your application: use Progress::Any::Output; Progress::Any::Output->set('TermProgressBarColor'); or: use Progress::Any::Output 'TermProgressBarColor'; To give parameters to output: use Progress::Any::Output; Progress::Any::Output->set('TermProgressBarColor', width=>50, ...); or: use Progress::Any::Output 'TermProgressBarColor', width=>50, ...; To assign output to a certain (sub)task: use Progress::Any::Output; Progress::Any::Output->set({task=>'main.download'}, 'TermMessage'); To add additional output, use C instead of C. =head1 DESCRIPTION See L for overview. =head1 METHODS =head2 Progress::Any::Output->set([ \%opts ], $output[, @args]) => obj Set (or replace) output. Will load and instantiate C. To only set output for a certain (sub)task, set C<%opts> to C<< { task => $task } >>. C<@args> will be passed to output module's constructor. Return the instantiated object. If C<$output> is an object (a reference, really), it will be used as-is. =head2 Progress::Any::Output->add([ \%opts ], $output[, @args]) Like set(), but will add output instead of replace existing one(s). =head1 SEE ALSO L =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2015 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Progress-Any-0.20/lib/Progress/Any.pm0000644000175000017500000006760712461643144015104 0ustar u1u1package Progress::Any; our $DATE = '2015-01-27'; # DATE our $VERSION = '0.20'; # VERSION use 5.010001; use strict; use warnings; use Time::Duration qw(); use Time::HiRes qw(time); sub import { my ($self, @args) = @_; my $caller = caller(); for (@args) { if ($_ eq '$progress') { my $progress = $self->get_indicator(task => ''); { no strict 'refs'; my $v = "$caller\::progress"; *$v = \$progress; } } else { die "Unknown import argument: $_"; } } } # store Progress::Any objects for each task our %indicators; # key = task name # store output objects our %outputs; # key = task name, value = [$outputobj, ...] # store settings/data for each object our %output_data; # key = "$output_object", value = {key=>val, ...} # internal attributes: # - _elapsed (float*) = accumulated elapsed time so far # - _start_time (float) = when is the last time the indicator state is changed # from 'stopped' to 'started'. when indicator is changed from 'started' to # 'stopped', this will be set to undef. # - _remaining = used to store user's estimation of remaining time. will be # unset after each update(). # return 1 if created, 0 if already created/initialized sub _init_indicator { my ($class, $task) = @_; #say "D: _init_indicator($task)"; # prevent double initialization return $indicators{$task} if $indicators{$task}; my $progress = bless({ task => $task, title => $task, target => 0, pos => 0, state => 'stopped', _remaining => undef, _set_remaining_time => undef, _elapsed => 0, _start_time => 0, }, $class); $indicators{$task} = $progress; # if we create an indicator named a.b.c, we must also create a.b, a, and ''. if ($task =~ s/\.?\w+\z//) { $class->_init_indicator($task); } $progress; } sub get_indicator { my ($class, %args) = @_; my %oargs = %args; my $task = delete($args{task}); if (!defined($task)) { my @caller = caller(0); #say "D:caller=".join(",",map{$_//""} @caller); $task = $caller[0] eq '(eval)' ? 'main' : $caller[0]; $task =~ s/::/./g; $task =~ s/[^.\w]+/_/g; } die "Invalid task syntax '$task', please only use dotted words" unless $task =~ /\A(?:\w+(\.\w+)*)?\z/; my %uargs; my $p = $class->_init_indicator($task); for my $an (qw/title target pos remaining state/) { if (exists $args{$an}) { $uargs{$an} = delete($args{$an}); } } die "Unknown argument(s) to get_indicator(): ".join(", ", keys(%args)) if keys(%args); $p->_update(%uargs) if keys %uargs; $p; } my %attrs = ( title => {is => 'rw'}, target => {is => 'rw'}, pos => {is => 'rw'}, state => {is => 'rw'}, ); # create attribute methods for my $an (keys %attrs) { next if $attrs{$an}{manual}; my $code; if ($attrs{$an}{is} eq 'rw') { $code = sub { my $self = shift; if (@_) { $self->_update($an => shift); } $self->{$an}; }; } else { $code = sub { my $self = shift; die "Can't set value, $an is an ro attribute" if @_; $self->{$an}; }; } no strict 'refs'; *{$an} = $code; } sub elapsed { my $self = shift; if ($self->{state} eq 'started') { return $self->{_elapsed} + (time()-$self->{_start_time}); } else { return $self->{_elapsed}; } } sub total_pos { my $self = shift; my $t = $self->{task}; my $res = $self->{pos}; for (keys %indicators) { if ($t eq '') { next if $_ eq ''; } else { next unless index($_, "$t.") == 0; } $res += $indicators{$_}{pos}; } $res; } sub total_target { my $self = shift; my $t = $self->{task}; my $res = $self->{target}; return undef unless defined($res); for (keys %indicators) { if ($t eq '') { next if $_ eq ''; } else { next unless index($_, "$t.") == 0; } return undef unless defined $indicators{$_}{target}; $res += $indicators{$_}{target}; } $res; } sub percent_complete { my $self = shift; my $total_pos = $self->total_pos; my $total_target = $self->total_target; return undef unless defined($total_target); if ($total_target == 0) { if ($self->{state} eq 'finished') { return 100; } else { return 0; } } else { return $total_pos / $total_target * 100; } } sub remaining { my $self = shift; if (defined $self->{_remaining}) { if ($self->{state} eq 'started') { my $r = $self->{_remaining}-(time()-$self->{_set_remaining_time}); return $r > 0 ? $r : 0; } else { return $self->{_remaining}; } } else { if (defined $self->{target}) { if ($self->{pos} == 0) { return 0; } else { return ($self->{target} - $self->{pos})/$self->{pos} * $self->elapsed; } } else { return undef; } } } sub total_remaining { my $self = shift; my $t = $self->{task}; my $res = $self->remaining; return undef unless defined $res; for (keys %indicators) { if ($t eq '') { next if $_ eq ''; } else { next unless index($_, "$t.") == 0; } my $res2 = $indicators{$_}->remaining; return undef unless defined $res2; $res += $res2; } $res; } # the routine to use to update rw attributes, does validation and checks to make # sure things are consistent. sub _update { my ($self, %args) = @_; # no need to check for unknown arg in %args, it's an internal method anyway my $now = time(); my $task = $self->{task}; #use Data::Dump; print "D: _update($task) "; dd \%args; SET_TITLE: { last unless exists $args{title}; my $val = $args{title}; die "Invalid value for title, must be defined" unless defined($val); $self->{title} = $val; } SET_TARGET: { last unless exists $args{target}; my $val = $args{target}; die "Invalid value for target, must be a positive number or undef" unless !defined($val) || $val >= 0; # ensure that pos does not exceed target if (defined($val) && $self->{pos} > $val) { $self->{pos} = $val; } $self->{target} = $val; undef $self->{_remaining}; } SET_POS: { last unless exists $args{pos}; my $val = $args{pos}; die "Invalid value for pos, must be a positive number" unless defined($val) && $val >= 0; # ensure that pos does not exceed target if (defined($self->{target}) && $val > $self->{target}) { $val = $self->{target}; } $self->{pos} = $val; undef $self->{_remaining}; } SET_REMAINING: { last unless exists $args{remaining}; my $val = $args{remaining}; die "Invalid value for remaining, must be a positive number" unless defined($val) && $val >= 0; $self->{_remaining} = $val; $self->{_set_remaining_time} = $now; } SET_STATE: { last unless exists $args{state}; my $old = $self->{state}; my $val = $args{state} // 'started'; die "Invalid value for state, must be stopped/started/finished" unless $val =~ /\A(?:stopped|started|finished)\z/; last if $old eq $val; if ($val eq 'started') { $self->{_start_time} = $now; # automatically start parents my @parents; { my $t = $task; while (1) { last unless $t =~ s/\.\w+\z//; push @parents, $t; } push @parents, ''; } for my $t (@parents) { my $p = $indicators{$t}; if ($p->{state} ne 'started') { $p->{state} = 'started'; $p->{_start_time} = $now; } } } else { $self->{_elapsed} += $now - $self->{_start_time}; if ($val eq 'finished') { die "BUG: Can't finish task '$task', pos is still < target" if defined($self->{target}) && $self->{pos} < $self->{target}; $self->{_remaining} = 0; $self->{_set_remaining_time} = $now; } } $self->{state} = $val; } DONE: #use Data::Dump; print "after update: "; dd $self; return; } sub _should_update_output { my ($self, $output, $now) = @_; my $key = "$output"; $output_data{$key} //= {}; my $odata = $output_data{$key}; if (!defined($odata->{mtime})) { # output has never been updated, update return 1; } elsif ($self->{state} eq 'finished') { # finishing, update the output to show finished state return 1; } elsif ($odata->{force_update}) { # force update delete $odata->{force_update}; return 1; # } elsif ($args->{prio} eq 'low') { # perhaps provide something like this? a low-priority or minor update so # we don't have to update the outputs? } else { # normal update, update if not too frequent if (!defined($odata->{freq})) { # negative number means seconds, positive means pos delta. only # update if that number of seconds, or that difference in pos has # been passed. $odata->{freq} = -0.5; } if ($odata->{freq} < 0) { return 1 if $now >= $odata->{mtime} - $odata->{freq}; } else { return 1 if abs($self->{pos} - $odata->{pos}) >= $odata->{freq}; } return 0; } } sub update { my ($self, %args) = @_; my $pos = delete($args{pos}) // $self->{pos} + 1; my $state = delete($args{state}) // 'started'; $self->_update(pos => $pos, state => $state); my $message = delete($args{message}); my $level = delete($args{level}); die "Unknown argument(s) to update(): ".join(", ", keys(%args)) if keys(%args); my $now = time(); # find output(s) and call it { my $task = $self->{task}; while (1) { if ($outputs{$task}) { for my $output (@{ $outputs{$task} }) { next unless $self->_should_update_output($output, $now); if (ref($message) eq 'CODE') { $message = $message->(); } $output->update( indicator => $indicators{$task}, message => $message, level => $level, time => $now, ); my $key = "$output"; $output_data{$key}{mtime} = $now; $output_data{$key}{pos} = $pos; } } last unless $task =~ s/\.?\w+\z//; } } } sub start { my $self = shift; $self->_update(state => 'started'); } sub stop { my $self = shift; $self->_update(state => 'stopped'); } sub finish { my ($self, %args) = @_; $self->update(pos=>$self->{target}, state=>'finished', %args); } # - currently used letters: emnPpRrTt% # - currently used by Output::TermProgressBarColor: bB # - letters that can be used later: s (state) sub fill_template { my ($self, $template, %args) = @_; # TODO: some caching so "%e%e" produces two identical numbers state $re = qr{( # all=1 % ( #width=2 -?\d+ )? ( #dot=3 \.?) ( #prec=4 \d+)? ( #conv=5 [emnPpRrTt%]) )}x; state $sub = sub { my %args = @_; my ($all, $width, $dot, $prec, $conv) = ($1, $2, $3, $4, $5); my $p = $args{indicator}; my ($fmt, $sconv, $data); if ($conv eq 'n') { $data = $p->{task}; } elsif ($conv eq 't') { $data = $p->{title}; } elsif ($conv eq '%') { $data = '%'; } elsif ($conv eq 'm') { $data = $args{message} // ''; } elsif ($conv eq 'p') { my $val = $p->percent_complete; $width //= 3; if (defined $val) { $data = $val; $prec //= 0; $sconv = "f"; } else { $data = '?'; } } elsif ($conv eq 'P') { $data = $p->total_pos; $prec //= 0; $sconv = "f"; } elsif ($conv eq 'T') { my $val = $p->total_target; if (defined $val) { $data = $val; $prec //= 0; $sconv = "f"; } else { $data = '?'; } } elsif ($conv eq 'e') { my $val = $p->elapsed; $val = 1 if $val < 1; # TMP, prevent duration() return "just now" $data = Time::Duration::concise(Time::Duration::duration($val)); $width //= -8; } elsif ($conv eq 'r') { my $val = $p->total_remaining; if (defined $val) { $val = 1 if $val < 1; # TMP, prevent duration() return "just now $data = Time::Duration::concise(Time::Duration::duration($val)); } else { $data = '?'; } $width //= -8; } elsif ($conv eq 'R') { my $val = $p->total_remaining; if (defined $val) { $val = 1 if $val < 1; # TMP, prevent duration() return "just now $data = Time::Duration::concise(Time::Duration::duration($val)). " left"; # XXX i18n } else { $val = $p->elapsed; $val = 1 if $val < 1; # TMP, prevent duration() return "just now $data = Time::Duration::concise(Time::Duration::duration($val)). " elapsed"; # XXX i18n } $width //= -(8 + 1 + 7); } else { # return as-is $fmt = '%s'; $data = $all; } # sprintf format $sconv //= 's'; $dot = "." if $sconv eq 'f'; $fmt //= join("", grep {defined} ("%", $width, $dot, $prec, $sconv)); #say "D:fmt=$fmt"; sprintf $fmt, $data; }; $template =~ s{$re}{$sub->(%args, indicator=>$self)}egox; $template; } 1; # ABSTRACT: Record progress to any output __END__ =pod =encoding UTF-8 =head1 NAME Progress::Any - Record progress to any output =head1 VERSION This document describes version 0.20 of Progress::Any (from Perl distribution Progress-Any), released on 2015-01-27. =head1 SYNOPSIS =head2 First example, simple usage in a script use Progress::Any '$progress'; use Progress::Any::Output 'TermProgressBarColor'; $progress->target(10); for (1..10) { $progress->update(message => "Doing item $_"); sleep 1; } Sample output: % ./script.pl 60% [Doing item 6==== ]3s left =head2 Second example, usage in module as well as script In your module: package MyApp; use Progress::Any; sub download { my @urls = @_; return unless @urls; my $progress = Progress::Any->get_indicator( task => "download", pos=>0, target=>~~@urls); for my $url (@urls) { # download the $url ... $progress->update(message => "Downloaded $url"); } $progress->finish; } In your application: use MyApp; use Progress::Any::Output; Progress::Any::Output->set('TermProgressBarColor'); MyApp::download("url1", "url2", "url3", "url4", "url5"); sample output, in succession: % ./script.pl 20% [====== Downloaded url1 ]0m00s Left 40% [=======Downloaded url2 ]0m01s Left 60% [=======Downloaded url3 ]0m01s Left 80% [=======Downloaded url4== ]0m00s Left (At 100%, the output automatically cleans up the progress bar). =head3 Another example, demonstrating multiple indicators and the LogAny output: use Progress::Any; use Progress::Any::Output; use Log::Any::App; Progress::Any::Output->set('LogAny', template => '[%-8t] [%P/%2T] %m'); my $pdl = Progress::Any->get_indicator(task => 'download'); my $pcp = Progress::Any->get_indicator(task => 'copy'); $pdl->pos(10); $pdl->target(10); $pdl->update(message => "downloading A"); $pcp->update(message => "copying A"); $pdl->update(message => "downloading B"); $pcp->update(message => "copying B"); will show something like: [download] [1/10] downloading A [copy ] [1/ ?] copying A [download] [2/10] downloading B [copy ] [2/ ?] copying B =head2 Example of using with Perinci::CmdLine If you use L, you can mark your function as expecting a Progress::Any object and it will be supplied to you in a special argument C<-progress>: use File::chdir; use Perinci::CmdLine; $SPEC{check_dir} = { v => 1.1, args => { dir => {summary=>"Path to check", schema=>"str*", req=>1, pos=>0}, }, features => {progress=>1}, }; sub check_dir { my %args = @_; my $progress = $args{-progress}; my $dir = $args{dir}; (-d $dir) or return [412, "No such dir: $dir"]; local $CWD = $dir; opendir my($dh), $dir; my @ent = readdir($dh); $progress->pos(0); $progress->target(~~@ent); for (@ent) { # do the check ... $progress->update(message => $_); sleep 1; } $progress->finish; [200]; } Perinci::CmdLine->new(url => '/main/check_dir')->run; =head1 DESCRIPTION C is an interface for applications that want to display progress to users. It decouples progress updating and output, rather similar to how L decouples log producers and consumers (output). The API is also rather similar to Log::Any, except I is called I and I is called I. Progress::Any records position/target and calculates elapsed time, estimated remaining time, and percentage of completion. One or more output modules (Progress::Any::Output::*) display this information. In your modules, you typically only need to use Progress::Any, get one or more indicators, set target and update it during work. In your application, you use Progress::Any::Output and set/add one or more outputs to display the progress. By setting output only in the application and not in modules, you separate the formatting/display concern from the logic. Screenshots: =head1 STATUS API might still change, will be stabilized in 1.0. =begin HTML


Using TermProgressBarColor output


Using DesktopNotify output =end HTML The list of features: =over 4 =item * multiple progress indicators You can use different indicator for each task/subtask. =item * customizable output Output is handled by one of C modules. Currently available outputs: C (no output), C (display as simple message on terminal), C (display as color progress bar on terminal), C (log using L), C (call a subroutine). Other possible output ideas: IM/Twitter/SMS, GUI, web/AJAX, remote/RPC (over L for example, so that L-based command-line clients can display progress update from remote functions). =item * multiple outputs One or more outputs can be used to display one or more indicators. =item * hierarchical progress A task can be divided into subtasks. If a subtask is updated, its parent task (and its parent, and so on) are also updated proportionally. =item * message Aside from setting a number/percentage, allow including a message when updating indicator. =item * undefined target Target can be undefined, so a bar output might not show any bar (or show them, but without percentage indicator), but can still show messages. =item * retargetting Target can be changed in the middle of things. =back =head1 EXPORTS =head2 $progress => OBJ The root indicator. Equivalent to: Progress::Any->get_indicator(task => '') =head1 ATTRIBUTES Below are the attributes of an indicator/task: =head2 task => STR* (default: from caller's package, or C

) Task name. If not specified will be set to caller's package (C<::> will be replaced with C<.>), e.g. if you are calling this method from C, then task will be set to C. If caller is code inside eval, C
will be used instead. =head2 title => STR* (default: task name) Specify task title. Task title is a longer description for a task and can contain spaces and other characters. It is displayed in some outputs, as well as using C<%t> in C. For example, for a task called C, its title might be C. =head2 target => POSNUM (default: 0) The total number of items to finish. Can be set to undef to mean that we don't know (yet) how many items there are to finish (in which case, we cannot estimate percent of completion and remaining time). =head2 pos => POSNUM* (default: 0) The number of items that are already done. It cannot be larger than C, if C is defined. If C is set to a value smaller than C or C is set to a value larger than C, C will be changed to be C. =head2 state => STR (default: C) State of task/indicator. Either: C, C, or C. Initially it will be set to C, which means elapsed time won't be running and will stay at 0. C will set the state to C to get elapsed time to run. At the end of task, you can call C (or alternatively set C to C) to stop the elapsed time again. The difference between C and C is: when C and C are both at 0, percent completed is assumed to be 0% when state is C, but 100% when state is C. =head1 METHODS =head2 Progress::Any->get_indicator(%args) => OBJ Get a progress indicator for a certain task. C<%args> contain attribute values, at least C must be specified. Note that this module maintains a list of indicator singleton objects for each task (in C<%indicators> package variable), so subsequent C for the same task will return the same object. =head2 $progress->update(%args) Update indicator. Will also, usually, update associated output(s) if necessary. Arguments: =over 4 =item * pos => NUM Set the new position. If unspecified, defaults to current position + 1. If pos is larger than target, outputs will generally still show 100%. Note that fractions are allowed. =item * message => str|code Set a message to be displayed when updating indicator. Aside from a string, you can also pass a coderef here. It can be used to delay costly calculation. The message will only be calculated when actually sent to output. =item * level => NUM EXPERIMENTAL, NOT YET IMPLEMENTED BY MOST OUTPUTS. Setting the importance level of this update. Default is C (or C for fractional update), but can be set to C or C. Output can choose to ignore updates lower than a certain level. =item * state => STR Can be set to C to finish a task. =back =head2 $progress->finish(%args) Equivalent to: $progress->update( ( pos => $progress->target ) x !!defined($progress->target), state => 'finished', %args, ); =head2 $progress->start() Set state to C. =head2 $progress->stop() Set state to C. =head2 $progress->elapsed() => FLOAT Get elapsed time. Just like a stop-watch, when state is C elapsed time will run and when state is C, it will freeze. =head2 $progress->remaining() => undef|FLOAT Give estimated remaining time until task is finished, which will depend on how fast the C is called, i.e. how fast C is approaching C. Will be undef if C is undef. =head2 $progress->total_remaining() => undef|FLOAT Give estimated remaining time added by all its subtasks' remaining. Return undef if any one of those time is undef. =head2 $progress->total_pos() => FLOAT Total of indicator's pos and all of its subtasks'. =head2 $progress->total_target() => undef|FLOAT Total of indicator's target and all of its subtasks'. Return undef if any one of those is undef. =head2 $progress->percent_complete() => undef|FLOAT Give percentage of completion, calculated using C<< total_pos / total_target * 100 >>. Undef if total_target is undef. =head2 $progress->fill_template($template) Fill template with values, like in C. Usually used by output modules. Available templates: =over =item * C<%(width)n> Task name (the value of the C attribute). C is optional, an integer, like in C, can be negative to mean left-justify instead of right. =item * C<%(width)t> Task title (the value of the C attribute). =item * C<%(width)e> Elapsed time (the result from the C<elapsed()> method). Currently using L<Time::Duration> concise format, e.g. 10s, 1m40s, 16m40s, 1d4h, and so on. Format might be configurable and localizable in the future. Default width is -8. Examples: 2m30s 10s =item * C<%(width)r> Estimated remaining time (the result of the C<total_remaining()> method). Currently using L<Time::Duration> concise format, e.g. 10s, 1m40s, 16m40s, 1d4h, and so on. Will show C<?> if unknown. Format might be configurable and localizable in the future. Default width is -8. Examples: 1m40s 5s =item * C<%(width)R> Estimated remaining time I<or> elapsed time, if estimated remaining time is not calculatable (e.g. when target is undefined). Format might be configurable and localizable in the future. Default width is -(8+1+7). Examples: 30s left 1m40s elapsed =item * C<%(width).(prec)p> Percentage of completion (the result of the C<percent_complete()> method). C<width> and C<precision> are optional, like C<%f> in Perl's C<sprintf()>, default is C<%3.0p>. If percentage is unknown (due to target being undef), will show C<?>. =item * C<%(width)P> Current position (the result of the C<total_pos()> method). =item * C<%(width)T> Target (the result of the C<total_target()> method). If undefined, will show C<?>. =item * C<%m> Message (the C<update()> parameter). If message is unspecified, will show empty string. =item * C<%%> A literal C<%> sign. =back =head1 FAQ =head1 SEE ALSO Other progress modules on CPAN: L<Term::ProgressBar>, L<Term::ProgressBar::Simple>, L<Time::Progress>, among others. Output modules: C<Progress::Any::Output::*> See examples on how Progress::Any is used by other modules: L<Perinci::CmdLine> (supplying progress object to functions), L<Git::Bunch> (using progress object). =head1 HOMEPAGE Please visit the project's homepage at L<https://metacpan.org/release/Progress-Any>. =head1 SOURCE Source repository is at L<https://github.com/perlancar/perl-Progress-Any>. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Progress-Any> When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR perlancar <perlancar@cpan.org> =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2015 by perlancar@cpan.org. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut �������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/README����������������������������������������������������������������������������0000644�0001750�0001750�00000030270�12461643144�012307� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������SYNOPSIS First example, simple usage in a script use Progress::Any '$progress'; use Progress::Any::Output 'TermProgressBarColor'; $progress->target(10); for (1..10) { $progress->update(message => "Doing item $_"); sleep 1; } Sample output: % ./script.pl 60% [Doing item 6==== ]3s left Second example, usage in module as well as script In your module: package MyApp; use Progress::Any; sub download { my @urls = @_; return unless @urls; my $progress = Progress::Any->get_indicator( task => "download", pos=>0, target=>~~@urls); for my $url (@urls) { # download the $url ... $progress->update(message => "Downloaded $url"); } $progress->finish; } In your application: use MyApp; use Progress::Any::Output; Progress::Any::Output->set('TermProgressBarColor'); MyApp::download("url1", "url2", "url3", "url4", "url5"); sample output, in succession: % ./script.pl 20% [====== Downloaded url1 ]0m00s Left 40% [=======Downloaded url2 ]0m01s Left 60% [=======Downloaded url3 ]0m01s Left 80% [=======Downloaded url4== ]0m00s Left (At 100%, the output automatically cleans up the progress bar). Another example, demonstrating multiple indicators and the LogAny output: use Progress::Any; use Progress::Any::Output; use Log::Any::App; Progress::Any::Output->set('LogAny', template => '[%-8t] [%P/%2T] %m'); my $pdl = Progress::Any->get_indicator(task => 'download'); my $pcp = Progress::Any->get_indicator(task => 'copy'); $pdl->pos(10); $pdl->target(10); $pdl->update(message => "downloading A"); $pcp->update(message => "copying A"); $pdl->update(message => "downloading B"); $pcp->update(message => "copying B"); will show something like: [download] [1/10] downloading A [copy ] [1/ ?] copying A [download] [2/10] downloading B [copy ] [2/ ?] copying B Example of using with Perinci::CmdLine If you use Perinci::CmdLine, you can mark your function as expecting a Progress::Any object and it will be supplied to you in a special argument -progress: use File::chdir; use Perinci::CmdLine; $SPEC{check_dir} = { v => 1.1, args => { dir => {summary=>"Path to check", schema=>"str*", req=>1, pos=>0}, }, features => {progress=>1}, }; sub check_dir { my %args = @_; my $progress = $args{-progress}; my $dir = $args{dir}; (-d $dir) or return [412, "No such dir: $dir"]; local $CWD = $dir; opendir my($dh), $dir; my @ent = readdir($dh); $progress->pos(0); $progress->target(~~@ent); for (@ent) { # do the check ... $progress->update(message => $_); sleep 1; } $progress->finish; [200]; } Perinci::CmdLine->new(url => '/main/check_dir')->run; STATUS API might still change, will be stabilized in 1.0. DESCRIPTION Progress::Any is an interface for applications that want to display progress to users. It decouples progress updating and output, rather similar to how Log::Any decouples log producers and consumers (output). The API is also rather similar to Log::Any, except Adapter is called Output and category is called task. Progress::Any records position/target and calculates elapsed time, estimated remaining time, and percentage of completion. One or more output modules (Progress::Any::Output::*) display this information. In your modules, you typically only need to use Progress::Any, get one or more indicators, set target and update it during work. In your application, you use Progress::Any::Output and set/add one or more outputs to display the progress. By setting output only in the application and not in modules, you separate the formatting/display concern from the logic. Screenshots: The list of features: * multiple progress indicators You can use different indicator for each task/subtask. * customizable output Output is handled by one of Progress::Any::Output::* modules. Currently available outputs: Null (no output), TermMessage (display as simple message on terminal), TermProgressBarColor (display as color progress bar on terminal), LogAny (log using Log::Any), Callback (call a subroutine). Other possible output ideas: IM/Twitter/SMS, GUI, web/AJAX, remote/RPC (over Riap for example, so that Perinci::CmdLine-based command-line clients can display progress update from remote functions). * multiple outputs One or more outputs can be used to display one or more indicators. * hierarchical progress A task can be divided into subtasks. If a subtask is updated, its parent task (and its parent, and so on) are also updated proportionally. * message Aside from setting a number/percentage, allow including a message when updating indicator. * undefined target Target can be undefined, so a bar output might not show any bar (or show them, but without percentage indicator), but can still show messages. * retargetting Target can be changed in the middle of things. EXPORTS $progress => OBJ The root indicator. Equivalent to: Progress::Any->get_indicator(task => '') ATTRIBUTES Below are the attributes of an indicator/task: task => STR* (default: from caller's package, or main) Task name. If not specified will be set to caller's package (:: will be replaced with .), e.g. if you are calling this method from Foo::Bar::baz(), then task will be set to Foo.Bar. If caller is code inside eval, main will be used instead. title => STR* (default: task name) Specify task title. Task title is a longer description for a task and can contain spaces and other characters. It is displayed in some outputs, as well as using %t in fill_template(). For example, for a task called copy, its title might be Copying files to remote server. target => POSNUM (default: 0) The total number of items to finish. Can be set to undef to mean that we don't know (yet) how many items there are to finish (in which case, we cannot estimate percent of completion and remaining time). pos => POSNUM* (default: 0) The number of items that are already done. It cannot be larger than target, if target is defined. If target is set to a value smaller than pos or pos is set to a value larger than target, pos will be changed to be target. state => STR (default: stopped) State of task/indicator. Either: stopped, started, or finished. Initially it will be set to stopped, which means elapsed time won't be running and will stay at 0. update() will set the state to started to get elapsed time to run. At the end of task, you can call finish() (or alternatively set state to finished) to stop the elapsed time again. The difference between stopped and finished is: when target and pos are both at 0, percent completed is assumed to be 0% when state is stopped, but 100% when state is finished. METHODS Progress::Any->get_indicator(%args) => OBJ Get a progress indicator for a certain task. %args contain attribute values, at least task must be specified. Note that this module maintains a list of indicator singleton objects for each task (in %indicators package variable), so subsequent get_indicator() for the same task will return the same object. $progress->update(%args) Update indicator. Will also, usually, update associated output(s) if necessary. Arguments: * pos => NUM Set the new position. If unspecified, defaults to current position + 1. If pos is larger than target, outputs will generally still show 100%. Note that fractions are allowed. * message => str|code Set a message to be displayed when updating indicator. Aside from a string, you can also pass a coderef here. It can be used to delay costly calculation. The message will only be calculated when actually sent to output. * level => NUM EXPERIMENTAL, NOT YET IMPLEMENTED BY MOST OUTPUTS. Setting the importance level of this update. Default is normal (or low for fractional update), but can be set to high or low. Output can choose to ignore updates lower than a certain level. * state => STR Can be set to finished to finish a task. $progress->finish(%args) Equivalent to: $progress->update( ( pos => $progress->target ) x !!defined($progress->target), state => 'finished', %args, ); $progress->start() Set state to started. $progress->stop() Set state to stopped. $progress->elapsed() => FLOAT Get elapsed time. Just like a stop-watch, when state is started elapsed time will run and when state is stopped, it will freeze. $progress->remaining() => undef|FLOAT Give estimated remaining time until task is finished, which will depend on how fast the update() is called, i.e. how fast pos is approaching target. Will be undef if target is undef. $progress->total_remaining() => undef|FLOAT Give estimated remaining time added by all its subtasks' remaining. Return undef if any one of those time is undef. $progress->total_pos() => FLOAT Total of indicator's pos and all of its subtasks'. $progress->total_target() => undef|FLOAT Total of indicator's target and all of its subtasks'. Return undef if any one of those is undef. $progress->percent_complete() => undef|FLOAT Give percentage of completion, calculated using total_pos / total_target * 100. Undef if total_target is undef. $progress->fill_template($template) Fill template with values, like in sprintf(). Usually used by output modules. Available templates: * %(width)n Task name (the value of the task attribute). width is optional, an integer, like in sprintf(), can be negative to mean left-justify instead of right. * %(width)t Task title (the value of the title attribute). * %(width)e Elapsed time (the result from the elapsed() method). Currently using Time::Duration concise format, e.g. 10s, 1m40s, 16m40s, 1d4h, and so on. Format might be configurable and localizable in the future. Default width is -8. Examples: 2m30s 10s * %(width)r Estimated remaining time (the result of the total_remaining() method). Currently using Time::Duration concise format, e.g. 10s, 1m40s, 16m40s, 1d4h, and so on. Will show ? if unknown. Format might be configurable and localizable in the future. Default width is -8. Examples: 1m40s 5s * %(width)R Estimated remaining time or elapsed time, if estimated remaining time is not calculatable (e.g. when target is undefined). Format might be configurable and localizable in the future. Default width is -(8+1+7). Examples: 30s left 1m40s elapsed * %(width).(prec)p Percentage of completion (the result of the percent_complete() method). width and precision are optional, like %f in Perl's sprintf(), default is %3.0p. If percentage is unknown (due to target being undef), will show ?. * %(width)P Current position (the result of the total_pos() method). * %(width)T Target (the result of the total_target() method). If undefined, will show ?. * %m Message (the update() parameter). If message is unspecified, will show empty string. * %% A literal % sign. FAQ SEE ALSO Other progress modules on CPAN: Term::ProgressBar, Term::ProgressBar::Simple, Time::Progress, among others. Output modules: Progress::Any::Output::* See examples on how Progress::Any is used by other modules: Perinci::CmdLine (supplying progress object to functions), Git::Bunch (using progress object). ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/META.json�������������������������������������������������������������������������0000644�0001750�0001750�00000037002�12461643144�013050� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "abstract" : "Record progress to any output", "author" : [ "perlancar <perlancar@cpan.org>" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.029, CPAN::Meta::Converter version 2.143240", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Progress-Any", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "Perl::osnames" : "0.09" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Rinci" : "0.01" } }, "runtime" : { "requires" : { "Time::Duration" : "0", "perl" : "5.010001" } }, "test" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::Exception" : "0", "Test::More" : "0.98" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Progress-Any" }, "homepage" : "https://metacpan.org/release/Progress-Any", "repository" : { "type" : "git", "url" : "git://github.com/perlancar/perl-Progress-Any.git", "web" : "https://github.com/perlancar/perl-Progress-Any" } }, "version" : "0.20", "x_Dist_Zilla" : { "perl" : { "version" : "5.018001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "follow_symlinks" : "0", "include_dotfiles" : "0", "prefix" : "", "prune_directory" : [], "root" : "." } }, "name" : "@Author::PERLANCAR/@Filter/GatherDir", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::PERLANCAR/@Filter/PruneCruft", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::PERLANCAR/@Filter/ManifestSkip", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::PERLANCAR/@Filter/MetaYAML", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::PERLANCAR/@Filter/License", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Author::PERLANCAR/@Filter/PodCoverageTests", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::PERLANCAR/@Filter/PodSyntaxTests", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Author::PERLANCAR/@Filter/ExtraTests", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::PERLANCAR/@Filter/ExecDir", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::PERLANCAR/@Filter/ShareDir", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::PERLANCAR/@Filter/MakeMaker", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::PERLANCAR/@Filter/Manifest", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::PERLANCAR/@Filter/ConfirmRelease", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Author::PERLANCAR/@Filter/UploadToCPAN", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::Rinci::AbstractFromMeta", "name" : "@Author::PERLANCAR/Rinci::AbstractFromMeta", "version" : "0.06" }, { "class" : "Dist::Zilla::Plugin::PodnameFromFilename", "name" : "@Author::PERLANCAR/PodnameFromFilename", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::MetaResources", "name" : "@Author::PERLANCAR/PERLANCAR::MetaResources", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::CheckChangeLog", "name" : "@Author::PERLANCAR/CheckChangeLog", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::CheckMetaResources", "name" : "@Author::PERLANCAR/CheckMetaResources", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::PERLANCAR/MetaJSON", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::PERLANCAR/MetaConfig", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::GenShellCompletion", "name" : "@Author::PERLANCAR/GenShellCompletion", "version" : "0.07" }, { "class" : "Dist::Zilla::Plugin::OurDate", "name" : "@Author::PERLANCAR/OurDate", "version" : "0.02" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.009" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@Author::PERLANCAR/Name", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@Author::PERLANCAR/Version", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Author::PERLANCAR/prelude", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "SYNOPSIS", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "DESCRIPTION", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "OVERVIEW", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "ATTRIBUTES", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "METHODS", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "FUNCTIONS", "version" : "4.009" }, { "class" : "Pod::Weaver::Plugin::Rinci", "name" : "@Author::PERLANCAR/Rinci", "version" : "0.29" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@Author::PERLANCAR/Leftovers", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@Author::PERLANCAR/postlude", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Completion::GetoptLongComplete", "name" : "@Author::PERLANCAR/Completion::GetoptLongComplete", "version" : "0.06" }, { "class" : "Pod::Weaver::Section::Completion::PerinciCmdLine", "name" : "@Author::PERLANCAR/Completion::PerinciCmdLine", "version" : "0.09" }, { "class" : "Pod::Weaver::Section::Homepage::DefaultCPAN", "name" : "@Author::PERLANCAR/Homepage::DefaultCPAN", "version" : "0.03" }, { "class" : "Pod::Weaver::Section::Source::DefaultGitHub", "name" : "@Author::PERLANCAR/Source::DefaultGitHub", "version" : "0.05" }, { "class" : "Pod::Weaver::Section::Bugs::DefaultRT", "name" : "@Author::PERLANCAR/Bugs::DefaultRT", "version" : "0.03" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@Author::PERLANCAR/Authors", "version" : "4.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@Author::PERLANCAR/Legal", "version" : "4.009" }, { "class" : "Pod::Weaver::Plugin::EnsureUniqueSections", "name" : "@Author::PERLANCAR/EnsureUniqueSections", "version" : "0.121550" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@Author::PERLANCAR/SingleEncoding", "version" : "4.009" } ] } }, "name" : "@Author::PERLANCAR/PodWeaver", "version" : "4.006" }, { "class" : "Dist::Zilla::Plugin::PruneFiles", "name" : "@Author::PERLANCAR/PruneFiles", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::ReadmeFromPod", "name" : "@Author::PERLANCAR/ReadmeFromPod", "version" : "0.30" }, { "class" : "Dist::Zilla::Plugin::Rinci::Validate", "name" : "@Author::PERLANCAR/Rinci::Validate", "version" : "0.20" }, { "class" : "Dist::Zilla::Plugin::SetScriptShebang", "name" : "@Author::PERLANCAR/SetScriptShebang", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::OurPkgVersion", "name" : "@Author::PERLANCAR/PERLANCAR::OurPkgVersion", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "bail_out_on_fail" : "0", "fail_on_warning" : "author", "fake_home" : "0", "filename" : "t/00-compile.t", "module_finder" : [ ":InstallModules" ], "needs_display" : "0", "phase" : "test", "script_finder" : [ ":ExecFiles" ], "skips" : [] } }, "name" : "@Author::PERLANCAR/Test::Compile", "version" : "2.051" }, { "class" : "Dist::Zilla::Plugin::Test::Rinci", "name" : "@Author::PERLANCAR/Test::Rinci", "version" : "0.01" }, { "class" : "Dist::Zilla::Plugin::PERLANCAR::GenTodoMd", "name" : "@Author::PERLANCAR/PERLANCAR::GenTodoMd", "version" : "0.03" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "5.029" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "5.029" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "5.029" } } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/Makefile.PL�����������������������������������������������������������������������0000644�0001750�0001750�00000002513�12461643144�013400� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.029. use strict; use warnings; use 5.010001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Record progress to any output", "AUTHOR" => "perlancar <perlancar\@cpan.org>", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "Perl::osnames" => "0.09" }, "DISTNAME" => "Progress-Any", "EXE_FILES" => [], "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.010001", "NAME" => "Progress::Any", "PREREQ_PM" => { "Time::Duration" => 0 }, "TEST_REQUIRES" => { "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::Exception" => 0, "Test::More" => "0.98" }, "VERSION" => "0.20", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Perl::osnames" => "0.09", "Test::Exception" => 0, "Test::More" => "0.98", "Time::Duration" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/dist.ini��������������������������������������������������������������������������0000644�0001750�0001750�00000000252�12461643144�013070� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������version=0.20 name=Progress-Any [@Author::PERLANCAR] :version=0.23 [Prereqs / TestRequires] Test::Exception=0 Test::More=0.98 [Prereqs] perl=5.010001 Time::Duration=0 ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/t/��������������������������������������������������������������������������������0000775�0001750�0001750�00000000000�12461643144�011672� 5����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/t/release-rinci.t�����������������������������������������������������������������0000644�0001750�0001750�00000000504�12461643144�014576� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Rinci 0.01"; plan skip_all => "Test::Rinci 0.01 required for testing Rinci metadata" if $@; metadata_in_all_modules_ok(); ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/t/01-basics.t���������������������������������������������������������������������0000644�0001750�0001750�00000015203�12461643144�013540� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/usr/bin/perl use 5.010; use strict; use warnings; use Progress::Any; use Test::More 0.98; use Test::Exception; use Time::HiRes qw(sleep); subtest "get_indicator, {total_,pos}, {total_,}target, percent_complete" => sub { %Progress::Any::indicators = (); my $p_ab = Progress::Any->get_indicator(task=>"a.b", target=>10); is($p_ab->pos, 0, "a.b's pos"); is($p_ab->total_pos, 0, "a.b's total_pos"); is($p_ab->target, 10, "a.b's target"); is($p_ab->total_target, 10, "a.b's total target"); is($p_ab->percent_complete, 0, "a.b's percent_complete"); my $p_a = Progress::Any->get_indicator(task=>"a"); is($p_a->pos, 0, "a's target"); is($p_a->total_pos, 0, "a's target"); is($p_a->target, 0, "a's target"); is($p_a->total_target, 10, "a's total target"); is($p_a->percent_complete, 0, "a's percent_complete"); my $p_ = Progress::Any->get_indicator(task=>""); is($p_->pos, 0, "root's target"); is($p_->total_pos, 0, "root's target"); is($p_->target, 0, "root's target"); is($p_->total_target, 10, "root's total target"); is($p_->percent_complete, 0, "root's percent_complete"); my $p_abd = Progress::Any->get_indicator(task=>"a.b.d", target=>7, pos=>2); is($p_abd->pos, 2, "a.b.d's pos"); is($p_abd->total_pos, 2, "a.b.d's total_pos"); is($p_abd->target, 7, "a.b.d's target"); is($p_abd->total_target, 7, "a.b.d's total target"); is(sprintf("%.0f", $p_abd->percent_complete), 29, "a.b.d's percent_complete"); is($p_ab->total_pos, 2, "a.b's total_pos"); is($p_ab->total_target, 17, "a.b's total target"); is(sprintf("%.0f", $p_ab->percent_complete), 12, "a.b's percent_complete"); is($p_a->total_pos, 2, "a's total pos"); is($p_a->total_target, 17, "a's total target"); is(sprintf("%.0f", $p_a->percent_complete), 12, "a's percent_complete"); is($p_->total_pos, 2, "root's total pos"); is($p_->total_target, 17, "root's total target"); is(sprintf("%.0f", $p_->percent_complete), 12, "root's percent_complete"); my $p_ac = Progress::Any->get_indicator(task=>"a.c", target=>5, pos=>1); is($p_ac->pos, 1, "a.c's pos"); is($p_ac->total_pos, 1, "a.c's total_pos"); is($p_ac->target, 5, "a.c's target"); is($p_ac->total_target, 5, "a.c's total target"); is(sprintf("%.0f", $p_ac->percent_complete), 20, "a.c's percent_complete"); is($p_a->total_pos, 3, "a's pos"); is($p_a->total_target, 22, "a's total target"); is(sprintf("%.0f", $p_a->percent_complete), 14, "a's percent_complete"); is($p_->total_pos, 3, "root's pos"); is($p_->total_target, 22, "root's total target"); is(sprintf("%.0f", $p_->percent_complete), 14, "root's percent_complete"); my $p_abe = Progress::Any->get_indicator(task=>"a.b.e", target=>undef); is($p_abe->pos, 0, "a.b.e's pos"); ok(!defined($p_abe->target), "a.b.e's target is undef"); ok(!defined($p_abe->percent_complete), "a.b.e's percent_complete is undef"); ok(!defined($p_ab->total_target), "a.b's total_target is undef"); ok(!defined($p_ab->percent_complete), "a.b's percent_complete is undef"); ok(!defined($p_a->total_target), "a's total_target is undef"); ok(!defined($p_a->percent_complete), "a's percent_complete is undef"); ok(!defined($p_->total_target), "root's total_target is undef"); ok(!defined($p_->percent_complete), "root's percent_complete is undef"); dies_ok { Progress::Any->get_indicator(task=>'a b') } 'invalid task in get_indicator() -> dies'; dies_ok { Progress::Any->get_indicator(task=>'foo', foo=>1) } 'unknown arg in get_indicator() -> dies'; dies_ok { Progress::Any->get_indicator(task=>'foo', target=>-1) } 'invalid target in get_indicator() -> dies'; dies_ok { Progress::Any->get_indicator(task=>'foo', pos=>-1) } 'invalid pos in get_indicator() -> dies'; }; subtest "update, state, elapsed, start, stop, finish" => sub { plan skip_all => "Temp. put in RELEASE_TESTING due to fragility of timing" unless $ENV{RELEASE_TESTING}; %Progress::Any::indicators = (); my $p = Progress::Any->get_indicator(task=>"a.b", target=>10); is($p->state, 'stopped', 'state before update() 1'); is($p->pos, 0, 'pos before update() 1'); sleep 0.05; is($p->elapsed, 0, "elapsed doesn't run before update() 1"); $p->update; is($p->state, 'started', 'state after update() 1'); is($p->pos, 1, 'pos after update() 1'); my $p_a = Progress::Any->get_indicator(task=>"a"); is($p_a->state, 'started', 'parent a is automatically started by update()'); my $p_ = Progress::Any->get_indicator(task=>""); is($p_->state, 'started', 'parent root is automatically started by update()'); sleep 1; is(sprintf("%.0f", $p->elapsed), "1", "elapsed runs after update() 1"); $p->stop; sleep 1; is(sprintf("%.0f", $p->elapsed), "1", "elapsed doesn't run after stop()"); $p->start; sleep 1; is(sprintf("%.0f", $p->elapsed), "2", "elapsed runs again after start()"); $p->update(pos=>8); is($p->pos, 8, "update() 2 with specified pos"); dies_ok { $p->update(foo=>1) } 'unknown arg in update() -> dies'; }; # XXX subtest remaining, set remaining, remaining_total subtest "fill_template" => sub { plan skip_all => "Currently release testing only due to timing-related and fail on some CT machines" unless $ENV{RELEASE_TESTING}; %Progress::Any::indicators = (); my $pa = Progress::Any->get_indicator(task=>"a", title=>"alf", target=>40); my $pb = Progress::Any->get_indicator(task=>"b", title=>"boo", target=>40); my $p_ = Progress::Any->get_indicator(task=>""); $pa->update(); sleep 0.05; is($pa->fill_template("%t"), "alf", "t"); is($pa->fill_template("%3n"), " a", "n, width"); is($pa->fill_template("%-3m", message=>"b"), "b ", "m, negative width"); is($pa->fill_template("%m"), "", "m defaults to ''"); is($pa->fill_template("%%"), "%", "%"); is($pa->fill_template("%%"), "%", "%"); is($pa->fill_template("%e"), "1s ", "e, default"); is($pa->fill_template("%2e"), "1s", "e, width"); like($pa->fill_template("%p%%"), qr/^ [23]%$/, "p"); # on most systems it's 2% but on some 3% is($p_->fill_template("%p%%"), " 1%", "p root"); is($pa->fill_template("%r"), "2s ", "r"); #is($p_->fill_template("%r"), "4s ", "r root"); is($pa->fill_template("%R"), "2s left ", "R"); $pa->target(undef); is($pa->fill_template("%R"), "1s elapsed ", "R"); is($pa->fill_template("%p"), " ?", "p unknown"); is($pa->fill_template("%T"), "?", "T unknown"); is($pa->fill_template("%z"), "%z", "unknown template returns as-is"); }; DONE_TESTING: done_testing; ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/t/release-pod-coverage.t����������������������������������������������������������0000644�0001750�0001750�00000000572�12461643144�016052� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); ��������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/t/00-compile.t��������������������������������������������������������������������0000644�0001750�0001750�00000002221�12461643144�013717� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.051 use Test::More; plan tests => 3 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Progress/Any.pm', 'Progress/Any/Output.pm', 'Progress/Any/Output/Null.pm' ); # no fake home requested my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L<perlfaq8/How can I capture STDERR from an external command?> my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/t/release-pod-syntax.t������������������������������������������������������������0000644�0001750�0001750�00000000456�12461643144�015606� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/weaver.ini������������������������������������������������������������������������0000644�0001750�0001750�00000000025�12461643144�013414� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������[@Author::PERLANCAR] �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Progress-Any-0.20/META.yml��������������������������������������������������������������������������0000644�0001750�0001750�00000024247�12461643144�012707� 0����������������������������������������������������������������������������������������������������ustar �u1������������������������������u1���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������--- abstract: 'Record progress to any output' author: - 'perlancar <perlancar@cpan.org>' build_requires: File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test::Exception: '0' Test::More: '0.98' configure_requires: ExtUtils::MakeMaker: '0' Perl::osnames: '0.09' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.029, CPAN::Meta::Converter version 2.143240' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Progress-Any requires: Time::Duration: '0' perl: '5.010001' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Progress-Any homepage: https://metacpan.org/release/Progress-Any repository: git://github.com/perlancar/perl-Progress-Any.git version: '0.20' x_Dist_Zilla: perl: version: '5.018001' plugins: - class: Dist::Zilla::Plugin::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] follow_symlinks: '0' include_dotfiles: '0' prefix: '' prune_directory: [] root: . name: '@Author::PERLANCAR/@Filter/GatherDir' version: '5.029' - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::PERLANCAR/@Filter/PruneCruft' version: '5.029' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::PERLANCAR/@Filter/ManifestSkip' version: '5.029' - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::PERLANCAR/@Filter/MetaYAML' version: '5.029' - class: Dist::Zilla::Plugin::License name: '@Author::PERLANCAR/@Filter/License' version: '5.029' - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Author::PERLANCAR/@Filter/PodCoverageTests' version: '5.029' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::PERLANCAR/@Filter/PodSyntaxTests' version: '5.029' - class: Dist::Zilla::Plugin::ExtraTests name: '@Author::PERLANCAR/@Filter/ExtraTests' version: '5.029' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::PERLANCAR/@Filter/ExecDir' version: '5.029' - class: Dist::Zilla::Plugin::ShareDir name: '@Author::PERLANCAR/@Filter/ShareDir' version: '5.029' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::PERLANCAR/@Filter/MakeMaker' version: '5.029' - class: Dist::Zilla::Plugin::Manifest name: '@Author::PERLANCAR/@Filter/Manifest' version: '5.029' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::PERLANCAR/@Filter/ConfirmRelease' version: '5.029' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Author::PERLANCAR/@Filter/UploadToCPAN' version: '5.029' - class: Dist::Zilla::Plugin::Rinci::AbstractFromMeta name: '@Author::PERLANCAR/Rinci::AbstractFromMeta' version: '0.06' - class: Dist::Zilla::Plugin::PodnameFromFilename name: '@Author::PERLANCAR/PodnameFromFilename' version: '0.01' - class: Dist::Zilla::Plugin::PERLANCAR::MetaResources name: '@Author::PERLANCAR/PERLANCAR::MetaResources' version: '0.03' - class: Dist::Zilla::Plugin::CheckChangeLog name: '@Author::PERLANCAR/CheckChangeLog' version: '0.02' - class: Dist::Zilla::Plugin::CheckMetaResources name: '@Author::PERLANCAR/CheckMetaResources' version: '0.001' - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::PERLANCAR/MetaJSON' version: '5.029' - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::PERLANCAR/MetaConfig' version: '5.029' - class: Dist::Zilla::Plugin::GenShellCompletion name: '@Author::PERLANCAR/GenShellCompletion' version: '0.07' - class: Dist::Zilla::Plugin::OurDate name: '@Author::PERLANCAR/OurDate' version: '0.02' - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.009' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.009' - class: Pod::Weaver::Section::Name name: '@Author::PERLANCAR/Name' version: '4.009' - class: Pod::Weaver::Section::Version name: '@Author::PERLANCAR/Version' version: '4.009' - class: Pod::Weaver::Section::Region name: '@Author::PERLANCAR/prelude' version: '4.009' - class: Pod::Weaver::Section::Generic name: SYNOPSIS version: '4.009' - class: Pod::Weaver::Section::Generic name: DESCRIPTION version: '4.009' - class: Pod::Weaver::Section::Generic name: OVERVIEW version: '4.009' - class: Pod::Weaver::Section::Collect name: ATTRIBUTES version: '4.009' - class: Pod::Weaver::Section::Collect name: METHODS version: '4.009' - class: Pod::Weaver::Section::Collect name: FUNCTIONS version: '4.009' - class: Pod::Weaver::Plugin::Rinci name: '@Author::PERLANCAR/Rinci' version: '0.29' - class: Pod::Weaver::Section::Leftovers name: '@Author::PERLANCAR/Leftovers' version: '4.009' - class: Pod::Weaver::Section::Region name: '@Author::PERLANCAR/postlude' version: '4.009' - class: Pod::Weaver::Section::Completion::GetoptLongComplete name: '@Author::PERLANCAR/Completion::GetoptLongComplete' version: '0.06' - class: Pod::Weaver::Section::Completion::PerinciCmdLine name: '@Author::PERLANCAR/Completion::PerinciCmdLine' version: '0.09' - class: Pod::Weaver::Section::Homepage::DefaultCPAN name: '@Author::PERLANCAR/Homepage::DefaultCPAN' version: '0.03' - class: Pod::Weaver::Section::Source::DefaultGitHub name: '@Author::PERLANCAR/Source::DefaultGitHub' version: '0.05' - class: Pod::Weaver::Section::Bugs::DefaultRT name: '@Author::PERLANCAR/Bugs::DefaultRT' version: '0.03' - class: Pod::Weaver::Section::Authors name: '@Author::PERLANCAR/Authors' version: '4.009' - class: Pod::Weaver::Section::Legal name: '@Author::PERLANCAR/Legal' version: '4.009' - class: Pod::Weaver::Plugin::EnsureUniqueSections name: '@Author::PERLANCAR/EnsureUniqueSections' version: '0.121550' - class: Pod::Weaver::Plugin::SingleEncoding name: '@Author::PERLANCAR/SingleEncoding' version: '4.009' name: '@Author::PERLANCAR/PodWeaver' version: '4.006' - class: Dist::Zilla::Plugin::PruneFiles name: '@Author::PERLANCAR/PruneFiles' version: '5.029' - class: Dist::Zilla::Plugin::ReadmeFromPod name: '@Author::PERLANCAR/ReadmeFromPod' version: '0.30' - class: Dist::Zilla::Plugin::Rinci::Validate name: '@Author::PERLANCAR/Rinci::Validate' version: '0.20' - class: Dist::Zilla::Plugin::SetScriptShebang name: '@Author::PERLANCAR/SetScriptShebang' version: '0.01' - class: Dist::Zilla::Plugin::PERLANCAR::OurPkgVersion name: '@Author::PERLANCAR/PERLANCAR::OurPkgVersion' version: '0.03' - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: bail_out_on_fail: '0' fail_on_warning: author fake_home: '0' filename: t/00-compile.t module_finder: - ':InstallModules' needs_display: '0' phase: test script_finder: - ':ExecFiles' skips: [] name: '@Author::PERLANCAR/Test::Compile' version: '2.051' - class: Dist::Zilla::Plugin::Test::Rinci name: '@Author::PERLANCAR/Test::Rinci' version: '0.01' - class: Dist::Zilla::Plugin::PERLANCAR::GenTodoMd name: '@Author::PERLANCAR/PERLANCAR::GenTodoMd' version: '0.03' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: '5.029' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '5.029' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '5.029' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '5.029' ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������