Smart-Comments-1.06/000755 000765 000024 00000000000 12612774076 014561 5ustar00neilbstaff000000 000000 Smart-Comments-1.06/Changes000644 000765 000024 00000003401 12612774076 016052 0ustar00neilbstaff000000 000000 Revision history for Perl module Smart::Comments 1.06 2015-10-24 NEILB - Added min perl version to code, so it will now appear in metadata - Added L<> links around the dependencies listed in the doc. RT#16456 - Fixed some failing tests reported from CPAN Testers 1.05_01 2015-10-22 NEILB - The test t/while_num.t was using subtests in a way that requires *I think* at least verson 0.99 of Test::More. This caused some CPAN Testers failures. Set min version on Test::More in just that test. - The github repo changed to reflect my changed github username 1.05_01 2015-10-20 NEILB - Reformatted as per CPAN::Changes::Spec, most recent release first. - Switched to Dist::Zilla - Added min perl version to code, so it will now appear in metadata - Added L<> links around the dependencies listed in the doc. RT#16456 1.000005 2013-07-19 DCONWAY - Fixed typo in docs - Fixed bad assumption (nolongdouble) in t/while_num.t 1.000004 2013-06-26 DCONWAY - Fixed bug in handling of and (thanks Fred) v1.0.3 2008-02-22 DCONWAY - Added -ENV config option (thanks Steven) - Added doc note about -MSmart::Comments approach (thanks David) - Smartened up vertical spacing of output (thanks Steve!) v1.0.2 2006-02-17 DCONWAY - Cleaned up bracket alignment when printing variable contents - Added [][] (and other bracket pairs) as valid fill sequences (thanks Jerrad) - Added , , etc. timespace stamps (thanks Tomi) 1.0.1 2005-05-25 DCONWAY - New release to override previous CPAN version 0.0.3 2005-05-24 DCONWAY - New release to reacquire CPAN ownership (thanks Autrijus) 0.0.2 2005-05-24 DCONWAY - No changes logged 0.01 2004-09-27 AUTRIJUS - Initial release. Smart-Comments-1.06/dist.ini000644 000765 000024 00000000444 12612774076 016227 0ustar00neilbstaff000000 000000 name = Smart-Comments author = Damian Conway license = Perl_5 copyright_holder = Damian Conway copyright_year = 2005 version = 1.06 [@Filter] -bundle = @Basic -remove = Readme [PkgVersion] [AutoPrereqs] [MetaJSON] [GithubMeta] [Git::Tag] tag_message= [Git::Push] Smart-Comments-1.06/lib/000755 000765 000024 00000000000 12612774076 015327 5ustar00neilbstaff000000 000000 Smart-Comments-1.06/LICENSE000644 000765 000024 00000043660 12612774076 015577 0ustar00neilbstaff000000 000000 This software is copyright (c) 2005 by Damian Conway. 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) 2005 by Damian Conway. 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) 2005 by Damian Conway. 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 Smart-Comments-1.06/Makefile.PL000644 000765 000024 00000002527 12612774076 016541 0ustar00neilbstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.037. use strict; use warnings; use 5.008; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Comments that do more than just sit there", "AUTHOR" => "Damian Conway ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Smart-Comments", "EXE_FILES" => [], "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008", "NAME" => "Smart::Comments", "PREREQ_PM" => { "Carp" => 0, "Data::Dumper" => 0, "Filter::Simple" => 0, "List::Util" => 0, "Text::Balanced" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Test::More" => "0.99" }, "VERSION" => "1.06", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Data::Dumper" => 0, "ExtUtils::MakeMaker" => 0, "Filter::Simple" => 0, "List::Util" => 0, "Test::More" => "0.99", "Text::Balanced" => 0, "strict" => 0, "warnings" => 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); Smart-Comments-1.06/MANIFEST000644 000765 000024 00000000771 12612774076 015717 0ustar00neilbstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.037. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Smart/Comments.pm t/00.load.t t/ENV_0.t t/ENV_1.t t/ENV_str.t t/assert.t t/brackets.t t/c_like_for_loop.t t/check.t t/confirm.t t/ensure.t t/insist.t t/labelled_perlish_loop.t t/message.t t/perlish_for.t t/perlish_for_percentage.t t/pod-coverage.t t/pod.t t/require.t t/selective.t t/simple_perlish_for.t t/var.t t/verify.t t/while.t t/while_num.t Smart-Comments-1.06/META.json000644 000765 000024 00000002377 12612774076 016213 0ustar00neilbstaff000000 000000 { "abstract" : "Comments that do more than just sit there", "author" : [ "Damian Conway " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Smart-Comments", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Data::Dumper" : "0", "Filter::Simple" : "0", "List::Util" : "0", "Text::Balanced" : "0", "perl" : "5.008", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Test::More" : "0.99" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/neilb/Smart-Comments", "repository" : { "type" : "git", "url" : "https://github.com/neilb/Smart-Comments.git", "web" : "https://github.com/neilb/Smart-Comments" } }, "version" : "1.06" } Smart-Comments-1.06/META.yml000644 000765 000024 00000001276 12612774076 016040 0ustar00neilbstaff000000 000000 --- abstract: 'Comments that do more than just sit there' author: - 'Damian Conway ' build_requires: Test::More: '0.99' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Smart-Comments requires: Carp: '0' Data::Dumper: '0' Filter::Simple: '0' List::Util: '0' Text::Balanced: '0' perl: '5.008' strict: '0' warnings: '0' resources: homepage: https://github.com/neilb/Smart-Comments repository: https://github.com/neilb/Smart-Comments.git version: '1.06' Smart-Comments-1.06/README000644 000765 000024 00000001266 12612774076 015446 0ustar00neilbstaff000000 000000 Smart::Comments Smart comments provide an easy way to insert debugging and tracking code into a program. They can report the value of a variable, track the progress of a loop, and verify that particular assertions are true. Best of all, when you're finished debugging, you don't have to remove them. Simply commenting out the C line turns them back into regular comments. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install COPYRIGHT AND LICENCE Copyright (C) 2005, Damian Conway This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Smart-Comments-1.06/t/000755 000765 000024 00000000000 12612774076 015024 5ustar00neilbstaff000000 000000 Smart-Comments-1.06/t/00.load.t000644 000765 000024 00000000201 12612774076 016337 0ustar00neilbstaff000000 000000 use Test::More tests => 1; BEGIN { use_ok( 'Smart::Comments' ); } diag( "Testing Smart::Comments $Smart::Comments::VERSION" ); Smart-Comments-1.06/t/assert.t000644 000765 000024 00000002440 12612774076 016512 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### assert: $x < '1' ok length $STDERR == 0 => 'True assertion is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 22. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### assert: $x < 0 }; ok $@ => 'False assertion is deadly'; ok $@ eq "\n" => 'False assertion is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False assertion is loud'; is $STDERR, $ASSERTION => 'False assertion is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 50. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### assert: $y < $x }; ok $@ => 'False two-part assertion is deadly'; ok $@ eq "\n" => 'False two-part assertion is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part assertion is loud'; is $STDERR, $ASSERTION2 => 'False two-part assertion is loudly correct'; Smart-Comments-1.06/t/brackets.t000644 000765 000024 00000001204 12612774076 017004 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; for my $ivar (1..20) { ### Simple for loop:[][] done $count++; is $ivar, $count => "Iteration $count"; } like $STDERR, qr/Simple for loop:\[ done\r/ => 'First iteration'; like $STDERR, qr/Simple for loop:\[\] done\r/ => 'Second iteration'; like $STDERR, qr/Simple for loop:\[\]\[ done\r/ => 'Thiird iteration'; Smart-Comments-1.06/t/c_like_for_loop.t000644 000765 000024 00000000746 12612774076 020345 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; LABEL: for (my $count=0;$count < 100;$count++) { ### C-like for loop:===| done # nothing } like $STDERR, qr/C-like for loop:| done\r/ => 'First iteration'; like $STDERR, qr/C-like for loop:=| done\r/ => 'Second iteration'; Smart-Comments-1.06/t/check.t000644 000765 000024 00000002155 12612774076 016271 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### check: $x < 1 ok length $STDERR == 0 => 'True check is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 26. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### check: $x < 0 }; ok !$@ => 'False check not deadly'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False check is loud'; is $STDERR, $ASSERTION => 'False check is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 55. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### check: $y < $x }; ok !$@ => 'False two-part check not deadly'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part check is loud'; is $STDERR, $ASSERTION2 => 'False two-part check is loudly correct'; Smart-Comments-1.06/t/confirm.t000644 000765 000024 00000002201 12612774076 016641 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### confirm: $x < 1 ok length $STDERR == 0 => 'True confirm is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 26. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### confirm: $x < 0 }; ok !$@ => 'False confirm not deadly'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False confirm is loud'; is $STDERR, $ASSERTION => 'False confirm is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 55. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### confirm: $y < $x }; ok !$@ => 'False two-part confirm not deadly'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part confirm is loud'; is $STDERR, $ASSERTION2 => 'False two-part confirm is loudly correct'; Smart-Comments-1.06/t/ensure.t000644 000765 000024 00000002401 12612774076 016507 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### ensure: $x < 1 ok length $STDERR == 0 => 'True ensure is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 22. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### ensure: $x < 0 }; ok $@ => 'False ensure is deadly'; ok $@ eq "\n" => 'False ensure is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False ensure is loud'; is $STDERR, $ASSERTION => 'False ensure is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 50. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### ensure: $y < $x }; ok $@ => 'False two-part ensure is deadly'; ok $@ eq "\n" => 'False two-part ensure is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part ensure is loud'; is $STDERR, $ASSERTION2 => 'False two-part ensure is loudly correct'; Smart-Comments-1.06/t/ENV_0.t000644 000765 000024 00000000435 12612774076 016062 0ustar00neilbstaff000000 000000 BEGIN { delete $ENV{Smart_Comments}; } use Smart::Comments -ENV; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; ### Testing 1... ### Testing 2... ### Testing 3... my $expected = q{}; is $STDERR, $expected => 'Silenced messages work'; Smart-Comments-1.06/t/ENV_1.t000644 000765 000024 00000000544 12612774076 016064 0ustar00neilbstaff000000 000000 BEGIN { $ENV{Smart_Comments} = 1; } use Smart::Comments -ENV; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; ### Testing 1... ### Testing 2... ### Testing 3... my $expected = <<"END_MESSAGES"; #\## Testing 1... #\## Testing 2... #\## Testing 3... END_MESSAGES is $STDERR, $expected => 'Messages work'; Smart-Comments-1.06/t/ENV_str.t000644 000765 000024 00000000537 12612774076 016536 0ustar00neilbstaff000000 000000 BEGIN { $ENV{Smart_Comments} = '###:#####'; } use Smart::Comments -ENV; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; ### Testing 1... #### Testing 2... ##### Testing 3... my $expected = <<"END_MESSAGES"; #\## Testing 1... #\## Testing 3... END_MESSAGES is $STDERR, $expected => 'Messages work'; Smart-Comments-1.06/t/insist.t000644 000765 000024 00000002401 12612774076 016517 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### insist: $x < 1 ok length $STDERR == 0 => 'True insist is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 22. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### insist: $x < 0 }; ok $@ => 'False insist is deadly'; ok $@ eq "\n" => 'False insist is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False insist is loud'; is $STDERR, $ASSERTION => 'False insist is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 50. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### insist: $y < $x }; ok $@ => 'False two-part insist is deadly'; ok $@ eq "\n" => 'False two-part insist is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part insist is loud'; is $STDERR, $ASSERTION2 => 'False two-part insist is loudly correct'; Smart-Comments-1.06/t/labelled_perlish_loop.t000644 000765 000024 00000001024 12612774076 021531 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; LABEL: for my $ivar (1..3) { ### Simple for loop:===| done $count++; is $ivar, $count => "Iteration $count"; } like $STDERR, qr/Simple for loop:| done\r/ => 'First iteration'; like $STDERR, qr/Simple for loop:=========| done\r/ => 'Second iteration'; Smart-Comments-1.06/t/message.t000644 000765 000024 00000000470 12612774076 016636 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; ### Testing 1... ### Testing 2... ### Testing 3... my $expected = <<"END_MESSAGES"; #\## Testing 1... #\## Testing 2... #\## Testing 3... END_MESSAGES is $STDERR, $expected => 'Messages work'; Smart-Comments-1.06/t/perlish_for.t000644 000765 000024 00000001013 12612774076 017520 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; for my $ivar (1..3) { ### Simple for loop:===| done $count++; is $ivar, $count => "Iteration $count"; } like $STDERR, qr/Simple for loop:| done\r/ => 'First iteration'; like $STDERR, qr/Simple for loop:=========| done\r/ => 'Second iteration'; Smart-Comments-1.06/t/perlish_for_percentage.t000644 000765 000024 00000001310 12612774076 021715 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; LABEL: for (1..5) { ### Simple for loop:===[%] done (%) # nothing } like $STDERR, qr/Simple for loop:\[0%\] done \(0%\)/ => 'First iteration'; like $STDERR, qr/Simple for loop:\[25%\] done \(25%\)/ => 'Second iteration'; like $STDERR, qr/Simple for loop:\[50%\] done \(50%\)/ => 'Third iteration'; like $STDERR, qr/Simple for loop:=\[75%\] done \(75%\)/ => 'Fourth iteration'; Smart-Comments-1.06/t/pod-coverage.t000644 000765 000024 00000000254 12612774076 017565 0ustar00neilbstaff000000 000000 #!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); Smart-Comments-1.06/t/pod.t000644 000765 000024 00000000214 12612774076 015770 0ustar00neilbstaff000000 000000 #!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Smart-Comments-1.06/t/require.t000644 000765 000024 00000002415 12612774076 016667 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### require: $x < 1 ok length $STDERR == 0 => 'True require is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 22. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### require: $x < 0 }; ok $@ => 'False require is deadly'; ok $@ eq "\n" => 'False require is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False require is loud'; is $STDERR, $ASSERTION => 'False require is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 50. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### require: $y < $x }; ok $@ => 'False two-part require is deadly'; ok $@ eq "\n" => 'False two-part require is deadly silent'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part require is loud'; is $STDERR, $ASSERTION2 => 'False two-part require is loudly correct'; Smart-Comments-1.06/t/selective.t000644 000765 000024 00000000500 12612774076 017167 0ustar00neilbstaff000000 000000 use Smart::Comments '###', '####', '######'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; ### ok 1 - Accepts 3 #'s... #### ok 2 - Accepts 4 #'s... ##### not ok 3 - Shouldn't accept 5 #'s... ###### ok 3 - Accepts 6 #'s... $STDERR =~ s/^###\s*//gm; $STDERR =~ s/^\s*\n//gxms; print "1..3\n", $STDERR; Smart-Comments-1.06/t/simple_perlish_for.t000644 000765 000024 00000001002 12612774076 021067 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; for (1..3) { ### Simple for loop:===| done $count++; is $_, $count => "Iteration $count"; } like $STDERR, qr/Simple for loop:| done\r/ => 'First iteration'; like $STDERR, qr/Simple for loop:=========| done\r/ => 'Second iteration'; Smart-Comments-1.06/t/var.t000644 000765 000024 00000001721 12612774076 016002 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $scalar = 'scalar value'; my @array = (1..3); my %hash = ('a'..'d'); ### $scalar ### @array; ### %hash my $expected = <<"END_MESSAGES"; #\## \$scalar: 'scalar value' #\## \@array: [ #\## 1, #\## 2, #\## 3 #\## ] #\## \%hash: { #\## a => 'b', #\## c => 'd' #\## } END_MESSAGES is $STDERR, $expected => 'Simple variables work'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; ### scalars: $scalar ### arrays: @array ### and hashes too: %hash my $expected2 = <<"END_MESSAGES"; #\## scalars: 'scalar value' #\## arrays: [ #\## 1, #\## 2, #\## 3 #\## ] #\## and hashes too: { #\## a => 'b', #\## c => 'd' #\## } END_MESSAGES is $STDERR, $expected2 => 'Labelled variables work'; Smart-Comments-1.06/t/verify.t000644 000765 000024 00000002167 12612774076 016523 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $x = 0; ### verify: $x < 1 ok length $STDERR == 0 => 'True verify is silent'; $ASSERTION = << 'END_ASSERT'; # $x < 0 was not true at FILE line 26. # $x was: 0 END_ASSERT $ASSERTION =~ s/#/###/g; eval { ### verify: $x < 0 }; ok !$@ => 'False verify not deadly'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False verify is loud'; is $STDERR, $ASSERTION => 'False verify is loudly correct'; close *STDERR; $STDERR = q{}; open *STDERR, '>', \$STDERR; my $y = []; $x = 10; my $ASSERTION2 = << 'END_ASSERTION2'; # $y < $x was not true at FILE line 55. # $y was: [] # $x was: 10 END_ASSERTION2 $ASSERTION2 =~ s/#/###/g; eval { ### verify: $y < $x }; ok !$@ => 'False two-part verify not deadly'; $STDERR =~ s/ at \S+ line / at FILE line /; ok length $STDERR != 0 => 'False two-part verify is loud'; is $STDERR, $ASSERTION2 => 'False two-part verify is loudly correct'; Smart-Comments-1.06/t/while.t000644 000765 000024 00000000725 12612774076 016325 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; LABEL: while ($count < 100) { ### Simple while loop:===| done $count++; } like $STDERR, qr/Simple while loop:| done\r/ => 'First iteration'; like $STDERR, qr/Simple while loop:=| done\r/ => 'Second iteration'; Smart-Comments-1.06/t/while_num.t000644 000765 000024 00000001251 12612774076 017177 0ustar00neilbstaff000000 000000 use Smart::Comments; use Test::More 0.99 'no_plan'; close *STDERR; my $STDERR = q{}; open *STDERR, '>', \$STDERR; my $count = 0; LABEL: while ($count < 100) { ### while:===[%] done (%) $count++; } close *STDERR; open *STDERR, '>-'; my $prev_count = -1; sub test_format_and_incr { my ($n, $output) = @_; subtest "Iteration $n" => sub { ok $output =~ m/while:=*\[(\d+)\]\s+done \(\1\)/ => 'Correct format'; my $count = $1; cmp_ok $count, '>', $prev_count => 'Correctly incremented'; $prev_count = $count; }; } my @outputs = grep /\S/, split /\r/, $STDERR; for my $n (0..5) { test_format_and_incr($n, $outputs[$n]); } Smart-Comments-1.06/lib/Smart/000755 000765 000024 00000000000 12612774076 016415 5ustar00neilbstaff000000 000000 Smart-Comments-1.06/lib/Smart/Comments.pm000644 000765 000024 00000077676 12612774076 020567 0ustar00neilbstaff000000 000000 package Smart::Comments; $Smart::Comments::VERSION = '1.06'; use 5.008; use warnings; use strict; use Carp; use List::Util qw(sum); use Filter::Simple; my $maxwidth = 69; # Maximum width of display my $showwidth = 35; # How wide to make the indicator my $showstarttime = 6; # How long before showing time-remaining estimate my $showmaxtime = 10; # Don't start estimate if less than this to go my $whilerate = 30; # Controls the rate at which while indicator grows my $minfillwidth = 5; # Fill area must be at least this wide my $average_over = 5; # Number of time-remaining estimates to average my $minfillreps = 2; # Minimum size of a fill and fill cap indicator my $forupdatequantum = 0.01; # Only update every 1% of elapsed distance # Synonyms for asserts and requirements... my $require = qr/require|ensure|assert|insist/; my $check = qr/check|verify|confirm/; # Horizontal whitespace... my $hws = qr/[^\S\n]/; # Optional colon... my $optcolon = qr/$hws*;?/; # Automagic debugging as well... my $DBX = '$DB::single = $DB::single = 1;'; # Implement comments-to-code source filter... FILTER { shift; # Don't need the package name s/\r\n/\n/g; # Handle win32 line endings # Default introducer pattern... my $intro = qr/#{3,}/; # Handle args... my @intros; while (@_) { my $arg = shift @_; if ($arg =~ m{\A -ENV \Z}xms) { my $env = $ENV{Smart_Comments} || $ENV{SMART_COMMENTS} || $ENV{SmartComments} || $ENV{SMARTCOMMENTS} ; return if !$env; # i.e. if no filtering if ($env !~ m{\A \s* 1 \s* \Z}xms) { unshift @_, split m{\s+|\s*:\s*}xms, $env; } } else { push @intros, $arg; } } if (my @unknowns = grep {!/$intro/} @intros) { croak "Incomprehensible arguments: @unknowns\n", "in call to 'use Smart::Comments'"; } # Make non-default introducer pattern... if (@intros) { $intro = '(?-x:'.join('|',@intros).')(?!\#)'; } # Preserve DATA handle if any... if (s{ ^ __DATA__ \s* $ (.*) \z }{}xms) { no strict qw< refs >; my $DATA = $1; open *{caller(1).'::DATA'}, '<', \$DATA or die "Internal error: $!"; } # Progress bar on a for loop... s{ ^ $hws* ( (?: [^\W\d]\w*: \s*)? for(?:each)? \s* (?:my)? \s* (?:\$ [^\W\d]\w*)? \s* ) \( ([^;\n]*?) \) \s* \{ [ \t]* $intro \s (.*) \s* $ } { _decode_for($1, $2, $3) }xgem; # Progress bar on a while loop... s{ ^ $hws* ( (?: [^\W\d]\w*: \s*)? (?:while|until) \s* \( .*? \) \s* ) \{ [ \t]* $intro \s (.*) \s* $ } { _decode_while($1, $2) }xgem; # Progress bar on a C-style for loop... s{ ^ $hws* ( (?: [^\W\d]\w*: \s*)? for \s* \( .*? ; .*? ; .*? \) \s* ) \{ $hws* $intro $hws (.*) $hws* $ } { _decode_while($1, $2) }xgem; # Requirements... s{ ^ $hws* $intro [ \t] $require : \s* (.*?) $optcolon $hws* $ } { _decode_assert($1,"fatal") }gemx; # Assertions... s{ ^ $hws* $intro [ \t] $check : \s* (.*?) $optcolon $hws* $ } { _decode_assert($1) }gemx; # Any other smart comment is a simple dump. # Dump a raw scalar (the varname is used as the label)... s{ ^ $hws* $intro [ \t]+ (\$ [\w:]* \w) $optcolon $hws* $ } {Smart::Comments::_Dump(pref=>q{$1:},var=>[$1]);$DBX}gmx; # Dump a labelled scalar... s{ ^ $hws* $intro [ \t] (.+ :) [ \t]* (\$ [\w:]* \w) $optcolon $hws* $ } {Smart::Comments::_Dump(pref=>q{$1},var=>[$2]);$DBX}gmx; # Dump a raw hash or array (the varname is used as the label)... s{ ^ $hws* $intro [ \t]+ ([\@%] [\w:]* \w) $optcolon $hws* $ } {Smart::Comments::_Dump(pref=>q{$1:},var=>[\\$1]);$DBX}gmx; # Dump a labelled hash or array... s{ ^ $hws* $intro [ \t]+ (.+ :) [ \t]* ([\@%] [\w:]* \w) $optcolon $hws* $ } {Smart::Comments::_Dump(pref=>q{$1},var=>[\\$2]);$DBX}gmx; # Dump a labelled expression... s{ ^ $hws* $intro [ \t]+ (.+ :) (.+) } {Smart::Comments::_Dump(pref=>q{$1},var=>[$2]);$DBX}gmx; # Dump an 'in progress' message s{ ^ $hws* $intro $hws* (.+ [.]{3}) $hws* $ } {Smart::Comments::_Dump(pref=>qq{$1});$DBX}gmx; # Dump an unlabelled expression (the expression is used as the label)... s{ ^ $hws* $intro $hws* (.*) $optcolon $hws* $ } {Smart::Comments::_Dump(pref=>q{$1:},var=>Smart::Comments::_quiet_eval(q{[$1]}));$DBX}gmx; # An empty comment dumps an empty line... s{ ^ $hws* $intro [ \t]+ $ } {warn qq{\n};}gmx; # Anything else is a literal string to be printed... s{ ^ $hws* $intro $hws* (.*) } {Smart::Comments::_Dump(pref=>q{$1});$DBX}gmx; }; sub _quiet_eval { local $SIG{__WARN__} = sub{}; return scalar eval shift; } sub _uniq { my %seen; grep { !$seen{$_}++ } @_ } # Converts an assertion to the equivalent Perl code... sub _decode_assert { my ($assertion, $fatal) = @_; # Choose the right signalling mechanism... $fatal = $fatal ? 'die "\n"' : 'warn "\n"'; my $dump = 'Smart::Comments::_Dump'; use Text::Balanced qw(extract_variable extract_multiple); # Extract variables from assertion and enreference any arrays or hashes... my @vars = map { /^$hws*[%\@]/ ? "$dump(pref=>q{ $_ was:},var=>[\\$_], nonl=>1);" : "$dump(pref=>q{ $_ was:},var=>[$_],nonl=>1);" } _uniq extract_multiple($assertion, [\&extract_variable], undef, 1); # Generate the test-and-report code... return qq{unless($assertion){warn "\\n", q{### $assertion was not true};@vars; $fatal}}; } # Generate progress-bar code for a Perlish for loop... my $ID = 0; sub _decode_for { my ($for, $range, $mesg) = @_; # Give the loop a unique ID... $ID++; # Rewrite the loop with a progress bar as its first statement... return "my \$not_first__$ID;$for (my \@SmartComments__range__$ID = $range) { Smart::Comments::_for_progress(qq{$mesg}, \$not_first__$ID, \\\@SmartComments__range__$ID);"; } # Generate progress-bar code for a Perlish while loop... sub _decode_while { my ($while, $mesg) = @_; # Give the loop a unique ID... $ID++; # Rewrite the loop with a progress bar as its first statement... return "my \$not_first__$ID;$while { Smart::Comments::_while_progress(qq{$mesg}, \\\$not_first__$ID);"; } # Generate approximate time descriptions... sub _desc_time { my ($seconds) = @_; my $hours = int($seconds/3600); $seconds -= 3600*$hours; my $minutes = int($seconds/60); $seconds -= 60*$minutes; my $remaining; # Describe hours to the nearest half-hour (and say how close to it)... if ($hours) { $remaining = $minutes < 5 ? "about $hours hour".($hours==1?"":"s") : $minutes < 25 ? "less than $hours.5 hours" : $minutes < 35 ? "about $hours.5 hours" : $minutes < 55 ? "less than ".($hours+1)." hours" : "about ".($hours+1)." hours"; } # Describe minutes to the nearest minute elsif ($minutes) { $remaining = "about $minutes minutes"; chop $remaining if $minutes == 1; } # Describe tens of seconds to the nearest ten seconds... elsif ($seconds > 10) { $seconds = int(($seconds+5)/10); $remaining = "about ${seconds}0 seconds"; } # Never be more accurate than ten seconds... else { $remaining = "less than 10 seconds"; } return $remaining; } # Update the moving average of a series given the newest measurement... my %started; my %moving; sub _moving_average { my ($context, $next) = @_; my $moving = $moving{$context} ||= []; push @$moving, $next; if (@$moving >= $average_over) { splice @$moving, 0, $#$moving-$average_over; } return sum(@$moving)/@$moving; } # Recognize progress bars... my @progress_pats = ( # left extending end marker of bar right # anchor bar ("fill") | gap after bar anchor # ====== ======================= === ================= ==== qr{^(\s*.*?) (\[\]\[\]) () \s* (\S?.*)}x, qr{^(\s*.*?) (\(\)\(\)) () \s* (\S?.*)}x, qr{^(\s*.*?) (\{\}\{\}) () \s* (\S?.*)}x, qr{^(\s*.*?) (\<\>\<\>) () \s* (\S?.*)}x, qr{^(\s*.*?) (?>(\S)\2{$minfillreps,}) (\S+) \s{$minfillreps,} (\S.*)}x, qr{^(\s*.*?) (?>(\S)\2{$minfillreps,}) () \s{$minfillreps,} (\S.*)}x, qr{^(\s*.*?) (?>(\S)\2{$minfillreps,}) (\S*) (?=\s*$)}x, qr{^(\s*.*?) () () () \s*$ }x, ); # Clean up components of progress bar (inserting defaults)... sub _prog_pat { for my $pat (@progress_pats) { $_[0] =~ $pat or next; return ($1, $2||"", $3||"", $4||""); } return; } # State information for various progress bars... my (%count, %max, %prev_elapsed, %prev_fraction, %showing); # Animate the progress bar of a for loop... sub _for_progress { my ($mesg, $not_first, $data) = @_; my ($at, $max, $elapsed, $remaining, $fraction); # Update progress bar... if ($not_first) { # One more iteration towards the maximum... $at = ++$count{$data}; $max = $max{$data}; # How long now (both absolute and relative)... $elapsed = time - $started{$data}; $fraction = $max>0 ? $at/$max : 1; # How much change occurred... my $motion = $fraction - $prev_fraction{$data}; # Don't update if count wrapped (unlikely) or if finished # or if no visible change... return unless $not_first < 0 || $at == $max || $motion > $forupdatequantum; # Guestimate how long still to go... $remaining = _moving_average $data, $fraction ? $elapsed/$fraction-$elapsed : 0; } # If first iteration... else { # Start at the beginning... $at = $count{$data} = 0; # Work out where the end will be... $max = $max{$data} = $#$data; # Start the clock... $started{$data} = time; $elapsed = 0; $fraction = 0; # After which, it will no longer be the first iteration. $_[1] = 1; # $not_first } # Remember the previous increment fraction... $prev_fraction{$data} = $fraction; # Now draw the progress bar (if it's a valid one)... if (my ($left, $fill, $leader, $right) = _prog_pat($mesg)) { # Insert the percentage progress in place of a '%'... s/%/int(100*$fraction).'%'/ge for ($left, $leader, $right); # Work out how much space is available for the bar itself... my $fillwidth = $showwidth - length($left) - length($right); # But no less than the prespecified minimum please... $fillwidth = $minfillwidth if $fillwidth < $minfillwidth; # Make enough filler... my $totalfill = $fill x $fillwidth; # How big is the end of the bar... my $leaderwidth = length($leader); # Truncate where? my $fillend = $at==$max ? $fillwidth : $fillwidth*$fraction-$leaderwidth; $fillend = 0 if $fillend < 0; # Now draw the bar, using carriage returns to overwrite it... print STDERR "\r", " "x$maxwidth, "\r", $left, sprintf("%-${fillwidth}s", substr($totalfill, 0, $fillend) . $leader), $right; # Work out whether to show an ETA estimate... if ($elapsed >= $showstarttime && $at < $max && ($showing{$data} || $remaining && $remaining >= $showmaxtime) ) { print STDERR " (", _desc_time($remaining), " remaining)"; $showing{$data} = 1; } # Close off the line, if we're finished... print STDERR "\r", " "x$maxwidth, "\n" if $at >= $max; } } my %shown; my $prev_length = -1; # Animate the progress bar of a while loop... sub _while_progress { my ($mesg, $not_first_ref) = @_; my $at; # If we've looped this one before, recover the current iteration count... if ($$not_first_ref) { $at = ++$count{$not_first_ref}; } # Otherwise set the iteration count to zero... else { $at = $count{$not_first_ref} = 0; $$not_first_ref = 1; } # Extract the components of the progress bar... if (my ($left, $fill, $leader, $right) = _prog_pat($mesg)) { # Replace any '%' with the current iteration count... s/%/$at/ge for ($left, $leader, $right); # How much space is there for the progress bar? my $fillwidth = $showwidth - length($left) - length($right); # Make it at least the prespecified minimum amount... $fillwidth = $minfillwidth if $fillwidth < $minfillwidth; # How big is the end of the bar? my $leaderwidth = length($leader); # How big does that make the bar itself (use reciprocal growth)... my $length = int(($fillwidth-$leaderwidth) *(1-$whilerate/($whilerate+$at))); # Don't update if the picture would look the same... return if length $fill && $prev_length == $length; # Otherwise, remember where we got to... $prev_length = $length; # And print the bar... print STDERR "\r", " "x$maxwidth, "\r", $left, sprintf("%-${fillwidth}s", substr($fill x $fillwidth, 0, $length) . $leader), $right; } } # Vestigal (I think)... #sub Assert { # my %arg = @_; # return unless $arg{pass} #} use Data::Dumper 'Dumper'; # Dump a variable and then reformat the resulting string more prettily... my $prev_STDOUT = 0; my $prev_STDERR = 0; my %prev_caller = ( file => q{}, line => 0 ); sub _Dump { my %args = @_; my ($pref, $varref, $nonl) = @args{qw(pref var nonl)}; # Handle timestamps and spacestamps... my (undef, $file, $line) = caller; $pref =~ s/<(?:now|time|when)>/scalar localtime()/ge; $pref =~ s/<(?:here|place|where)>/"$file", line $line/g; $pref =~ s/<(?:file)>/$file/g; $pref =~ s/<(?:line)>/$line/g; # Add a newline? my @caller = caller; my $spacer_required = $prev_STDOUT != tell(*STDOUT) || $prev_STDERR != tell(*STDERR) || $prev_caller{file} ne $caller[1] || $prev_caller{line} != $caller[2]-1; $spacer_required &&= !$nonl; @prev_caller{qw} = @caller[1,2]; # Handle a prefix with no actual variable... if ($pref && !defined $varref) { $pref =~ s/:$//; print STDERR "\n" if $spacer_required; warn "### $pref\n"; $prev_STDOUT = tell(*STDOUT); $prev_STDERR = tell(*STDERR); return; } # Set Data::Dumper up for a tidy dump and do the dump... local $Data::Dumper::Quotekeys = 0; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Indent = 2; my $dumped = Dumper $varref; # Clean up the results... $dumped =~ s/\$VAR1 = \[\n//; $dumped =~ s/\s*\];\s*$//; $dumped =~ s/\A(\s*)//; # How much to shave off and put back on each line... my $indent = length $1; my $outdent = " " x (length($pref) + 1); # Report "inside-out" and "flyweight" objects more cleanly... $dumped =~ s{bless[(] do[{]\\[(]my \$o = undef[)][}], '([^']+)' [)]} {}g; # Adjust the indents... $dumped =~ s/^[ ]{$indent}([ ]*)/### $outdent$1/gm; # Print the message... print STDERR "\n" if $spacer_required; warn "### $pref $dumped\n"; $prev_STDERR = tell(*STDERR); $prev_STDOUT = tell(*STDOUT); } 1; # Magic true value required at end of module __END__ =head1 NAME Smart::Comments - Comments that do more than just sit there =head1 VERSION This document describes Smart::Comments version 1.000005 =head1 SYNOPSIS use Smart::Comments; my $var = suspect_value(); ### $var ### got: $var ### Now computing value... # and when looping: for my $big_num (@big_nums) { ### Factoring... done factor($big_num); } while ($error > $tolerance) { ### Refining---> done refine_approximation() } for (my $i=0; $i<$MAX_INT; $i++) { ### Working===[%] done do_something_expensive_with($i); } =head1 DESCRIPTION Smart comments provide an easy way to insert debugging and tracking code into a program. They can report the value of a variable, track the progress of a loop, and verify that particular assertions are true. Best of all, when you're finished debugging, you don't have to remove them. Simply commenting out the C line turns them back into regular comments. Leaving smart comments in your code is smart because if you needed them once, you'll almost certainly need them again later. =head1 INTERFACE All smart comments start with three (or more) C<#> characters. That is, they are regular C<#>-introduced comments whose first two (or more) characters are also C<#>'s. =head2 Using the Module The module is loaded like any other: use Smart::Comments; When loaded it filters the remaining code up to the next: no Smart::Comments; directive, replacing any smart comments with smart code that implements the comments behaviour. If you're debugging an application you can also invoke it with the module from the command-line: perl -MSmart::Comments $application.pl Of course, this only enables smart comments in the application file itself, not in any modules that the application loads. You can also specify particular levels of smartness, by including one or more markers as arguments to the C: use Smart::Comments '###', '####'; These arguments tell the module to filter only those comments that start with the same number of C<#>'s. So the above C statement would "activate" any smart comments of the form: ### Smart... #### Smarter... but not those of the form: ##### Smartest... This facility is useful for differentiating progress bars (see L), which should always be active, from debugging comments (see L), which should not: #### Debugging here... for (@values) { ### Progress: 0... 100 do_stuff(); } Note that, for simplicity, all smart comments described below will be written with three C<#>'s; in all such cases, any number of C<#>'s greater than three could be used instead. =head2 Debugging via Comments The simplest way to use smart comments is for debugging. The module supports the following forms, all of which print to C: =over =item C<< ### LABEL : EXPRESSION >> The LABEL is any sequence of characters up to the first colon. The EXPRESSION is any valid Perl expression, including a simple variable. When active, the comment prints the label, followed by the value of the expression. For example: ### Expected: 2 * $prediction ### Got: $result prints: ### Expected: 42 ### Got: 13 =item C<< ### EXPRESSION >> The EXPRESSION is any valid Perl expression, including a simple variable. When active, the comment prints the expression, followed by the value of the expression. For example: ### 2 * $prediction ### $result prints: ### 2 * $prediction: 42 ### $result: 13 =item C<< ### TEXT... >> The TEXT is any sequence of characters that end in three dots. When active, the comment just prints the text, including the dots. For example: ### Acquiring data... $data = get_data(); ### Verifying data... verify_data($data); ### Assimilating data... assimilate_data($data); ### Tired now, having a little lie down... sleep 900; would print: ### Acquiring data... ### Verifying data... ### Assimilating data... ### Tired now, having a little lie down... as each phase commenced. This is particularly useful for tracking down precisely where a bug is occurring. It is also useful in non-debugging situations, especially when batch processing, as a simple progress feedback mechanism. Within a textual smart comment you can use the special sequence C<< >> (or C<<