Filter-Template-1.043/000755 000765 000024 00000000000 12202157413 014626 5ustar00trocstaff000000 000000 Filter-Template-1.043/CHANGES000644 000765 000024 00000002047 12202157413 015624 0ustar00trocstaff000000 000000 ================================================== Changes from 2012-08-12 00:00:00 +0000 to present. ================================================== ------------------------------------------ version 1.042 at 2013-08-10 22:10:38 +0000 ------------------------------------------ Change: e94ca1960e5f547c5e21fc43e97209121954f369 Author: Rocco Caputo Date : 2013-08-10 18:10:38 +0000 Update dist.ini for new workflow. ------------------------------------------ version 1.041 at 2013-08-04 19:25:34 +0000 ------------------------------------------ Change: 18e53d8bfd46f9add20d97d89cca452c64952ce1 Author: Rocco Caputo Date : 2013-08-04 15:25:34 +0000 Switch to Dist::Zilla. Change: 0327b134cb40abe2ace03803b6eb9e2169112372 Author: Rocco Caputo Date : 2010-03-08 02:46:49 +0000 Add a MANIFEST. Not sure where it went. ================================================ Plus 5 releases after 2012-08-12 00:00:00 +0000. ================================================ Filter-Template-1.043/dist.ini000644 000765 000024 00000001407 12202157413 016274 0ustar00trocstaff000000 000000 name = Filter-Template author = Rocco Caputo copyright_holder = Rocco Caputo license = Perl_5 [AutoMetaResources] bugtracker.rt = 1 license = http://dev.perl.org/licenses/ repository.github = user:rcaputo [AutoPrereqs] [CheckPrereqsIndexed] [Prereqs::MatchInstalled::All] exclude = bytes exclude = constant exclude = lib exclude = perl exclude = strict exclude = vars exclude = warnings [Homepage] [ReadmeFromPod] [ReadmeMarkdownFromPod] [ReportVersions] [Repository] git_remote = gh [Git::Check] [Git::NextVersion] first_version = 1.041 version_regexp = ^v(\d+\.\d+)$ [ChangelogFromGit] tag_regexp = v(\d+[_.]\d+) [Git::Tag] tag_format = v%v tag_message = Release %v. [@Classic] [MetaJSON] Filter-Template-1.043/lib/000755 000765 000024 00000000000 12202157413 015374 5ustar00trocstaff000000 000000 Filter-Template-1.043/LICENSE000644 000765 000024 00000043744 12202157413 015647 0ustar00trocstaff000000 000000 This software is copyright (c) 2013 by Rocco Caputo . 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) 2013 by Rocco Caputo . 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, Suite 500, Boston, MA 02110-1335 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) 2013 by Rocco Caputo . 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 Filter-Template-1.043/Makefile.PL000644 000765 000024 00000003115 12202157413 016600 0ustar00trocstaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "a source filter for inline code templates (macros)", "AUTHOR" => "Rocco Caputo ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Filter-Template", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Filter::Template", "PREREQ_PM" => { "Carp" => "1.26", "Filter::Util::Call" => "1.49", "Symbol" => "1.06", "bytes" => 0, "constant" => 0, "strict" => 0, "vars" => 0 }, "TEST_REQUIRES" => { "Scalar::Util" => "1.29", "Test::More" => "0.98", "lib" => 0, "warnings" => 0 }, "VERSION" => "1.043", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Filter-Template-1.043/MANIFEST000644 000765 000024 00000000377 12202157413 015766 0ustar00trocstaff000000 000000 CHANGES LICENSE MANIFEST MANIFEST.SKIP META.json META.yml Makefile.PL README README.mkdn dist.ini lib/Filter/Template.pm lib/Filter/Template/UseBytes.pm t/000-report-versions.t t/01_inline.t t/02_usebytes.t t/release-pod-coverage.t t/release-pod-syntax.t Filter-Template-1.043/MANIFEST.SKIP000600 000765 000024 00000000452 12202157413 016515 0ustar00trocstaff000000 000000 CVS \.\# \.bak$ \.cvsignore \.gz$ \.orig$ \.patch$ \.ppd$ \.rej$ \.rej$ \.svn \.swo$ \.swp$ \.tmp$ ^Makefile$ ^Makefile\.old$ ^POE.ppd$ ^\. ^_Inline ^_build ^blib/ ^comptest ^cover_db/ ^coverage\.report$ ^docs ^pm_to_blib$ ^poe_report\.xml$ run_network_tests test-output\.err$ tests/[23]0_.*\.t ~$ Filter-Template-1.043/META.json000644 000765 000024 00000003432 12202157413 016251 0ustar00trocstaff000000 000000 { "abstract" : "a source filter for inline code templates (macros)", "author" : [ "Rocco Caputo " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300035, CPAN::Meta::Converter version 2.132140", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Filter-Template", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "1.26", "Filter::Util::Call" : "1.49", "Symbol" : "1.06", "bytes" : "0", "constant" : "0", "strict" : "0", "vars" : "0" } }, "test" : { "requires" : { "Scalar::Util" : "1.29", "Test::More" : "0.98", "lib" : "0", "perl" : "5.004", "warnings" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Filter-Template@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Filter-Template" }, "homepage" : "http://search.cpan.org/dist/Filter-Template/", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/rcaputo/filter-template.git", "web" : "https://github.com/rcaputo/filter-template" } }, "version" : "1.043" } Filter-Template-1.043/META.yml000644 000765 000024 00000001531 12202157413 016077 0ustar00trocstaff000000 000000 --- abstract: 'a source filter for inline code templates (macros)' author: - 'Rocco Caputo ' build_requires: Scalar::Util: 1.29 Test::More: 0.98 lib: 0 perl: 5.004 warnings: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300035, CPAN::Meta::Converter version 2.132140' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Filter-Template requires: Carp: 1.26 Filter::Util::Call: 1.49 Symbol: 1.06 bytes: 0 constant: 0 strict: 0 vars: 0 resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Filter-Template homepage: http://search.cpan.org/dist/Filter-Template/ license: http://dev.perl.org/licenses/ repository: git://github.com/rcaputo/filter-template.git version: 1.043 Filter-Template-1.043/README000644 000765 000024 00000017355 12202157413 015521 0ustar00trocstaff000000 000000 NAME Filter::Template - a source filter for inline code templates (macros) VERSION version 1.043 SYNOPSIS use Filter::Template; # use Filter::Template ( isa => 'SomeModule' ); template max (one,two) { ((one) > (two) ? (one) : (two)) } print {% max $one, $two %}, "\n"; const PI 3.14159265359 print "PI\n"; # Constants are expanded inside strings. print "HAPPINESS\n"; # Also expanded due to naive parser. enum ZERO ONE TWO enum 12 TWELVE THIRTEEN FOURTEEN enum + FIFTEEN SIXTEEN SEVENTEEN # Prints numbers, due to naive parser. print "ZERO ONE TWO TWELVE THIRTEEN FOURTEEN FIFTEEN SIXTEEN SEVENTEEN\n"; if ($expression) { # include ... lines of code ... } # include unless ($expression) { # include ... lines of code ... } elsif ($expression) { # include ... lines of code ... } else { # include ... lines of code ... } # include DESCRIPTION Filter::Template is a Perl source filter that provides simple inline source code templates. Inlined source code can be significantly faster than subroutines, especially for small-scale functions like accessors and mutators. On the other hand, they are more difficult to maintain and use. Choose your trade-offs wisely. Templates Code templates are defined with the "template" statement, which looks a lot like "sub". Because this is a naive source filter, however, the open brace must be on the same line as the "template" keyword. Furthermore, the first closing brace in column zero ends a macro body. template oops { die "Oops"; } Templates are inserted into a program using a simple syntax that was adapted from other template libraries. It was chosen to be compatible with the Perl syntax highlighting of common text editors. This inserts the body of "template oops". {% oops %} Templates can have parameters. The syntax for template parameters was based on prototypes for Perl subroutines. The two main differences are that parameters are named, and sigils are not used. template sum_2 (parameter_0, parameter_1) { print( parameter_0 + parameter_1, "\n" ); } To insert a template with parameters, simply list the parameters after the template name. {% sum_2 $base, $increment %} At expansion time, occurrences of the parameter names within the template are replaced with the source code provided in the template invocation. In the previous example, "sum_2" literally expands to print( $base + $increment, "\n" ); and is then compiled by Perl. Constants and Enumerations Filter::Template also defines "const" and "enum" keywords. They are essentially simplified templates without parameters. "const" defines a constant that is replaced before compile time. Unlike Perl's native constants, these are not demoted to function calls when Perl is run in debugging or profiling mode. const CONSTANT_NAME 'constant value' const ANOTHER_CONSTANT 23 Enumerations are like constants but several sequential integers can be defined in one statement. Enumerations start from zero by default: enum ZEROTH FIRST SECOND If the first parameter of an enumeration is a number, then the enumerated constants will start with that value: enum 10 TENTH ELEVENTH TWELFTH Enumerations may not span lines, but they can be continued. If the first enumeration parameter is the plus sign, then constants will start where the previous enumeration left off. enum 13 THIRTEENTH FOURTEENTH FIFTEENTH enum + SIXTEENTH SEVENTEENTH EIGHTEENTH Conditional Code Inclusion (#ifdef) The preprocessor supports something like cpp's #if/#else/#endif by usurping a bit of Perl's conditional syntax. The following conditional statements will be evaluated at compile time if they are followed by the comment "# include": if (EXPRESSION) { # include BLOCK; } elsif (EXPRESSION) { # include BLOCK; } else { # include BLOCK; } # include unless (EXPRESSION) { # include BLOCK; } # include The code in each conditional statement's BLOCK will be included or excluded in the compiled code depending on the outcome of its EXPRESSION. Conditional includes are nestable, but else and elsif must be on the same line as the previous block's closing brace, as they are in the previous example. Filter::Template::UseBytes uses conditional code to define different versions of a {% use_bytes %} macro depending whether the "bytes" pragma exists. IMPORTING TEMPLATES Filter::Template can import templates defined by another class. For example, this invocation imports the "use_bytes" template: use Filter::Template ( isa => 'Filter::Template::UseBytes' ); Imported templates can be redefined in the current namespace. Note: If the imported templates require additional Perl modules, any code which imports them must also "use" those modules. DEBUGGING Filter::Template has three debugging constants which will only take effect if they are defined before the module is first used. To trace source filtering in general, and to see the resulting code and operations performed on each line, define: sub Filter::Template::DEBUG () { 1 } To trace template invocations as they happen, define: sub Filter::Template::DEBUG_INVOKE () { 1 } To see template, constant, and enum definitions, define: sub Filter::Template::DEBUG_DEFINE () { 1 } To see warnings when a template or constant is redefined, define: sub Filter::Template::DEFINE () { 1 } CAVEATS Source filters are line-based, and so is the template language. The only constructs that may span lines are template definitions, and those must span lines. Filter::Template does not parse perl. The regular expressions that detect and replace code are simplistic and may not do the right things when parsing challenging Perl syntax. Constants are replaced within strings, for example. The regexp optimizer makes silly subexpressions like /(?:|m)/. That could be done better as /m?/ or /(?:jklm)?/ if the literal is longer than a single character. The regexp optimizer does not optimize (?:x|y|z) as character classes. The regexp optimizer is based on code in Ilya Zakharevich's Text::Trie. Better regexp optimizers were released afterwards, and Filter::Template should use one of them. LINKS BUG TRACKER https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Filter-Templat e REPOSITORY http://github.com/rcaputo/filter-template http://gitorious.org/filter-template OTHER RESOURCES http://search.cpan.org/dist/Filter-Template/ SEE ALSO Text::Trie, PAR, Filter::Template::UseBytes. AUTHOR & COPYRIGHT Filter::Template is Copyright 2000-2013 Rocco Caputo. Some parts are Copyright 2001 Matt Cashner. All rights reserved. Filter::Template is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Filter::Template was previously known as POE::Preprocessor. Filter-Template-1.043/README.mkdn000644 000765 000024 00000015725 12202157413 016450 0ustar00trocstaff000000 000000 # NAME Filter::Template - a source filter for inline code templates (macros) # VERSION version 1.043 # SYNOPSIS use Filter::Template; # use Filter::Template ( isa => 'SomeModule' ); template max (one,two) { ((one) > (two) ? (one) : (two)) } print {% max $one, $two %}, "\n"; const PI 3.14159265359 print "PI\n"; # Constants are expanded inside strings. print "HAPPINESS\n"; # Also expanded due to naive parser. enum ZERO ONE TWO enum 12 TWELVE THIRTEEN FOURTEEN enum + FIFTEEN SIXTEEN SEVENTEEN # Prints numbers, due to naive parser. print "ZERO ONE TWO TWELVE THIRTEEN FOURTEEN FIFTEEN SIXTEEN SEVENTEEN\n"; if ($expression) { # include ... lines of code ... } # include unless ($expression) { # include ... lines of code ... } elsif ($expression) { # include ... lines of code ... } else { # include ... lines of code ... } # include # DESCRIPTION Filter::Template is a Perl source filter that provides simple inline source code templates. Inlined source code can be significantly faster than subroutines, especially for small-scale functions like accessors and mutators. On the other hand, they are more difficult to maintain and use. Choose your trade-offs wisely. ## Templates Code templates are defined with the `template` statement, which looks a lot like `sub`. Because this is a naive source filter, however, the open brace must be on the same line as the `template` keyword. Furthermore, the first closing brace in column zero ends a macro body. template oops { die "Oops"; } Templates are inserted into a program using a simple syntax that was adapted from other template libraries. It was chosen to be compatible with the Perl syntax highlighting of common text editors. This inserts the body of `template oops`. {% oops %} Templates can have parameters. The syntax for template parameters was based on prototypes for Perl subroutines. The two main differences are that parameters are named, and sigils are not used. template sum_2 (parameter_0, parameter_1) { print( parameter_0 + parameter_1, "\n" ); } To insert a template with parameters, simply list the parameters after the template name. {% sum_2 $base, $increment %} At expansion time, occurrences of the parameter names within the template are replaced with the source code provided in the template invocation. In the previous example, `sum_2` literally expands to print( $base + $increment, "\n" ); and is then compiled by Perl. ## Constants and Enumerations Filter::Template also defines `const` and `enum` keywords. They are essentially simplified templates without parameters. `const` defines a constant that is replaced before compile time. Unlike Perl's native constants, these are not demoted to function calls when Perl is run in debugging or profiling mode. const CONSTANT_NAME 'constant value' const ANOTHER_CONSTANT 23 Enumerations are like constants but several sequential integers can be defined in one statement. Enumerations start from zero by default: enum ZEROTH FIRST SECOND If the first parameter of an enumeration is a number, then the enumerated constants will start with that value: enum 10 TENTH ELEVENTH TWELFTH Enumerations may not span lines, but they can be continued. If the first enumeration parameter is the plus sign, then constants will start where the previous enumeration left off. enum 13 THIRTEENTH FOURTEENTH FIFTEENTH enum + SIXTEENTH SEVENTEENTH EIGHTEENTH ## Conditional Code Inclusion (\#ifdef) The preprocessor supports something like cpp's \#if/\#else/\#endif by usurping a bit of Perl's conditional syntax. The following conditional statements will be evaluated at compile time if they are followed by the comment `# include`: if (EXPRESSION) { # include BLOCK; } elsif (EXPRESSION) { # include BLOCK; } else { # include BLOCK; } # include unless (EXPRESSION) { # include BLOCK; } # include The code in each conditional statement's BLOCK will be included or excluded in the compiled code depending on the outcome of its EXPRESSION. Conditional includes are nestable, but else and elsif must be on the same line as the previous block's closing brace, as they are in the previous example. Filter::Template::UseBytes uses conditional code to define different versions of a {% use\_bytes %} macro depending whether the `bytes` pragma exists. # IMPORTING TEMPLATES Filter::Template can import templates defined by another class. For example, this invocation imports the `use_bytes` template: use Filter::Template ( isa => 'Filter::Template::UseBytes' ); Imported templates can be redefined in the current namespace. Note: If the imported templates require additional Perl modules, any code which imports them must also `use` those modules. # DEBUGGING Filter::Template has three debugging constants which will only take effect if they are defined before the module is first used. To trace source filtering in general, and to see the resulting code and operations performed on each line, define: sub Filter::Template::DEBUG () { 1 } To trace template invocations as they happen, define: sub Filter::Template::DEBUG_INVOKE () { 1 } To see template, constant, and enum definitions, define: sub Filter::Template::DEBUG_DEFINE () { 1 } To see warnings when a template or constant is redefined, define: sub Filter::Template::DEFINE () { 1 } # CAVEATS Source filters are line-based, and so is the template language. The only constructs that may span lines are template definitions, and those __must__ span lines. Filter::Template does not parse perl. The regular expressions that detect and replace code are simplistic and may not do the right things when parsing challenging Perl syntax. Constants are replaced within strings, for example. The regexp optimizer makes silly subexpressions like /(?:|m)/. That could be done better as /m?/ or /(?:jklm)?/ if the literal is longer than a single character. The regexp optimizer does not optimize (?:x|y|z) as character classes. The regexp optimizer is based on code in Ilya Zakharevich's Text::Trie. Better regexp optimizers were released afterwards, and Filter::Template should use one of them. # LINKS ## BUG TRACKER https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Filter-Template ## REPOSITORY http://github.com/rcaputo/filter-template http://gitorious.org/filter-template ## OTHER RESOURCES http://search.cpan.org/dist/Filter-Template/ # SEE ALSO [Text::Trie](http://search.cpan.org/perldoc?Text::Trie), [PAR](http://search.cpan.org/perldoc?PAR), [Filter::Template::UseBytes](http://search.cpan.org/perldoc?Filter::Template::UseBytes). # AUTHOR & COPYRIGHT Filter::Template is Copyright 2000-2013 Rocco Caputo. Some parts are Copyright 2001 Matt Cashner. All rights reserved. Filter::Template is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Filter::Template was previously known as POE::Preprocessor. Filter-Template-1.043/t/000755 000765 000024 00000000000 12202157413 015071 5ustar00trocstaff000000 000000 Filter-Template-1.043/t/000-report-versions.t000644 000765 000024 00000031270 12202157413 020737 0ustar00trocstaff000000 000000 #!perl use warnings; use strict; use Test::More 0.94; # Include a cut-down version of YAML::Tiny so we don't introduce unnecessary # dependencies ourselves. package Local::YAML::Tiny; use strict; use Carp 'croak'; # UTF Support? sub HAVE_UTF8 () { $] >= 5.007003 } BEGIN { if ( HAVE_UTF8 ) { # The string eval helps hide this from Test::MinimumVersion eval "require utf8;"; die "Failed to load UTF-8 support" if $@; } # Class structure require 5.004; $YAML::Tiny::VERSION = '1.40'; # Error storage $YAML::Tiny::errstr = ''; } # Printable characters for escapes my %UNESCAPES = ( z => "\x00", a => "\x07", t => "\x09", n => "\x0a", v => "\x0b", f => "\x0c", r => "\x0d", e => "\x1b", '\\' => '\\', ); ##################################################################### # Implementation # Create an empty YAML::Tiny object sub new { my $class = shift; bless [ @_ ], $class; } # Create an object from a file sub read { my $class = ref $_[0] ? ref shift : shift; # Check the file my $file = shift or return $class->_error( 'You did not specify a file name' ); return $class->_error( "File '$file' does not exist" ) unless -e $file; return $class->_error( "'$file' is a directory, not a file" ) unless -f _; return $class->_error( "Insufficient permissions to read '$file'" ) unless -r _; # Slurp in the file local $/ = undef; local *CFG; unless ( open(CFG, $file) ) { return $class->_error("Failed to open file '$file': $!"); } my $contents = ; unless ( close(CFG) ) { return $class->_error("Failed to close file '$file': $!"); } $class->read_string( $contents ); } # Create an object from a string sub read_string { my $class = ref $_[0] ? ref shift : shift; my $self = bless [], $class; my $string = $_[0]; unless ( defined $string ) { return $self->_error("Did not provide a string to load"); } # Byte order marks # NOTE: Keeping this here to educate maintainers # my %BOM = ( # "\357\273\277" => 'UTF-8', # "\376\377" => 'UTF-16BE', # "\377\376" => 'UTF-16LE', # "\377\376\0\0" => 'UTF-32LE' # "\0\0\376\377" => 'UTF-32BE', # ); if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) { return $self->_error("Stream has a non UTF-8 BOM"); } else { # Strip UTF-8 bom if found, we'll just ignore it $string =~ s/^\357\273\277//; } # Try to decode as utf8 utf8::decode($string) if HAVE_UTF8; # Check for some special cases return $self unless length $string; unless ( $string =~ /[\012\015]+\z/ ) { return $self->_error("Stream does not end with newline character"); } # Split the file into lines my @lines = grep { ! /^\s*(?:\#.*)?\z/ } split /(?:\015{1,2}\012|\015|\012)/, $string; # Strip the initial YAML header @lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/ and shift @lines; # A nibbling parser while ( @lines ) { # Do we have a document header? if ( $lines[0] =~ /^---\s*(?:(.+)\s*)?\z/ ) { # Handle scalar documents shift @lines; if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) { push @$self, $self->_read_scalar( "$1", [ undef ], \@lines ); next; } } if ( ! @lines or $lines[0] =~ /^(?:---|\.\.\.)/ ) { # A naked document push @$self, undef; while ( @lines and $lines[0] !~ /^---/ ) { shift @lines; } } elsif ( $lines[0] =~ /^\s*\-/ ) { # An array at the root my $document = [ ]; push @$self, $document; $self->_read_array( $document, [ 0 ], \@lines ); } elsif ( $lines[0] =~ /^(\s*)\S/ ) { # A hash at the root my $document = { }; push @$self, $document; $self->_read_hash( $document, [ length($1) ], \@lines ); } else { croak("YAML::Tiny failed to classify the line '$lines[0]'"); } } $self; } # Deparse a scalar string to the actual scalar sub _read_scalar { my ($self, $string, $indent, $lines) = @_; # Trim trailing whitespace $string =~ s/\s*\z//; # Explitic null/undef return undef if $string eq '~'; # Quotes if ( $string =~ /^\'(.*?)\'\z/ ) { return '' unless defined $1; $string = $1; $string =~ s/\'\'/\'/g; return $string; } if ( $string =~ /^\"((?:\\.|[^\"])*)\"\z/ ) { # Reusing the variable is a little ugly, # but avoids a new variable and a string copy. $string = $1; $string =~ s/\\"/"/g; $string =~ s/\\([never\\fartz]|x([0-9a-fA-F]{2}))/(length($1)>1)?pack("H2",$2):$UNESCAPES{$1}/gex; return $string; } # Special cases if ( $string =~ /^[\'\"!&]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } return {} if $string eq '{}'; return [] if $string eq '[]'; # Regular unquoted string return $string unless $string =~ /^[>|]/; # Error croak("YAML::Tiny failed to find multi-line scalar content") unless @$lines; # Check the indent depth $lines->[0] =~ /^(\s*)/; $indent->[-1] = length("$1"); if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Pull the lines my @multiline = (); while ( @$lines ) { $lines->[0] =~ /^(\s*)/; last unless length($1) >= $indent->[-1]; push @multiline, substr(shift(@$lines), length($1)); } my $j = (substr($string, 0, 1) eq '>') ? ' ' : "\n"; my $t = (substr($string, 1, 1) eq '-') ? '' : "\n"; return join( $j, @multiline ) . $t; } # Parse an array sub _read_array { my ($self, $array, $indent, $lines) = @_; while ( @$lines ) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } if ( $lines->[0] =~ /^(\s*\-\s+)[^\'\"]\S*\s*:(?:\s+|$)/ ) { # Inline nested hash my $indent2 = length("$1"); $lines->[0] =~ s/-/ /; push @$array, { }; $self->_read_hash( $array->[-1], [ @$indent, $indent2 ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-(\s*)(.+?)\s*\z/ ) { # Array entry with a value shift @$lines; push @$array, $self->_read_scalar( "$2", [ @$indent, undef ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) { shift @$lines; unless ( @$lines ) { push @$array, undef; return 1; } if ( $lines->[0] =~ /^(\s*)\-/ ) { my $indent2 = length("$1"); if ( $indent->[-1] == $indent2 ) { # Null array entry push @$array, undef; } else { # Naked indenter push @$array, [ ]; $self->_read_array( $array->[-1], [ @$indent, $indent2 ], $lines ); } } elsif ( $lines->[0] =~ /^(\s*)\S/ ) { push @$array, { }; $self->_read_hash( $array->[-1], [ @$indent, length("$1") ], $lines ); } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) { # This is probably a structure like the following... # --- # foo: # - list # bar: value # # ... so lets return and let the hash parser handle it return 1; } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } return 1; } # Parse an array sub _read_hash { my ($self, $hash, $indent, $lines) = @_; while ( @$lines ) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Get the key unless ( $lines->[0] =~ s/^\s*([^\'\" ][^\n]*?)\s*:(\s+|$)// ) { if ( $lines->[0] =~ /^\s*[?\'\"]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } croak("YAML::Tiny failed to classify line '$lines->[0]'"); } my $key = $1; # Do we have a value? if ( length $lines->[0] ) { # Yes $hash->{$key} = $self->_read_scalar( shift(@$lines), [ @$indent, undef ], $lines ); } else { # An indent shift @$lines; unless ( @$lines ) { $hash->{$key} = undef; return 1; } if ( $lines->[0] =~ /^(\s*)-/ ) { $hash->{$key} = []; $self->_read_array( $hash->{$key}, [ @$indent, length($1) ], $lines ); } elsif ( $lines->[0] =~ /^(\s*)./ ) { my $indent2 = length("$1"); if ( $indent->[-1] >= $indent2 ) { # Null hash entry $hash->{$key} = undef; } else { $hash->{$key} = {}; $self->_read_hash( $hash->{$key}, [ @$indent, length($1) ], $lines ); } } } } return 1; } # Set error sub _error { $YAML::Tiny::errstr = $_[1]; undef; } # Retrieve error sub errstr { $YAML::Tiny::errstr; } ##################################################################### # Use Scalar::Util if possible, otherwise emulate it BEGIN { eval { require Scalar::Util; }; if ( $@ ) { # Failed to load Scalar::Util eval <<'END_PERL'; sub refaddr { my $pkg = ref($_[0]) or return undef; if (!!UNIVERSAL::can($_[0], 'can')) { bless $_[0], 'Scalar::Util::Fake'; } else { $pkg = undef; } "$_[0]" =~ /0x(\w+)/; my $i = do { local $^W; hex $1 }; bless $_[0], $pkg if defined $pkg; $i; } END_PERL } else { Scalar::Util->import('refaddr'); } } ##################################################################### # main test ##################################################################### package main; BEGIN { # Skip modules that either don't want to be loaded directly, such as # Module::Install, or that mess with the test count, such as the Test::* # modules listed here. # # Moose::Role conflicts if Moose is loaded as well, but Moose::Role is in # the Moose distribution and it's certain that someone who uses # Moose::Role also uses Moose somewhere, so if we disallow Moose::Role, # we'll still get the relevant version number. my %skip = map { $_ => 1 } qw( App::FatPacker Class::Accessor::Classy Devel::Cover Module::Install Moose::Role POE::Loop::Tk Template::Test Test::Kwalitee Test::Pod::Coverage Test::Portability::Files Test::YAML::Meta open ); my $Test = Test::Builder->new; $Test->plan(skip_all => "META.yml could not be found") unless -f 'META.yml' and -r _; my $meta = (Local::YAML::Tiny->read('META.yml'))->[0]; my %requires; for my $require_key (grep { /requires/ } keys %$meta) { my %h = %{ $meta->{$require_key} }; $requires{$_}++ for keys %h; } delete $requires{perl}; diag("Testing with Perl $], $^X"); for my $module (sort keys %requires) { if ($skip{$module}) { note "$module doesn't want to be loaded directly, skipping"; next; } local $SIG{__WARN__} = sub { note "$module: $_[0]" }; require_ok $module or BAIL_OUT("can't load $module"); my $version = $module->VERSION; $version = 'undefined' unless defined $version; diag(" $module version is $version"); } done_testing; } Filter-Template-1.043/t/01_inline.t000644 000765 000024 00000004724 12202157413 017043 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w # vim: filetype=perl # Tests basic template features. use strict; use lib qw(./mylib); use Test::More tests => 18; BEGIN { use_ok("Filter::Template") }; # Define some inline templates. template numeric_max (, ) { ((() > ()) ? () : ()) } template numeric_min (, ) { ((() < ()) ? () : ()) } template lexical_max (, ) { ((() gt ()) ? () : ()) } template lexical_min (, ) { ((() lt ()) ? () : ()) } # Define some constants. const LEX_ONE 'one' const LEX_TWO 'two' enum NUM_ZERO NUM_ONE NUM_TWO enum 10 NUM_TEN enum + NUM_ELEVEN # Test the enumerations and constants first. ok(NUM_ZERO == 0, "NUM\_ZERO == 0"); ok(NUM_ONE == 1, "NUM\_ONE == 1"); ok(NUM_TWO == 2, "NUM\_TWO == 2"); ok(NUM_TEN == 10, "NUM\_TEN == 10"); ok(NUM_ELEVEN == 11, "NUM\_ELEVEN == 11"); ok(LEX_ONE eq 'one', "LEX\_ONE eq one"); ok(LEX_TWO eq 'two', "LEX\_TWO eq two"); # Test the templates. ok( {% numeric_max NUM_ONE, NUM_TWO %} == 2, "numeric_max" ); ok( {% numeric_min NUM_TEN, NUM_ELEVEN %} == 10, "numeric_min" ); ok( {% lexical_max LEX_ONE, LEX_TWO %} eq 'two', "lexical_max" ); ok( {% lexical_min LEX_ONE, LEX_TWO %} eq 'one', "lexical_min" ); # Test conditional code. my $test = "conditional unless"; unless (1) { # include fail($test); } else { # include pass($test); } # include $test = "conditional if/elsif"; if (0) { # include fail($test); } elsif (1) { # include pass($test); } else { # include fail($test); } # include if (0) { # include fail("outer if, before unless"); unless (1) { # include fail("inner unless"); } else { # include fail("inner unless"); } # include fail("outer if, after unless"); } else { # include pass("outer if, before unless"); unless (1) { # include fail("inner unless"); } else { # include pass("inner unless"); } # include pass("outer if, after unless"); } # include pass("end of tests"); exit; Filter-Template-1.043/t/02_usebytes.t000644 000765 000024 00000000674 12202157413 017431 0ustar00trocstaff000000 000000 #!/usr/bin/perl -w # vim: filetype=perl use strict; use Test::More tests => 2; use Filter::Template ( isa => "Filter::Template::UseBytes" ); SKIP: { skip("this version of perl is too old for C", 2) unless &Filter::Template::UseBytes::HAS_BYTES; # Hi, Phi! my $test_string = chr(0x618); ok(length($test_string) == 1, "Phi is one character"); {% use_bytes %} ok(length($test_string) == 2, "Phi is two bytes"); } exit 0; Filter-Template-1.043/t/release-pod-coverage.t000644 000765 000024 00000000765 12202157413 021257 0ustar00trocstaff000000 000000 #!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::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Filter-Template-1.043/t/release-pod-syntax.t000644 000765 000024 00000000450 12202157413 021001 0ustar00trocstaff000000 000000 #!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::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Filter-Template-1.043/lib/Filter/000755 000765 000024 00000000000 12202157413 016621 5ustar00trocstaff000000 000000 Filter-Template-1.043/lib/Filter/Template/000755 000765 000024 00000000000 12202157413 020374 5ustar00trocstaff000000 000000 Filter-Template-1.043/lib/Filter/Template.pm000644 000765 000024 00000053746 12202157413 020751 0ustar00trocstaff000000 000000 package Filter::Template; { $Filter::Template::VERSION = '1.043'; } use strict; use Carp qw(croak); use Filter::Util::Call; use Symbol qw(gensym); use constant TMP_PARAMETERS => 0; use constant TMP_CODE => 1; use constant TMP_NAME => 2; # only used in temporary %template use constant TMP_FILE => 3; use constant TMP_LINE => 4; # only used in temporary %template use constant STATE_PLAIN => 0x0000; use constant STATE_TEMPL_DEF => 0x0001; use constant COND_FLAG => 0; use constant COND_LINE => 1; use constant COND_INDENT => 2; #use constant DEBUG => 1; #use constant DEBUG_INVOKE => 1; #use constant DEBUG_DEFINE => 1; #use constant WARN_DEFINE => 1; BEGIN { defined &DEBUG or eval 'sub DEBUG () { 0 }'; # preprocessor defined &DEBUG_INVOKE or eval 'sub DEBUG_INVOKE () { 0 }'; # templ invocs defined &DEBUG_DEFINE or eval 'sub DEBUG_DEFINE () { 0 }'; # templ defines defined &WARN_DEFINE or eval 'sub WARN_DEFINE () { 0 }'; # redefine warning }; ### Start of regexp optimizer. # text_trie_trie is virtually identical to code in Ilya Zakharevich's # Text::Trie::Trie function. The minor differences involve hardcoding # the minimum substring length to 1 and sorting the output. sub text_trie_trie { my @list = @_; return shift if @_ == 1; my (@trie, %first); foreach (@list) { my $c = substr $_, 0, 1; if (exists $first{$c}) { push @{$first{$c}}, $_; } else { $first{$c} = [ $_ ]; } } foreach (sort keys %first) { # Find common substring my $substr = $first{$_}->[0]; (push @trie, $substr), next if @{$first{$_}} == 1; my $l = length($substr); foreach (@{$first{$_}}) { $l-- while substr($_, 0, $l) ne substr($substr, 0, $l); } $substr = substr $substr, 0, $l; # Feed the trie. @list = map {substr $_, $l} @{$first{$_}}; push @trie, [$substr, text_trie_trie(@list)]; } @trie; } # This is basically Text::Trie::walkTrie, but it's hardcoded to build # regular expressions. sub text_trie_as_regexp { my @trie = @_; my $num = 0; my $regexp = ''; foreach (@trie) { $regexp .= '|' if $num++; if (ref $_ eq 'ARRAY') { $regexp .= $_->[0] . '(?:'; # If the first tail is empty, make the whole group optional. my ($tail, $first); if (length $_->[1]) { $tail = ')'; $first = 1; } else { $tail = ')?'; $first = 2; } # Recurse into the group of tails. if ($#$_ > 1) { $regexp .= text_trie_as_regexp( @{$_}[$first .. $#$_] ); } $regexp .= $tail; } else { $regexp .= $_; } } $regexp; } ### End of regexp optimizer. # These must be accessible from outside the current package. use vars qw(%conditional_stacks %excluding_code %exclude_indent); sub fix_exclude { my $package_name = shift; $excluding_code{$package_name} = 0; if (@{$conditional_stacks{$package_name}}) { foreach my $flag (@{$conditional_stacks{$package_name}}) { unless ($flag->[COND_FLAG]) { $excluding_code{$package_name} = 1; $exclude_indent{$package_name} = $flag->[COND_INDENT]; last; } } } } my (%constants, %templates, %const_regexp, %template); sub import { my $self = shift; my %args; if(@_ > 1) { %args = @_; } # Outer closure to define a unique scope. { my $template_name = ''; my ($template_line, $enum_index); my ($package_name, $file_name, $line_number) = (caller)[0,1,2]; my $const_regexp_dirty = 0; my $state = STATE_PLAIN; # The following block processes inheritance requests for # templates/constants and enums. added by sungo 09/2001 my @isas; if ($args{isa}) { if (ref $args{isa} eq 'ARRAY') { foreach my $isa (@{$args{isa}}) { push @isas, $isa; } } else { push @isas, $args{isa}; } foreach my $isa (@isas) { eval "use $isa"; croak "Unable to load $isa : $@" if $@; foreach my $const (keys %{$constants{$isa}}) { $constants{$package_name}->{$const} = $constants{$isa}->{$const}; $const_regexp_dirty = 1; } foreach my $template (keys %{$templates{$isa}}) { $templates{$package_name}->{$template} = ( $templates{$isa}->{$template} ); } } } $conditional_stacks{$package_name} = [ ]; $excluding_code{$package_name} = 0; my $set_const = sub { my ($name, $value) = @_; if ( WARN_DEFINE and exists $constants{$package_name}->{$name} and $constants{$package_name}->{$name} ne $value ) { warn "const $name redefined at $file_name line $line_number\n"; } $constants{$package_name}->{$name} = $value; $const_regexp_dirty++; DEBUG_DEFINE and warn( ",-----\n", "| Defined a constant: $name = $value\n", "`-----\n" ); }; # Define the filter sub. filter_add( sub { my $status = filter_read(); $line_number++; ### Handle errors or EOF. if ($status <= 0) { if (@{$conditional_stacks{$package_name}}) { die( "include block never closed. It probably started " . "at $file_name line " . $conditional_stacks{$package_name}->[0]->[COND_LINE] . "\n" ); } return $status; } ### Usurp modified Perl syntax for code inclusion. These ### are hardcoded and always handled. # Only do the conditionals if there's a flag present. if (/\#\s*include/) { # if (...) { # include if (/^(\s*)if\s*\((.+)\)\s*\{\s*\#\s*include\s*$/) { my $space = (defined $1) ? $1 : ''; $_ = ( $space . "BEGIN { push( \@{\$" . __PACKAGE__ . "::conditional_stacks{'$package_name'}}, " . "[ !!$2, $line_number, '$space' ] ); \&" . __PACKAGE__ . "::fix_exclude('$package_name'); }; # $_" ); s/\#\s+/\# /; # Dummy line in the template. if ($state & STATE_TEMPL_DEF) { local $_ = $_; s/B/\# B/; $template_line++; $template{$package_name}->[TMP_CODE] .= $_; DEBUG and warn sprintf "%4d M: # mac 1: %s", $line_number, $_; } else { DEBUG and warn sprintf "%4d C: %s", $line_number, $_; } return $status; } # } # include elsif (/^\s*\}\s*\#\s*include\s*$/) { s/^(\s*)/$1\# /; pop @{$conditional_stacks{$package_name}}; &fix_exclude($package_name); unless ($state & STATE_TEMPL_DEF) { DEBUG and warn sprintf "%4d C: %s", $line_number, $_; return $status; } } # } else { # include elsif (/^\s*\}\s*else\s*\{\s*\#\s*include\s*$/) { unless (@{$conditional_stacks{$package_name}}) { die( "else { # include ... without if or unless " . "at $file_name line $line_number\n" ); return -1; } s/^(\s*)/$1\# /; $conditional_stacks{$package_name}->[-1]->[COND_FLAG] = ( !$conditional_stacks{$package_name}->[-1]->[COND_FLAG] ); &fix_exclude($package_name); unless ($state & STATE_TEMPL_DEF) { DEBUG and warn sprintf "%4d C: %s", $line_number, $_; return $status; } } # unless (...) { # include elsif (/^(\s*)unless\s*\((.+)\)\s*\{\s*\#\s*include\s*$/) { my $space = (defined $1) ? $1 : ''; $_ = ( $space . "BEGIN { push( \@{\$" . __PACKAGE__ . "::conditional_stacks{'$package_name'}}, " . "[ !$2, $line_number, '$space' ] ); \&" . __PACKAGE__ . "::fix_exclude('$package_name'); }; # $_" ); s/\#\s+/\# /; # Dummy line in the template. if ($state & STATE_TEMPL_DEF) { local $_ = $_; s/B/\# B/; $template_line++; $template{$package_name}->[TMP_CODE] .= $_; DEBUG and warn sprintf "%4d M: # mac 2: %s", $line_number, $_; } else { DEBUG and warn sprintf "%4d C: %s", $line_number, $_; } return $status; } # } elsif (...) { # include elsif (/^(\s*)\}\s*elsif\s*\((.+)\)\s*\{\s*\#\s*include\s*$/) { unless (@{$conditional_stacks{$package_name}}) { die( "Include elsif without include if or unless " . "at $file_name line $line_number\n" ); return -1; } my $space = (defined $1) ? $1 : ''; $_ = ( $space . "BEGIN { \$" . __PACKAGE__ . "::conditional_stacks{'$package_name'}->[-1] = " . "[ !!$2, $line_number, '$space' ]; \&" . __PACKAGE__ . "::fix_exclude('$package_name'); }; # $_" ); s/\#\s+/\# /; # Dummy line in the template. if ($state & STATE_TEMPL_DEF) { local $_ = $_; s/B/\# B/; $template_line++; $template{$package_name}->[TMP_CODE] .= $_; DEBUG and warn sprintf "%4d M: # mac 3: %s", $line_number, $_; } else { DEBUG and warn sprintf "%4d C: %s", $line_number, $_; } return $status; } } ### Not including code, so comment it out. Don't return ### $status here since the code may well be in a template. if ($excluding_code{$package_name}) { s{^($exclude_indent{$package_name})?} {$exclude_indent{$package_name}\# }; # Kludge: Must thwart templates on this line. s/\{\%(.*?)\%\}/TEMPLATE($1)/g; unless ($state & STATE_TEMPL_DEF) { DEBUG and warn sprintf "%4d C: %s", $line_number, $_; return $status; } } ### Inside a template definition. if ($state & STATE_TEMPL_DEF) { # Close it! if (/^\}\s*$/) { $state = STATE_PLAIN; DEBUG_DEFINE and warn ( ",-----\n", "| Defined template $template_name\n", "| Parameters: ", @{$template{$package_name}->[TMP_PARAMETERS]}, "\n", "| Code: {\n", $template{$package_name}->[TMP_CODE], "| }\n", "`-----\n" ); $template{$package_name}->[TMP_CODE] =~ s/^\s*//; $template{$package_name}->[TMP_CODE] =~ s/\s*$//; if ( WARN_DEFINE and exists $templates{$package_name}->{$template_name} and ( $templates{$package_name}->{$template_name}->[TMP_CODE] ne $template{$package_name}->[TMP_CODE] ) ) { warn( "template $template_name redefined at ", "$file_name line $line_number\n" ); } $templates{$package_name}->{$template_name} = ( $template{$package_name} ); $template_name = ''; } # Otherwise append this line to the template. else { $template_line++; $template{$package_name}->[TMP_CODE] .= $_; } # Either way, the code must not go on. $_ = "# mac 4: $_"; DEBUG and warn sprintf "%4d M: %s", $line_number, $_; return $status; } ### Ignore everything after __END__ or __DATA__. This works ### around a coredump in 5.005_61 through 5.6.0 at the ### expense of preprocessing data and documentation. if (/^__(END|DATA)__\s*$/) { $_ = "# $_"; return 0; } ### We're done if we're excluding code. if ($excluding_code{$package_name}) { return $status; } ### Define an enum. if (/^enum(?:\s+(\d+|\+))?\s+(.*?)\s*$/) { my $temp_line = $_; $enum_index = ( (defined $1) ? ( ($1 eq '+') ? $enum_index : $1 ) : 0 ); foreach (split /\s+/, $2) { $set_const->($_, $enum_index++); } $_ = "# $temp_line"; DEBUG and warn sprintf "%4d E: %s", $line_number, $_; return $status; } ### Define a constant. if (/^const\s+(\S+)\s+(.+?)\s*$/i) { &{$set_const}($1, $2); $_ = "# $_"; DEBUG and warn sprintf "%4d E: %s", $line_number, $_; return $status; } ### Begin a template definition. if (/^template\s*(\w+)\s*(?:\((.*?)\))?\s*\{\s*$/) { $state = STATE_TEMPL_DEF; my $temp_line = $_; $template_name = $1; $template_line = 0; my @template_params = ( (defined $2) ? split(/\s*\,\s*/, $2) : () ); $template{$package_name} = [ \@template_params, # TMP_PARAMETERS '', # TMP_CODE $template_name, # TMP_NAME $file_name, # TMP_FILE $line_number, # TMP_LINE ]; $_ = "# $temp_line"; DEBUG and warn sprintf "%4d D: %s", $line_number, $_; return $status; } ### Perform template substitutions. my $substitutions = 0; while (/(\{\%\s+(\S+)\s*(.*?)\s*\%\})/gs) { my ($name, $params) = ($2, $3); # Backtrack to the beginning of the substitution so that # the newly inserted text may also be checked. pos($_) -= length($1); DEBUG_INVOKE and warn( ",-----\n| template invocation: $name $params\n" ); if (exists $templates{$package_name}->{$name}) { my @use_params = split /\s*\,\s*/, $params; my @mac_params = ( @{$templates{$package_name}->{$name}->[TMP_PARAMETERS]} ); if (@use_params != @mac_params) { warn( "template $name parameter count (", scalar(@use_params), ") doesn't match defined count (", scalar(@mac_params), ") at $file_name line $line_number\n" ); return $status; } # Build a new bit of code here. my $substitution = $templates{$package_name}->{$name}->[TMP_CODE]; my $template_file = $templates{$package_name}->{$name}->[TMP_FILE]; my $template_line = $templates{$package_name}->{$name}->[TMP_LINE]; foreach my $mac_param (@mac_params) { my $use_param = shift @use_params; 1 while ($substitution =~ s/$mac_param/$use_param/g); } unless ($^P) { my @sub_lines = split /\n/, $substitution; my $sub_line = @sub_lines; while ($sub_line--) { splice( @sub_lines, $sub_line, 0, "# line $line_number " . "\"template $name (defined in $template_file at line " . ($template_line + $sub_line + 1) . ") " . "invoked from $file_name\"" ); } $substitution = join "\n", @sub_lines; } substr($_, pos($_), length($1)) = $substitution; $_ .= "# line " . ($line_number+1) . " \"$file_name\"\n" unless $^P; DEBUG_INVOKE and warn "$_`-----\n"; $substitutions++; } else { die( "template $name has not been defined ", "at $file_name line $line_number\n" ); last; } } # Only rebuild the constant regexp if necessary. This # prevents redundant regexp rebuilds when defining several # constants all together. if ($const_regexp_dirty) { $const_regexp{$package_name} = text_trie_as_regexp( text_trie_trie(keys %{$constants{$package_name}}) ); $const_regexp_dirty = 0; } # Perform constant substitutions. if (defined $const_regexp{$package_name}) { $substitutions += ( s[\b($const_regexp{$package_name})\b] [$constants{$package_name}->{$1}]sg ); } # Trace substitutions. if (DEBUG) { if ($substitutions) { foreach my $line (split /\n/) { warn sprintf "%4d S: %s\n", $line_number, $line; } } else { warn sprintf "%4d |: %s", $line_number, $_; } } return $status; } ); } } # Clear a package's templates. Used for destructive testing. sub clear_package { my ($self, $package) = @_; delete $constants{$package}; delete $templates{$package}; delete $const_regexp{$package}; delete $template{$package}; } 1; __END__ =head1 NAME Filter::Template - a source filter for inline code templates (macros) =head1 VERSION version 1.043 =head1 SYNOPSIS use Filter::Template; # use Filter::Template ( isa => 'SomeModule' ); template max (one,two) { ((one) > (two) ? (one) : (two)) } print {% max $one, $two %}, "\n"; const PI 3.14159265359 print "PI\n"; # Constants are expanded inside strings. print "HAPPINESS\n"; # Also expanded due to naive parser. enum ZERO ONE TWO enum 12 TWELVE THIRTEEN FOURTEEN enum + FIFTEEN SIXTEEN SEVENTEEN # Prints numbers, due to naive parser. print "ZERO ONE TWO TWELVE THIRTEEN FOURTEEN FIFTEEN SIXTEEN SEVENTEEN\n"; if ($expression) { # include ... lines of code ... } # include unless ($expression) { # include ... lines of code ... } elsif ($expression) { # include ... lines of code ... } else { # include ... lines of code ... } # include =head1 DESCRIPTION Filter::Template is a Perl source filter that provides simple inline source code templates. Inlined source code can be significantly faster than subroutines, especially for small-scale functions like accessors and mutators. On the other hand, they are more difficult to maintain and use. Choose your trade-offs wisely. =head2 Templates Code templates are defined with the C