Module-Compile-0.35/0000755000175000017500000000000012446625715012766 5ustar ingyingyModule-Compile-0.35/META.yml0000644000175000017500000000131112446625715014233 0ustar ingyingy--- abstract: 'Perl Module Compilation' author: - 'Ingy döt Net ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '6.30' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.132830' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Module-Compile no_index: directory: - inc - t - xt - example requires: Digest::SHA1: '2.13' perl: v5.8.1 resources: bugtracker: https://github.com/ingydotnet/module-compile-pm/issues homepage: https://github.com/ingydotnet/module-compile-pm repository: https://github.com/ingydotnet/module-compile-pm.git version: '0.35' Module-Compile-0.35/LICENSE0000644000175000017500000004365612446625715014011 0ustar ingyingyThis software is copyright (c) 2014 by Ingy döt Net. 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) 2014 by Ingy döt Net. 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) 2014 by Ingy döt Net. 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 Module-Compile-0.35/Makefile.PL0000644000175000017500000000172312446625715014743 0ustar ingyingy # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.019. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Perl Module Compilation", "AUTHOR" => "Ingy d\x{f6}t Net ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Module-Compile", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Module::Compile", "PREREQ_PM" => { "Digest::SHA1" => "2.13" }, "VERSION" => "0.35", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Digest::SHA1" => "2.13" ); 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); Module-Compile-0.35/README0000644000175000017500000001505612446625715013655 0ustar ingyingyNAME Module::Compile - Perl Module Compilation SYNOPSIS package Foo; use Module::Compile -base; sub pmc_compile { my ($class, $source) = @_; # Convert $source into (most likely Perl 5) $compiled_output return $compiled_output; } In "Bar.pm": package Bar; use Foo; ... no Foo or (implied "no Foo;"): package Bar; { use Foo; ... } To compile "Bar.pm" into "Bar.pmc": perl -c Bar.pm DESCRIPTION This module provides a system for writing modules that *compile* other Perl modules. Modules that use these compilation modules get compiled into some altered form the first time they are run. The result is cached into ".pmc" files. Perl has native support for ".pmc" files. It always checks for them, before loading a ".pm" file. EXAMPLE You can declare a "v6.pm" compiler with: package v6; use Module::Compile -base; sub pmc_compile { my ($class, $source) = @_; # ... some way to invoke pugs and give p5 code back ... } and use it like: # MyModule.pm use v6-pugs; module MyModule; # ...some p6 code here... no v6; # ...back to p5 land... On the first time this module is loaded, it will compile Perl 6 blocks into Perl 5 (as soon as the "no v6" line is seen), and merge it with the Perl 5 blocks, saving the result into a "MyModule.pmc" file. The next time around, Perl 5 will automatically load "MyModule.pmc" when someone says "use MyModule". On the other hand, Perl 6 can run MyModule.pm s a Perl 6 module just fine, as "use v6-pugs" and "no v6" both works in a Perl 6 setting. The v6.pm module will also check if "MyModule.pmc" is up to date. If it is, then it will touch its timestamp so the ".pmc" is loaded on the next time. BENEFITS Module::Compile compilers gives you the following benefits: * Ability to mix many source filterish modules in a much more sane manner. Module::Compile controls the compilation process, calling each compiler at the right time with the right data. * Ability to ship precompiled modules without shipping Module::Compile and the compiler modules themselves. * Easier debugging of compiled/filtered code. The ".pmc" has the real code you want to see. * Zero additional runtime penalty after compilation, because "perl" has already been doing the ".pmc" check on every module load since 1999! PARSING AND DISPATCH NOTE: *** NOT FULLY IMPLEMENTED YET *** Module::Compile attempts to make source filtering a sane process, by parsing up your module's source code into various blocks; so that by the time a compiler is called it only gets the source code that it should be looking at. This section describes the rather complex algorithm that Module::Compile uses. First, the source module is preprocessed to hide heredocs, since the content inside heredocs can possibly confuse further parsing. Next, the source module is divided into a shallow tree of blocks: PREAMBLE: (SUBROUTINE | BAREBLOCK | POD | PLAIN)S PACKAGES: PREFACE (SUBROUTINE | BAREBLOCK | POD | PLAIN)S DATA All of these blocks begin and end on line boundaries. They are described as follows: PREAMBLE Lines before the first "package" statement. PACKAGES Lines beginning with a `package statement and continuing until the next `package` or `DATA` section. DATA The DATA section. Begins with the line "__DATA__" or "__END__". SUBROUTINE A top level (not nested) subroutine. Ending '}' must be on its own line in the first column. BAREBLOCK A top level (not nested) code block. Ending '}' must be on its own line in the first column. POD Pod sections beginning with "^=\w+" and ending with "=cut". PLAIN Lines not in SUBROUTINE, BAREBLOCK or POD. PREFACE Lines before the first block in a package. Next, all the blocks are scanned for lines like: use Foo qw'x y z'; no Foo; Where Foo is a Module::Compile subclass. The lines within a given block between a "use" and "no" statement are marked to be passed to that compiler. The end of an inner block effectively acts as a "no" statement for any compile sections in that block. "use" statements in a PREFACE apply to all the code in a PACKAGE. "use" statements in a PREAMBLE apply to all the code in all PACKAGES. After all the code has been parsed into blocks and the blocks have been marked for various compilers, Module::Compile dispatches the code blocks to the compilers. It does so in a most specific to most general order. So inner blocks get compiled first, then outer blocks. A compiler may choose to declare that its result not be recompiled by some other containing parser. In this case the result of the compilation is replaced by a single line containing the hexadecimal digest of the result in double quotes followed by a semicolon. Like: "f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"; The rationale of this is that randoms strings are usally left alone by compilers. After all the compilers have finished, the digest lines will be expanded again. Every bit of the default process described above is overridable by various methods. DISTRIBUTION SUPPORT Module::Install makes it terribly easy to prepare a module distribution with compiled .pmc files. See Module::Install::PMC. All you need to do is add this line to your Makefile.PL: pmc_support; Any of your distrbution's modules that use Module::Compile based modules will automatically be compiled into .pmc files and shipped with your distribtution precompiled. This means that people who install your module distribtution do not need to have the compilers installed themselves. So you don't need to make the compiler modules be prerequisites. SEE ALSO * Module::Install * Module::Install::PMC AUTHORS * Ingy döt Net * Audrey Tang COPYRIGHT Copyright 2006-2014. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See Module-Compile-0.35/t/0000755000175000017500000000000012446625715013231 5ustar ingyingyModule-Compile-0.35/t/lexical.t0000644000175000017500000000064412446625715015043 0ustar ingyingyuse lib (-e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 1; no_diff; filters { pm => 'process_pm', }; pass 'Lexical compilation not implemented yet'; #run_is pm => 'pmc'; __DATA__ === Apply lexically to bare block. --- pm package Foo; lower lower lower { use Upper; lower lower lower } lower lower lower --- pmc package Foo; lower lower lower { LOWER LOWER LOWER } lower lower lower Module-Compile-0.35/t/lib/0000755000175000017500000000000012446625715013777 5ustar ingyingyModule-Compile-0.35/t/lib/Foo.pm0000644000175000017500000000033712446625715015063 0ustar ingyingypackage Foo; =head1 Tricksy __END__ =cut use Indented; sub greetings: print "Hello " . shift; no Indented; sub farewell { print "Goodbye " . shift; } 1; __END__ =head1 NAME t::Foo - Hello and Goodbye =cut Module-Compile-0.35/t/lib/Upper.pm0000644000175000017500000000012212446625715015423 0ustar ingyingypackage Upper; use strict; use Module::Compile -base; sub pmc_compile { uc } 1; Module-Compile-0.35/t/lib/DataTest.pm0000644000175000017500000000016212446625715016045 0ustar ingyingypackage DataTest; use Module::Compile; sub foo { return shift() + shift(); } 1; __DATA__ one two three Module-Compile-0.35/t/lib/Indented.pm0000644000175000017500000000016712446625715016073 0ustar ingyingypackage Indented; use Module::Compile -base; sub pmc_compile { s/^(sub \w+):(\n(?: +.*?\n)*)/$1 {$2}\n/gm; } 1; Module-Compile-0.35/t/lib/Pre.p0000644000175000017500000000033712446625715014711 0ustar ingyingypackage Pre; =head1 Tricksy __END__ =cut use Indented; sub greetings: print "Hello " . shift; no Indented; sub farewell { print "Goodbye " . shift; } 1; __END__ =head1 NAME t::Pre - Hello and Goodbye =cut Module-Compile-0.35/t/TestModuleCompile.pm0000644000175000017500000000055212446625715017167 0ustar ingyingypackage TestModuleCompile; use Test::Base -Base; use lib -e 't' ? 't/lib' : 'test/lib'; use Module::Compile(); package TestModuleCompile::Filter; use base 'Test::Base::Filter'; sub process_pm { Module::Compile->pmc_process(shift); } sub parse_pm { Module::Compile->pmc_parse_blocks(shift); } sub yaml_dump { require YAML; YAML::Dump(@_); } Module-Compile-0.35/t/pm.t0000644000175000017500000000214712446625715014036 0ustar ingyingymy $t; use lib ($t = -e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile skip_all => 'In progress...'; # tests => 1; BEGIN { $ENV{PERL5OPT} = '-MModule::Compile=-ext,p,pm' }; pass('foo'); use lib "$t/lib"; BEGIN { unlink "$t/lib/Pre.pm" } use Pre; run_is module => 'pm'; sub fixpath { s/t/$t/; return $_; } sub fixup { s/0\.\d\d/0.XX/; s/0x[0-9A-Fa-f]{4,8}/0xXXXXXXXX/; } __DATA__ === Compile Foo.p to Foo.pm --- module fixpath read_file fixup: t/lib/Foo.pm --- pm -trim # Generated by Indented 0 (Module::Compile 0.XX) - do not edit! ################((( 32-bit Checksum Validator III )))################ #line 1 BEGIN { use 5.006; local (*F, $/); ($F = __FILE__) =~ s!c$!!; open(F) or die "Cannot open $F: $!"; binmode(F, ':crlf'); if (unpack('%32N*', $F=readline(*F)) != 0xXXXXXXXX) { use Filter::Util::Call; my $f = $F; filter_add(sub { filter_del(); 1 while &filter_read; $_ = $f; 1; })}} #line 1 package Foo; =head1 Tricksy __END__ =cut sub greetings { print "Hello " . shift; } sub farewell { print "Goodbye " . shift; } 1; __END__ =head1 NAME t::Foo - Hello and Goodbye =cut Module-Compile-0.35/t/Testorz.pm0000644000175000017500000000026512446625715015244 0ustar ingyingypackage Testorz; use strict; use warnings; use Module::Compile -base; sub pmc_compile { s/^/# /gm; return <<"_"; # orz...\n $_ pass 'orz was here'; pass __FILE__; _ } 1; Module-Compile-0.35/t/release-pod-syntax.t0000644000175000017500000000045612446625715017147 0ustar ingyingy#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Module-Compile-0.35/t/fold_blocks.t0000644000175000017500000000551412446625715015704 0ustar ingyingyuse lib (-e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 9; filters({ perl => 'process' }); no_diff; run_is perl => 'folded'; sub process { Module::Compile->pmc_fold_blocks(shift) } __DATA__ === Fold a heredoc whilst preserving ~s --- perl my $x = "~ ~~ ~~~ ~~~~ ~~~~~"; sub foo { my $self = shift; $self->baz(<baz(<baz(<baz(<baz(<<''); sub bar { print "bar"; } } --- folded sub foo { my $self = shift; $self->baz(<<''); 8dc957d71f448e926d28ebe8444d5b33c1d69dc2 } === A double heredoc --- perl sub foo { my $self = shift; $self->baz(<<'THIS', <<"THAT"); THERE THAT THIS THIS THAT THERE } --- folded sub foo { my $self = shift; $self->baz(<<'THIS', <<"THAT"); fe5485c0595b48c3a4126af814e8d53517ecd1d8 THIS 5b35b1abf837461ac7f9b09d42f8560601b028f6 THAT THERE } === A double heredoc. Same END token --- perl sub foo { my $self = shift; $self->baz(<baz(< '>>', ); --- folded ( '<<' => '>>', ); === All kinds --- perl print "ok 1"; # $xxx = < \&test, no_chdir => 1, }, 'lib'; done_testing; Module-Compile-0.35/t/parse.t0000644000175000017500000000120112446625715014522 0ustar ingyingyuse lib (-e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 1; SKIP: { eval "require YAML"; if ($@ or $YAML::VERSION < 0.58) { skip "Test requires YAML-0.58 or higher", 1; } filters { pm => ['parse_pm', 'yaml_dump'] }; no_diff; run_is pm => 'parsed'; } __DATA__ === Parse compiler in block scope --- pm package Foo; use strict; { use Module::Compile xxx => 'yyy'; a = b; } c = d; --- parsed --- - "package Foo;\nuse strict;\n{\n" - {} - [] --- - "\n a = b;\n}\n\nc = d;\n" - Module::Compile: use: " use Module::Compile xxx => 'yyy';\n" - - Module::Compile Module-Compile-0.35/t/data1.t0000644000175000017500000000056312446625715014414 0ustar ingyingymy $t; use lib ($t = -e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 3; no_diff; my $pmc; BEGIN { $pmc = "$t/lib/DataTest.pmc"; unlink($pmc); ok((not -e $pmc), ".pmc doesn't exist yet"); } use DataTest; ok((-e $pmc), ".pmc exists"); local $/; my $data = ; is $data, "\none\ntwo\n\nthree\n\n", "DATA section is correct"; Module-Compile-0.35/t/compile.t0000644000175000017500000000361512446625715015053 0ustar ingyingyuse lib (-e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 2; filters { perl => 'eval', pm => 'process_pm', }; run_is pm => 'pmc'; __DATA__ === use_means_now --- perl package Compile::Now; use strict; use Module::Compile -base; sub pmc_use_means_now { 1 }; sub pmc_compile { my ($class, $content, $context) = @_; my $args = $context->{use} ? ' ' . $context->{use} : ''; chomp $args; return "# Do it now$args\n"; } --- pm package Foo; # start use Compile::Now 'c', 'd'; # middle use Data::Dumper; # earth use Compile::Now 'a', 'b'; # done 1; --- pmc package Foo; # start # Do it now use Compile::Now 'c', 'd'; # middle use Data::Dumper; # earth # Do it now use Compile::Now 'a', 'b'; # done 1; === Nested Compilers --- perl package Indento; use Module::Compile -base; sub pmc_compile { s/^(def \w+):(\n(?: +.*?\n)*)/$1 {$2}\n/g; PySubs->pmc_compile(); } package PySubs; sub pmc_compile { s/^def (\w+ \{)/sub $1/g; } package Y2K; use Module::Compile -base; sub pmc_compile { s/y/k/g } --- pm package Foo; use strict; use warnings; # sample main script drink(); use Indento; def drink: print "Drink "; use Y2K; print "yool aid, "; no Y2K; print "yo!" --- pmc package Foo; use strict; use warnings; # sample main script drink(); sub drink { print "Drink "; print "kool aid, "; print "yo!" } === Nested scopes --- SKIP --- perl package Xxx; use Module::Compile -base; sub pmc_compile { s/\w/x/g; $_ } package Yyy; use Module::Compile -base; sub pmc_compile { s/\w/y/g; $_ } --- pm use Xxx; use Yyy; blah blah blah package A; blah blah blah no Xxx; blah blah blah no Yyy; blah blah blah package B; blah blah blah { no Xxx; no Yyy; blah blah blah } __END__ blah blah blah --- pmc xxxx xxxx xxxx package A; xxxx xxxx xxxx yyyy yyyy yyyy blah blah blah package B; xxxx xxxx xxxx { blah blah blah } __END__ blah blah blah Module-Compile-0.35/t/orz.t0000644000175000017500000000056312446625715014234 0ustar ingyingy# BEGIN { unlink 't/orz.tc' } # Need to invoke Module::Compile before Test::More my $t; use lib ($t = -e 't' ? 't' : 'test'), 'inc'; use Module::Compile; use Test::More tests => 5; pass "Test runs"; ok ((-f "$t/orz.tc"), "Compiled file exists"); use Testorz; fail "don't want this to run"; no Testorz; pass "Second half of test runs"; END { unlink "$t/orz.tc" } Module-Compile-0.35/t/pmc.t0000644000175000017500000000204412446625715014175 0ustar ingyingymy $t; use lib ($t = -e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 1; use lib "$t/lib"; BEGIN { unlink "$t/lib/Foo.pmc" } use Foo; run_is module => 'pmc'; sub fixpath { s/t/$t/; return $_; } sub fixup { s/0\.\d\d/0.XX/; s/0x[0-9A-Fa-f]{4,8}/0xXXXXXXXX/; } END { unlink "$t/lib/Foo.pmc" } __DATA__ === Compile Foo.pm to Foo.pmc --- module fixpath read_file fixup: t/lib/Foo.pmc --- pmc -trim # Generated by Indented 0 (Module::Compile 0.XX) - do not edit! ################((( 32-bit Checksum Validator III )))################ #line 1 BEGIN { use 5.006; local (*F, $/); ($F = __FILE__) =~ s!c$!!; open(F) or die "Cannot open $F: $!"; binmode(F, ':crlf'); if (unpack('%32N*', $F=readline(*F)) != 0xXXXXXXXX) { use Filter::Util::Call; my $f = $F; filter_add(sub { filter_del(); 1 while &filter_read; $_ = $f; 1; })}} #line 1 package Foo; =head1 Tricksy __END__ =cut sub greetings { print "Hello " . shift; } sub farewell { print "Goodbye " . shift; } 1; __END__ =head1 NAME t::Foo - Hello and Goodbye =cut Module-Compile-0.35/t/data2.t0000644000175000017500000000056412446625715014416 0ustar ingyingymy $t; use lib ($t = -e 't' ? 't' : 'test'), 'inc'; use TestModuleCompile tests => 3; my $pmc; BEGIN { $pmc = "$t/lib/DataTest.pmc"; ok((-e $pmc), ".pmc exists"); } use DataTest; ok((-e $pmc), ".pmc still exists"); local $/; my $data = ; is $data, "\none\ntwo\n\nthree\n\n", "DATA section is correct"; END { unlink "$t/lib/DataTest.pmc" } Module-Compile-0.35/lib/0000755000175000017500000000000012446625715013534 5ustar ingyingyModule-Compile-0.35/lib/Module/0000755000175000017500000000000012446625715014761 5ustar ingyingyModule-Compile-0.35/lib/Module/Compile/0000755000175000017500000000000012446625715016351 5ustar ingyingyModule-Compile-0.35/lib/Module/Compile/Opt.pm0000644000175000017500000000114212446625715017447 0ustar ingyingyuse strict; use warnings; package Module::Compile::Opt; # TODO; What is this module for? # sub import { # my ($class, @args) = @_; # my $opts = $class->get_options(@args) # if $class->can('get_options'); # $class->sanity_check($opts); # require Module::Compile; # require Module::Compile::Ext; # Module::Compile::Ext->import(@{$opts->{ext}}); # # # put coderef into @INC # # Store PERL5OPT in .author # # In Module::Compile, complain if PERL5OPT != .author/PERL5OPT # } sub sanity_check { my $class = shift; die unless -e 'inc' and -e 'Makefile.PL'; } 1; Module-Compile-0.35/lib/Module/Compile/Opt.pod0000644000175000017500000000151012446625715017614 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.31. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME Module::Compile::Opt - Provide options to Module::Compile =head1 SYNOPSIS > export PERL5OPT=-MModule::Compile::Opt=-ext,p,pm > perl -c lib/Foo.p > cat lib/Foo.pm =head1 DESCRIPTION module::Compile::Opt allows you to give runtime options to Module::Compile By default Module::Compile compiles a module in a C<.pm> file into a C<.pmc> file. =head1 AUTHORS =over =item * Ingy döt Net =item * Audrey Tang =back =head1 COPYRIGHT Copyright 2006-2014. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut Module-Compile-0.35/lib/Module/Compile/Optimize.pod0000644000175000017500000000254112446625715020657 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.31. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME Module::Optimize - Perl Module Optimization =head1 SYNOPSIS package Foo; use Module::Optimize -base; sub pmc_optimize { my ($self, $source) = @_; # Convert perl5 $source into semantically equivalent $compiled_output return $compiled_output; } In C: package Bar; use Foo; or lexically: package Bar; { use Foo; ... } To compile C into C: perl -c Bar.pm =head1 DESCRIPTION This module provides a system for writing modules that I other Perl modules. Modules that use these compilation modules get compiled into some altered form the first time they are run. The result is cached into C<.pmc> files. Perl has native support for C<.pmc> files. It always checks for them, before loading a C<.pm> file. You get the following benefits: =head1 SEE ALSO Module::Compile =head1 AUTHORS =over =item * Ingy döt Net =item * Audrey Tang =back =head1 COPYRIGHT Copyright 2006-2014. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut Module-Compile-0.35/lib/Module/Optimize.pm0000644000175000017500000000045112446625715017117 0ustar ingyingyuse strict; use warnings; package Module::Optimize; use Module::Compile -base; sub pmc_is_optimizer_module { 1 } # Compile/Filter some source code into something else. This is almost # always overridden in a subclass. sub pmc_optimize { my ($class, $source) = @_; return $source; } 1; Module-Compile-0.35/lib/Module/Compile.pod0000644000175000017500000001524512446625715017064 0ustar ingyingy=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.31. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME Module::Compile - Perl Module Compilation =for html module-compile-pm module-compile-pm =head1 SYNOPSIS package Foo; use Module::Compile -base; sub pmc_compile { my ($class, $source) = @_; # Convert $source into (most likely Perl 5) $compiled_output return $compiled_output; } In C: package Bar; use Foo; ... no Foo or (implied "no Foo;"): package Bar; { use Foo; ... } To compile C into C: perl -c Bar.pm =head1 DESCRIPTION This module provides a system for writing modules that I other Perl modules. Modules that use these compilation modules get compiled into some altered form the first time they are run. The result is cached into C<.pmc> files. Perl has native support for C<.pmc> files. It always checks for them, before loading a C<.pm> file. =head1 EXAMPLE You can declare a C compiler with: package v6; use Module::Compile -base; sub pmc_compile { my ($class, $source) = @_; # ... some way to invoke pugs and give p5 code back ... } and use it like: # MyModule.pm use v6-pugs; module MyModule; # ...some p6 code here... no v6; # ...back to p5 land... On the first time this module is loaded, it will compile Perl 6 blocks into Perl 5 (as soon as the C line is seen), and merge it with the Perl 5 blocks, saving the result into a C file. The next time around, Perl 5 will automatically load C when someone says C. On the other hand, Perl 6 can run MyModule.pm s a Perl 6 module just fine, as C and C both works in a Perl 6 setting. The B module will also check if C is up to date. If it is, then it will touch its timestamp so the C<.pmc> is loaded on the next time. =head1 BENEFITS Module::Compile compilers gives you the following benefits: =over =item * Ability to mix many source filterish modules in a much more sane manner. Module::Compile controls the compilation process, calling each compiler at the right time with the right data. =item * Ability to ship precompiled modules without shipping Module::Compile and the compiler modules themselves. =item * Easier debugging of compiled/filtered code. The C<.pmc> has the real code you want to see. =item * Zero additional runtime penalty after compilation, because C has already been doing the C<.pmc> check on every module load since 1999! =back =head1 PARSING AND DISPATCH NOTE: *** NOT FULLY IMPLEMENTED YET *** Module::Compile attempts to make source filtering a sane process, by parsing up your module's source code into various blocks; so that by the time a compiler is called it only gets the source code that it should be looking at. This section describes the rather complex algorithm that Module::Compile uses. First, the source module is preprocessed to hide heredocs, since the content inside heredocs can possibly confuse further parsing. Next, the source module is divided into a shallow tree of blocks: PREAMBLE: (SUBROUTINE | BAREBLOCK | POD | PLAIN)S PACKAGES: PREFACE (SUBROUTINE | BAREBLOCK | POD | PLAIN)S DATA All of these blocks begin and end on line boundaries. They are described as follows: =over =item PREAMBLE Lines before the first C statement. =item PACKAGES Lines beginning with a `package statement and continuing until the next `package` or `DATA` section. =item DATA The DATA section. Begins with the line C<__DATA__> or C<__END__>. =item SUBROUTINE A top level (not nested) subroutine. Ending '}' must be on its own line in the first column. =item BAREBLOCK A top level (not nested) code block. Ending '}' must be on its own line in the first column. =item POD Pod sections beginning with C<^=\w+> and ending with C<=cut>. =item PLAIN Lines not in SUBROUTINE, BAREBLOCK or POD. =item PREFACE Lines before the first block in a package. =back Next, all the blocks are scanned for lines like: use Foo qw'x y z'; no Foo; Where Foo is a Module::Compile subclass. The lines within a given block between a C and C statement are marked to be passed to that compiler. The end of an inner block effectively acts as a C statement for any compile sections in that block. C statements in a PREFACE apply to all the code in a PACKAGE. C statements in a PREAMBLE apply to all the code in all PACKAGES. After all the code has been parsed into blocks and the blocks have been marked for various compilers, Module::Compile dispatches the code blocks to the compilers. It does so in a most specific to most general order. So inner blocks get compiled first, then outer blocks. A compiler may choose to declare that its result not be recompiled by some other containing parser. In this case the result of the compilation is replaced by a single line containing the hexadecimal digest of the result in double quotes followed by a semicolon. Like: "f1d2d2f924e986ac86fdf7b36c94bcdf32beec15"; The rationale of this is that randoms strings are usally left alone by compilers. After all the compilers have finished, the digest lines will be expanded again. Every bit of the default process described above is overridable by various methods. =head1 DISTRIBUTION SUPPORT Module::Install makes it terribly easy to prepare a module distribution with compiled .pmc files. See Module::Install::PMC. All you need to do is add this line to your Makefile.PL: pmc_support; Any of your distrbution's modules that use Module::Compile based modules will automatically be compiled into .pmc files and shipped with your distribtution precompiled. This means that people who install your module distribtution do not need to have the compilers installed themselves. So you don't need to make the compiler modules be prerequisites. =head1 SEE ALSO =over =item * L =item * L =back =head1 AUTHORS =over =item * Ingy döt Net =item * Audrey Tang =back =head1 COPYRIGHT Copyright 2006-2014. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut Module-Compile-0.35/lib/Module/Compile.pm0000644000175000017500000004046712446625715016722 0ustar ingyingy# To Do: # # - Make preface part of parsed code, since it might contain `package` # statements or other scoping stuff. # - Build code into an AST. use strict; use warnings; package Module::Compile; our $VERSION = '0.35'; use Digest::SHA1(); # A lexical hash to keep track of which files have already been filtered my $filtered = {}; # A map of digests to code blocks my $digest_map = {}; # All subroutines are prefixed with pmc_ so subclasses don't # accidentally override things they didn't intend to. # Determine which stack frame points to the code we are filtering. # This is a method in case it needs to be overridden. sub pmc_caller_stack_frame { 0 }; # This is called while parsing source code to determine if the # module/class in a use/no line is part of the Module::Compile game. # # Return true if this class supports PMC compilation. # # The hope is that this will allow interoperability with modules that # do not inherit from Module::Compile but still want to do this sort # of thing. sub pmc_is_compiler_module { 1 }; sub new { return bless {}, shift; } # This is called to determine whether the meaning of use/no is reversed. sub pmc_use_means_no { 0 } # This is called to determine whether the use line means a one line section. sub pmc_use_means_now { 0 } # All Module::Compile based modules inherit this import routine. sub import { my ($class) = @_; return if $class->pmc_use_means_no; goto &{$class->can('pmc_import')}; } # Treat unimport like import if use means no sub unimport { my ($class) = @_; return unless $class->pmc_use_means_no; goto &{$class->can('pmc_import')}; } sub pmc_import { my ($class, @args) = @_; # Handler modules can do `use Module::Compile -base;`. Make them ISA # Module::Compile and get the hell out of Dodge. $class->pmc_set_base(@args) and return; my ($module, $line) = (caller($class->pmc_caller_stack_frame))[1, 2]; return if $filtered->{$module}++; my $callback = sub { my ($class, $content, $data) = @_; my $output = $class->pmc_template($module, $content, $data); $class->pmc_output($module, $output); }; $class->pmc_check_compiled_file($module); $class->pmc_filter($module, $line, $callback); # Is there a meaningful return value here? return; } # File might not be a module (.pm) and might be compiled already. # If so, run the compiled file. sub pmc_check_compiled_file { my ($class, $file) = @_; if (defined $file and $file !~ /\.pm$/i) { # Do the freshness check ourselves my $pmc = $file.'c'; $class->pmc_run_compiled_file($pmc), die if -s $pmc and (-M $pmc <= -M $file); } } sub pmc_run_compiled_file { my ($class, $pmc) = @_; my ($package) = caller($class->pmc_file_caller_frame()); eval "package $package; do \$pmc"; die $@ if $@; exit 0; } sub pmc_file_caller_frame { 2 } # Set up inheritance sub pmc_set_base { my ($class, $flag) = @_; # Handle the `use Module::Compile -base;` command. if ($class->isa(__PACKAGE__) and defined $flag and $flag eq '-base') { my $descendant = (caller 1)[0];; no strict 'refs'; push @{$descendant . '::ISA'}, $class; return 1; } return 0; } # Generate the actual code that will go into the .pmc file. sub pmc_template { my ($class, $module, $content, $data) = @_; my $base = __PACKAGE__; my $check = $class->freshness_check($module); my $version = $class->VERSION || '0'; return join "\n", "# Generated by $class $version ($base $VERSION) - do not edit!", "$check$content$data"; } # This returns a piece of Perl code to do a runtime check to see if the # .pmc file is fresh. By default we use a 32-bit running checksum. sub freshness_check { my ($class, $module) = @_; my $sum = sprintf('%08X', do { local $/; open my $fh, "<", $module or die "Cannot open $module: $!"; binmode($fh, ':crlf'); # normalize CRLF for consistent checksum unpack('%32N*', <$fh>); }); return << "..."; ################((( 32-bit Checksum Validator III )))################ #line 1 BEGIN { use 5.006; local (*F, \$/); (\$F = __FILE__) =~ s!c\$!!; open(F) or die "Cannot open \$F: \$!"; binmode(F, ':crlf'); if (unpack('%32N*', \$F=readline(*F)) != 0x$sum) { use Filter::Util::Call; my \$f = \$F; filter_add(sub { filter_del(); 1 while &filter_read; \$_ = \$f; 1; })}} #line 1 ... } # Write the output to the .pmc file sub pmc_output { my ($class, $module, $output) = @_; $class->pmc_can_output($module) or return 0; my $pmc = $module . 'c'; # If we can't open the file, just return. The filtering will not be cached, # but that might be ok. open my $fh, ">", $pmc or return 0; # Protect against disk full or whatever else. local $@; eval { print $fh $output or die; close $fh or die; }; if ( my $e = $@ ) { # close $fh? die if unlink? if ( -e $pmc ) { unlink $pmc or die "Can't delete errant $pmc: $!"; } return 0; } return 1; } # Check whether output can be written. sub pmc_can_output { my ($class, $file_path) = @_; return 1; # return $file_path =~ /\.pm$/; } # We use a source filter to get all the code for compiling. sub pmc_filter { my ($class, $module, $line_number, $post_process) = @_; # Read original module source code instead of taking from filter, # because we need all the lines including the ones before the `use` # statement, so we can parse Perl into packages and such. open my $fh, $module or die "Can't open $module for input:\n$!"; my $module_content = do { local $/; <$fh> }; close $fh; # Find the real __DATA__ or __END__ line. (Not one hidden in a Pod # section or heredoc). my $folded_content = $class->pmc_fold_blocks($module_content); my $folded_data = ''; if ($folded_content =~ s/^((?:__(?:DATA|END)__$).*)//ms) { $folded_data = $1; } my $real_content = $class->pmc_unfold_blocks($folded_content); my $real_data = $class->pmc_unfold_blocks($folded_data); # Calculate the number of lines to skip in the source filter, since # we already have them in $real_content. my @lines = ($real_content =~ /(.*\n)/g); my $lines_to_skip = @lines; $lines_to_skip -= $line_number; # Use filter to skip past that many lines # Leave __DATA__ section intact my $done = 0; require Filter::Util::Call; Filter::Util::Call::filter_add(sub { return 0 if $done; my $data_line = ''; while (1) { my $status = Filter::Util::Call::filter_read(); last unless $status; return $status if $status < 0; # Skip lines up to the DATA section. next if $lines_to_skip-- > 0; if (/^__(?:END|DATA)__$/) { # Don't filter the DATA section, or else the DATA file # handle becomes invalid. # XXX - Maybe there is a way to simply recreate the DATA # file handle, or at least seek back to the start of it. # Needs investigation. # For now this means that we only allow compilation on # the module content; not the DATA section. Because we # want to make sure that the program runs the same way # as both a .pm and a .pmc. $data_line = $_; last; } } continue { $_ = ''; } $real_content =~ s/\r//g; my $filtered_content = $class->pmc_process($real_content); $class->$post_process($filtered_content, $real_data); $filtered_content =~ s/(.*\n){$line_number}//; $_ = $filtered_content . $data_line; $done = 1; }); } use constant TEXT => 0; use constant CONTEXT => 1; use constant CLASSES => 2; # Break the code into blocks. Compile the blocks. # Fold out heredocs etc # Parse the code into packages, blocks and subs # Parse the code by `use/no *::Compiler` # Build an AST # Reduce the AST until fully reduced # Return the result sub pmc_process { my $class = shift; my $data = shift; my @blocks = $class->pmc_parse_blocks($data); while (@blocks = $class->pmc_reduce(@blocks)) { if (@blocks == 1 and @{$blocks[0][CLASSES]} == 0) { my $content = $blocks[0][TEXT]; $content .= "\n" unless $content =~ /\n\z/; return $content; } } die "How did I get here?!?"; } # Analyze the remaining blocks and determine which compilers to call to reduce # the problem. # # XXX This routine must do some kind of reduction each pass, or infinite loop # will ensue. It is not yet certain if this is the case. sub pmc_reduce { my $class = shift; my @blocks; my $prev; while (@_) { my $block = shift; my $next = $_[TEXT]; if ($next and "@{$block->[CLASSES]}" eq "@{$next->[CLASSES]}") { shift; $block->[TEXT] .= $next->[TEXT]; } elsif ( (not $prev or @{$prev->[CLASSES]} < @{$block->[CLASSES]}) and (not $next or @{$next->[CLASSES]} < @{$block->[CLASSES]}) ) { my $prev_len = $prev ? @{$prev->[CLASSES]} : 0; my $next_len = $next ? @{$next->[CLASSES]} : 0; my $offset = ($prev_len > $next_len) ? $prev_len : $next_len; my $length = @{$block->[CLASSES]} - $offset; $class->pmc_call($block, $offset, $length); } push @blocks, $block; $prev = $block; } return @blocks; } # Call a set of compilers on a piece of source code. sub pmc_call { my $class = shift; my $block = shift; my $offset = shift; my $length = shift; my $text = $block->[TEXT]; my $context = $block->[CONTEXT]; my @classes = splice(@{$block->[CLASSES]}, $offset, $length); for my $klass (@classes) { local $_ = $text; my $return = $klass->pmc_compile($text, ($context->{$klass} || {})); $text = (defined $return and $return !~ /^\d+\z/) ? $return : $_; } $block->[TEXT] = $text; } # Divide a Perl module into blocks. This code divides a module based on # lines that use/no a Module::Compile subclass. sub pmc_parse_blocks { my $class = shift; my $data = shift; my @blocks = (); my @classes = (); my $context = {}; my $text = ''; my @parts = split /^([^\S\n]*(?:use|no)[^\S\n]+[\w\:\']+[^\n]*\n)/m, $data; for my $part (@parts) { if ($part =~ /^[^\S\n]*(use|no)[^\S\n]+([\w\:\']+)[^\n]*\n/) { my ($use, $klass, $file) = ($1, $2, $2); $file =~ s{(?:::|')}{/}g; if ($klass =~ /^\d+$/) { $text .= $part; next; } { local $@; eval { require "$file.pm" }; die $@ if $@ and "$@" !~ /^Can't locate /; } if ($klass->can('pmc_is_compiler_module') and $klass->pmc_is_compiler_module) { push @blocks, [$text, {%$context}, [@classes]]; $text = ''; @classes = grep {$_ ne $klass} @classes; if (($use eq 'use') xor $klass->pmc_use_means_no) { push @classes, $klass; $context->{$klass} = {%{$context->{$klass} || {}}}; $context->{$klass}{use} = $part; if ($klass->pmc_use_means_now) { push @blocks, ['', {%$context}, [@classes]]; @classes = grep {$_ ne $klass} @classes; delete $context->{$klass}; } } else { delete $context->{$klass}; } } else { $text .= $part; } } else { $text .= $part; } } push @blocks, [$text, {%$context}, [@classes]] if length $text; return @blocks; } # Compile/Filter some source code into something else. This is almost # always overridden in a subclass. sub pmc_compile { my ($class, $source_code_string, $context_hashref) = @_; return $source_code_string; } # Regexp fragments for matching heredoc, pod section, comment block and # data section. my $re_here = qr/ (?: # Heredoc starting line ^ # Start of some line ((?-s:.*?)) # $2 - text before heredoc marker <<(?!=) # heredoc marker [\t\x20]* # whitespace between marker and quote ((?>['"]?)) # $3 - possible left quote ([\w\-\.]*) # $4 - heredoc terminator (\3 # $5 - possible right quote (?-s:.*\n)) # and rest of the line (.*?\n) # $6 - Heredoc content (?pmc_fold_data() : $result =~ m{\A($re_pod)} ? $class->pmc_fold_pod() : $result =~ m{\A($re_comment)} ? $class->pmc_fold_comment() : $result =~ m{\A($re_here)} ? $class->pmc_fold_here() : die "'$result' didn't match '$re_comment'"; /ex or last; } $source =~ s/(?{$match} /xmeg; return $source; } # Fold a heredoc's content but don't fold other heredocs from the # same line. sub pmc_fold_here { my $class = shift; my $result = "$2~~~$3$4$5"; my $preface = ''; my $text = $6; my $stop = $7; while (1) { if ($text =~ s!^(([0-9a-fA-F]{40})\n.*\n)!!) { if (defined $digest_map->{$2}) { $preface .= $1; next; } else { $text = $1 . $text; last; } } last; } my $digest = $class->pmc_fold($text); $result = "$result$preface$digest\n$stop"; $result; } sub pmc_fold_pod { my $class = shift; my $text = $1; my $digest = $class->pmc_fold($text); return qq{===pod $digest\n===cut\n}; } sub pmc_fold_comment { my $class = shift; my $text = $1; my $digest = $class->pmc_fold($text); return qq{``` $digest\n}; } sub pmc_fold_data { my $class = shift; my $text = $1; my $digest = $class->pmc_fold($text); return qq{''' $digest\n}; } # Fold a piece of code into a unique string. sub pmc_fold { require Digest::SHA1; my ($class, $text) = @_; my $digest = Digest::SHA1::sha1_hex($text); $digest_map->{$digest} = $text; return $digest; } # Expand folded code into original content. sub pmc_unfold { my ($class, $digest) = @_; return $digest_map->{$digest}; } 1; Module-Compile-0.35/MANIFEST0000644000175000017500000000115112446625715014115 0ustar ingyingy# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.019. CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README inc/Spiffy.pm inc/Test/Base.pm inc/Test/Base/Filter.pm lib/Module/Compile.pm lib/Module/Compile.pod lib/Module/Compile/Opt.pm lib/Module/Compile/Opt.pod lib/Module/Compile/Optimize.pod lib/Module/Optimize.pm t/000-compile-modules.t t/TestModuleCompile.pm t/Testorz.pm t/compile.t t/data1.t t/data2.t t/fold_blocks.t t/lexical.t t/lib/DataTest.pm t/lib/Foo.pm t/lib/Indented.pm t/lib/Pre.p t/lib/Upper.pm t/orz.t t/parse.t t/pm.t t/pmc.t t/release-pod-syntax.t Module-Compile-0.35/Changes0000644000175000017500000000446612446625715014273 0ustar ingyingy0.35 Wed Dec 24 13:10:28 PST 2014 - Remove Module::Install::PMC from dist 0.34 Sat Aug 16 16:09:53 PDT 2014 - Fix strict/warnings 0.33 Sat Aug 16 15:31:37 PDT 2014 - Fix comments 0.32 Sat Aug 16 15:26:25 PDT 2014 - Change pod to swim 0.31 Sat Aug 16 14:07:04 PDT 2014 - Remove =travis section 0.30 Sat Aug 16 11:32:59 PDT 2014 - Meta 0.0.2 0.29 Sat Aug 16 03:49:25 PDT 2014 - Eliminate spurious trailing whitespace 0.28 Sat Aug 16 02:19:16 PDT 2014 - Eliminate File::Basename 0.27 Fri Aug 15 18:45:31 PDT 2014 - Add t/000-compile-modules.t 0.26 Wed Aug 13 12:13:45 PDT 2014 - Fix tests to use `inc` for Test::Base 0.25 Wed Aug 13 11:23:45 PDT 2014 - Fix indexing by not splitting VERSION lines (Module::Install modules) 0.24 Tue Aug 12 12:29:12 PDT 2014 - Switch to Zilla::Dist 0.23 Tue Jun 14 00:09:03 EST 2011 - Release with Module::Package 0.25 to fix previous issues. 0.22 Sun Jun 12 03:46:23 EST 2011 - Add Digest::SHA1 to deps 0.21 Fri Jun 10 22:04:26 EST 2011 - Make modern - Switch to Module::Package - Use Stardoc - Move out of Kwiki repo 0.20 Tue Oct 17 02:16:18 PDT 2006 - Removed a leftover 'use XXX;' that made tests fail. 0.19 Sun Oct 1 10:05:13 CST 2006 - Recognize whitespace after the heredoc marker, e.g. "<< 'FOO'" - Don't treat a literal '<<' string by itself as a heredoc marker. - Don't treat '<<=' as a heredoc marker. - Support 'use_means_now'. 0.18 Mon Jul 17 14:33:39 PDT 2006 - Patch from ruoso to make Makefile .pmc targets dep on .pm files. - Refactor caller stack number into a method. 0.17 Sun Jul 2 22:36:34 CDT 2006 - Support for compiling non-module files. 0.16 Mon Jun 26 11:50:46 CDT 2006 - Pugs tree changes - Support v6 0.15 Sun Mar 26 12:34:58 PST 2006 - Added ability to fold out potentially conflicting code. - Added a context block to pass more info to compilers. 0.14 Tue Mar 14 13:02:11 PST 2006 - Added Module::Install support for pmc - Lots of nice changes by audreyt 0.13 Mon Mar 13 06:49:18 PST 2006 - Applied a freshness_check patch from audreyt - Added a ToDo list - Apostrophe is a package delimiter. 0.12 Sun Mar 12 10:56:26 PST 2006 - Don't allow .pl -> .plc 0.11 Sun Mar 12 10:05:47 PST 2006 - Fixed API bugs - Fixed Doc - Applied changes from audreyt - Added stub for freshness check 0.10 Sun Mar 12 05:47:06 PST 2006 - Maiden voyage Module-Compile-0.35/CONTRIBUTING0000644000175000017500000000243712446625715014626 0ustar ingyingyContributing ============ The "Module-Compile" Project needs your help! Please consider being a contributor. This file contains instructions that will help you be an effective contributor to the Project. GitHub ------ The code for this Project is hosted at GitHub. The URL is: https://github.com/ingydotnet/module-compile-pm You can get the code with this command: git clone https://github.com/ingydotnet/module-compile-pm If you've found a bug or a missing feature that you would like the author to know about, report it here: https://github.com/ingydotnet/module-compile-pm/issues or fix it and submit a pull request here: https://github.com/ingydotnet/module-compile-pm/pulls See these links for help on interacting with GitHub: * https://help.github.com/ * https://help.github.com/articles/creating-a-pull-request Zilla::Dist ----------- This Project uses Zilla::Dist to prepare it for publishing to CPAN. Read: https://metacpan.org/pod/Zilla::Dist::Contributing for up-to-date instructions on what contributors like yourself need to know to use it. IRC --- Module-Compile has an IRC channel where you can find real people to help you: irc.perl.org#pkg Join the channel. Join the team! Thanks in advance, Ingy döt Net # This file generated by Zilla-Dist-0.0.179 Module-Compile-0.35/META.json0000644000175000017500000000246112446625715014412 0ustar ingyingy{ "abstract" : "Perl Module Compilation", "author" : [ "Ingy döt Net " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.132830", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Module-Compile", "no_index" : { "directory" : [ "inc", "t", "xt", "example" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "Digest::SHA1" : "2.13", "perl" : "v5.8.1" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ingydotnet/module-compile-pm/issues" }, "homepage" : "https://github.com/ingydotnet/module-compile-pm", "repository" : { "type" : "git", "url" : "https://github.com/ingydotnet/module-compile-pm.git", "web" : "https://github.com/ingydotnet/module-compile-pm" } }, "version" : "0.35" } Module-Compile-0.35/inc/0000755000175000017500000000000012446625715013537 5ustar ingyingyModule-Compile-0.35/inc/Spiffy.pm0000644000175000017500000003617512446625715015351 0ustar ingyingyuse strict; use warnings; package Spiffy; our $VERSION = '0.40'; use Carp; require Exporter; our @EXPORT = (); our @EXPORT_BASE = qw(field const stub super); our @EXPORT_OK = (@EXPORT_BASE, qw(id WWW XXX YYY ZZZ)); our %EXPORT_TAGS = (XXX => [qw(WWW XXX YYY ZZZ)]); my $stack_frame = 0; my $dump = 'yaml'; my $bases_map = {}; sub WWW; sub XXX; sub YYY; sub ZZZ; # This line is here to convince "autouse" into believing we are autousable. sub can { ($_[1] eq 'import' and caller()->isa('autouse')) ? \&Exporter::import # pacify autouse's equality test : $_[0]->SUPER::can($_[1]) # normal case } # TODO # # Exported functions like field and super should be hidden so as not to # be confused with methods that can be inherited. # sub new { my $class = shift; $class = ref($class) || $class; my $self = bless {}, $class; while (@_) { my $method = shift; $self->$method(shift); } return $self; } my $filtered_files = {}; my $filter_dump = 0; my $filter_save = 0; our $filter_result = ''; sub import { no strict 'refs'; no warnings; my $self_package = shift; # XXX Using parse_arguments here might cause confusion, because the # subclass's boolean_arguments and paired_arguments can conflict, causing # difficult debugging. Consider using something truly local. my ($args, @export_list) = do { local *boolean_arguments = sub { qw( -base -Base -mixin -selfless -XXX -dumper -yaml -filter_dump -filter_save ) }; local *paired_arguments = sub { qw(-package) }; $self_package->parse_arguments(@_); }; return spiffy_mixin_import(scalar(caller(0)), $self_package, @export_list) if $args->{-mixin}; $filter_dump = 1 if $args->{-filter_dump}; $filter_save = 1 if $args->{-filter_save}; $dump = 'yaml' if $args->{-yaml}; $dump = 'dumper' if $args->{-dumper}; local @EXPORT_BASE = @EXPORT_BASE; if ($args->{-XXX}) { push @EXPORT_BASE, @{$EXPORT_TAGS{XXX}} unless grep /^XXX$/, @EXPORT_BASE; } spiffy_filter() if ($args->{-selfless} or $args->{-Base}) and not $filtered_files->{(caller($stack_frame))[1]}++; my $caller_package = $args->{-package} || caller($stack_frame); push @{"$caller_package\::ISA"}, $self_package if $args->{-Base} or $args->{-base}; for my $class (@{all_my_bases($self_package)}) { next unless $class->isa('Spiffy'); my @export = grep { not defined &{"$caller_package\::$_"}; } ( @{"$class\::EXPORT"}, ($args->{-Base} or $args->{-base}) ? @{"$class\::EXPORT_BASE"} : (), ); my @export_ok = grep { not defined &{"$caller_package\::$_"}; } @{"$class\::EXPORT_OK"}; # Avoid calling the expensive Exporter::export # if there is nothing to do (optimization) my %exportable = map { ($_, 1) } @export, @export_ok; next unless keys %exportable; my @export_save = @{"$class\::EXPORT"}; my @export_ok_save = @{"$class\::EXPORT_OK"}; @{"$class\::EXPORT"} = @export; @{"$class\::EXPORT_OK"} = @export_ok; my @list = grep { (my $v = $_) =~ s/^[\!\:]//; $exportable{$v} or ${"$class\::EXPORT_TAGS"}{$v}; } @export_list; Exporter::export($class, $caller_package, @list); @{"$class\::EXPORT"} = @export_save; @{"$class\::EXPORT_OK"} = @export_ok_save; } } sub spiffy_filter { require Filter::Util::Call; my $done = 0; Filter::Util::Call::filter_add( sub { return 0 if $done; my ($data, $end) = ('', ''); while (my $status = Filter::Util::Call::filter_read()) { return $status if $status < 0; if (/^__(?:END|DATA)__\r?$/) { $end = $_; last; } $data .= $_; $_ = ''; } $_ = $data; my @my_subs; s[^(sub\s+\w+\s+\{)(.*\n)] [${1}my \$self = shift;$2]gm; s[^(sub\s+\w+)\s*\(\s*\)(\s+\{.*\n)] [${1}${2}]gm; s[^my\s+sub\s+(\w+)(\s+\{)(.*)((?s:.*?\n))\}\n] [push @my_subs, $1; "\$$1 = sub$2my \$self = shift;$3$4\};\n"]gem; my $preclare = ''; if (@my_subs) { $preclare = join ',', map "\$$_", @my_subs; $preclare = "my($preclare);"; } $_ = "use strict;use warnings;$preclare${_};1;\n$end"; if ($filter_dump) { print; exit } if ($filter_save) { $filter_result = $_; $_ = $filter_result; } $done = 1; } ); } sub base { push @_, -base; goto &import; } sub all_my_bases { my $class = shift; return $bases_map->{$class} if defined $bases_map->{$class}; my @bases = ($class); no strict 'refs'; for my $base_class (@{"${class}::ISA"}) { push @bases, @{all_my_bases($base_class)}; } my $used = {}; $bases_map->{$class} = [grep {not $used->{$_}++} @bases]; } my %code = ( sub_start => "sub {\n", set_default => " \$_[0]->{%s} = %s\n unless exists \$_[0]->{%s};\n", init => " return \$_[0]->{%s} = do { my \$self = \$_[0]; %s }\n" . " unless \$#_ > 0 or defined \$_[0]->{%s};\n", weak_init => " return do {\n" . " \$_[0]->{%s} = do { my \$self = \$_[0]; %s };\n" . " Scalar::Util::weaken(\$_[0]->{%s}) if ref \$_[0]->{%s};\n" . " \$_[0]->{%s};\n" . " } unless \$#_ > 0 or defined \$_[0]->{%s};\n", return_if_get => " return \$_[0]->{%s} unless \$#_ > 0;\n", set => " \$_[0]->{%s} = \$_[1];\n", weaken => " Scalar::Util::weaken(\$_[0]->{%s}) if ref \$_[0]->{%s};\n", sub_end => " return \$_[0]->{%s};\n}\n", ); sub field { my $package = caller; my ($args, @values) = do { no warnings; local *boolean_arguments = sub { (qw(-weak)) }; local *paired_arguments = sub { (qw(-package -init)) }; Spiffy->parse_arguments(@_); }; my ($field, $default) = @values; $package = $args->{-package} if defined $args->{-package}; die "Cannot have a default for a weakened field ($field)" if defined $default && $args->{-weak}; return if defined &{"${package}::$field"}; require Scalar::Util if $args->{-weak}; my $default_string = ( ref($default) eq 'ARRAY' and not @$default ) ? '[]' : (ref($default) eq 'HASH' and not keys %$default ) ? '{}' : default_as_code($default); my $code = $code{sub_start}; if ($args->{-init}) { my $fragment = $args->{-weak} ? $code{weak_init} : $code{init}; my @count = ($fragment =~ /(%s)/g); $code .= sprintf $fragment, $field, $args->{-init}, ($field) x (@count - 2); } $code .= sprintf $code{set_default}, $field, $default_string, $field if defined $default; $code .= sprintf $code{return_if_get}, $field; $code .= sprintf $code{set}, $field; $code .= sprintf $code{weaken}, $field, $field if $args->{-weak}; $code .= sprintf $code{sub_end}, $field; my $sub = eval $code; die $@ if $@; no strict 'refs'; *{"${package}::$field"} = $sub; return $code if defined wantarray; } sub default_as_code { require Data::Dumper; local $Data::Dumper::Sortkeys = 1; my $code = Data::Dumper::Dumper(shift); $code =~ s/^\$VAR1 = //; $code =~ s/;$//; return $code; } sub const { my $package = caller; my ($args, @values) = do { no warnings; local *paired_arguments = sub { (qw(-package)) }; Spiffy->parse_arguments(@_); }; my ($field, $default) = @values; $package = $args->{-package} if defined $args->{-package}; no strict 'refs'; return if defined &{"${package}::$field"}; *{"${package}::$field"} = sub { $default } } sub stub { my $package = caller; my ($args, @values) = do { no warnings; local *paired_arguments = sub { (qw(-package)) }; Spiffy->parse_arguments(@_); }; my ($field, $default) = @values; $package = $args->{-package} if defined $args->{-package}; no strict 'refs'; return if defined &{"${package}::$field"}; *{"${package}::$field"} = sub { require Carp; Carp::confess "Method $field in package $package must be subclassed"; } } sub parse_arguments { my $class = shift; my ($args, @values) = ({}, ()); my %booleans = map { ($_, 1) } $class->boolean_arguments; my %pairs = map { ($_, 1) } $class->paired_arguments; while (@_) { my $elem = shift; if (defined $elem and defined $booleans{$elem}) { $args->{$elem} = (@_ and $_[0] =~ /^[01]$/) ? shift : 1; } elsif (defined $elem and defined $pairs{$elem} and @_) { $args->{$elem} = shift; } else { push @values, $elem; } } return wantarray ? ($args, @values) : $args; } sub boolean_arguments { () } sub paired_arguments { () } # get a unique id for any node sub id { if (not ref $_[0]) { return 'undef' if not defined $_[0]; \$_[0] =~ /\((\w+)\)$/o or die; return "$1-S"; } require overload; overload::StrVal($_[0]) =~ /\((\w+)\)$/o or die; return $1; } #=============================================================================== # It's super, man. #=============================================================================== package DB; { no warnings 'redefine'; sub super_args { my @dummy = caller(@_ ? $_[0] : 2); return @DB::args; } } package Spiffy; sub super { my $method; my $frame = 1; while ($method = (caller($frame++))[3]) { $method =~ s/.*::// and last; } my @args = DB::super_args($frame); @_ = @_ ? ($args[0], @_) : @args; my $class = ref $_[0] ? ref $_[0] : $_[0]; my $caller_class = caller; my $seen = 0; my @super_classes = reverse grep { ($seen or $seen = ($_ eq $caller_class)) ? 0 : 1; } reverse @{all_my_bases($class)}; for my $super_class (@super_classes) { no strict 'refs'; next if $super_class eq $class; if (defined &{"${super_class}::$method"}) { ${"$super_class\::AUTOLOAD"} = ${"$class\::AUTOLOAD"} if $method eq 'AUTOLOAD'; return &{"${super_class}::$method"}; } } return; } #=============================================================================== # This code deserves a spanking, because it is being very naughty. # It is exchanging base.pm's import() for its own, so that people # can use base.pm with Spiffy modules, without being the wiser. #=============================================================================== my $real_base_import; my $real_mixin_import; BEGIN { require base unless defined $INC{'base.pm'}; $INC{'mixin.pm'} ||= 'Spiffy/mixin.pm'; $real_base_import = \&base::import; $real_mixin_import = \&mixin::import; no warnings; *base::import = \&spiffy_base_import; *mixin::import = \&spiffy_mixin_import; } # my $i = 0; # while (my $caller = caller($i++)) { # next unless $caller eq 'base' or $caller eq 'mixin'; # croak <isa('Spiffy'); } @base_classes; my $inheritor = caller(0); for my $base_class (@base_classes) { next if $inheritor->isa($base_class); croak "Can't mix Spiffy and non-Spiffy classes in 'use base'.\n", "See the documentation of Spiffy.pm for details\n " unless $base_class->isa('Spiffy'); $stack_frame = 1; # tell import to use different caller import($base_class, '-base'); $stack_frame = 0; } } sub mixin { my $self = shift; my $target_class = ref($self); spiffy_mixin_import($target_class, @_) } sub spiffy_mixin_import { my $target_class = shift; $target_class = caller(0) if $target_class eq 'mixin'; my $mixin_class = shift or die "Nothing to mixin"; eval "require $mixin_class"; my @roles = @_; my $pseudo_class = join '-', $target_class, $mixin_class, @roles; my %methods = spiffy_mixin_methods($mixin_class, @roles); no strict 'refs'; no warnings; @{"$pseudo_class\::ISA"} = @{"$target_class\::ISA"}; @{"$target_class\::ISA"} = ($pseudo_class); for (keys %methods) { *{"$pseudo_class\::$_"} = $methods{$_}; } } sub spiffy_mixin_methods { my $mixin_class = shift; no strict 'refs'; my %methods = spiffy_all_methods($mixin_class); map { $methods{$_} ? ($_, \ &{"$methods{$_}\::$_"}) : ($_, \ &{"$mixin_class\::$_"}) } @_ ? (get_roles($mixin_class, @_)) : (keys %methods); } sub get_roles { my $mixin_class = shift; my @roles = @_; while (grep /^!*:/, @roles) { @roles = map { s/!!//g; /^!:(.*)/ ? do { my $m = "_role_$1"; map("!$_", $mixin_class->$m); } : /^:(.*)/ ? do { my $m = "_role_$1"; ($mixin_class->$m); } : ($_) } @roles; } if (@roles and $roles[0] =~ /^!/) { my %methods = spiffy_all_methods($mixin_class); unshift @roles, keys(%methods); } my %roles; for (@roles) { s/!!//g; delete $roles{$1}, next if /^!(.*)/; $roles{$_} = 1; } keys %roles; } sub spiffy_all_methods { no strict 'refs'; my $class = shift; return if $class eq 'Spiffy'; my %methods = map { ($_, $class) } grep { defined &{"$class\::$_"} and not /^_/ } keys %{"$class\::"}; my %super_methods; %super_methods = spiffy_all_methods(${"$class\::ISA"}[0]) if @{"$class\::ISA"}; %{{%super_methods, %methods}}; } # END of naughty code. #=============================================================================== # Debugging support #=============================================================================== sub spiffy_dump { no warnings; if ($dump eq 'dumper') { require Data::Dumper; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 1; return Data::Dumper::Dumper(@_); } require YAML; $YAML::UseVersion = 0; return YAML::Dump(@_) . "...\n"; } sub at_line_number { my ($file_path, $line_number) = (caller(1))[1,2]; " at $file_path line $line_number\n"; } sub WWW { warn spiffy_dump(@_) . at_line_number; return wantarray ? @_ : $_[0]; } sub XXX { die spiffy_dump(@_) . at_line_number; } sub YYY { print spiffy_dump(@_) . at_line_number; return wantarray ? @_ : $_[0]; } sub ZZZ { require Carp; Carp::confess spiffy_dump(@_); } 1; Module-Compile-0.35/inc/Test/0000755000175000017500000000000012446625715014456 5ustar ingyingyModule-Compile-0.35/inc/Test/Base/0000755000175000017500000000000012446625715015330 5ustar ingyingyModule-Compile-0.35/inc/Test/Base/Filter.pm0000644000175000017500000001573512446625715017126 0ustar ingyingy#=============================================================================== # This is the default class for handling Test::Base data filtering. #=============================================================================== package Test::Base::Filter; use Spiffy -Base; use Spiffy ':XXX'; field 'current_block'; our $arguments; sub current_arguments { return undef unless defined $arguments; my $args = $arguments; $args =~ s/(\\s)/ /g; $args =~ s/(\\[a-z])/'"' . $1 . '"'/gee; return $args; } sub assert_scalar { return if @_ == 1; require Carp; my $filter = (caller(1))[3]; $filter =~ s/.*:://; Carp::croak "Input to the '$filter' filter must be a scalar, not a list"; } sub _apply_deepest { my $method = shift; return () unless @_; if (ref $_[0] eq 'ARRAY') { for my $aref (@_) { @$aref = $self->_apply_deepest($method, @$aref); } return @_; } $self->$method(@_); } sub _split_array { map { [$self->split($_)]; } @_; } sub _peel_deepest { return () unless @_; if (ref $_[0] eq 'ARRAY') { if (ref $_[0]->[0] eq 'ARRAY') { for my $aref (@_) { @$aref = $self->_peel_deepest(@$aref); } return @_; } return map { $_->[0] } @_; } return @_; } #=============================================================================== # these filters work on the leaves of nested arrays #=============================================================================== sub Join { $self->_peel_deepest($self->_apply_deepest(join => @_)) } sub Reverse { $self->_apply_deepest(reverse => @_) } sub Split { $self->_apply_deepest(_split_array => @_) } sub Sort { $self->_apply_deepest(sort => @_) } sub append { my $suffix = $self->current_arguments; map { $_ . $suffix } @_; } sub array { return [@_]; } sub base64_decode { $self->assert_scalar(@_); require MIME::Base64; MIME::Base64::decode_base64(shift); } sub base64_encode { $self->assert_scalar(@_); require MIME::Base64; MIME::Base64::encode_base64(shift); } sub chomp { map { CORE::chomp; $_ } @_; } sub chop { map { CORE::chop; $_ } @_; } sub dumper { no warnings 'once'; require Data::Dumper; local $Data::Dumper::Sortkeys = 1; local $Data::Dumper::Indent = 1; local $Data::Dumper::Terse = 1; Data::Dumper::Dumper(@_); } sub escape { $self->assert_scalar(@_); my $text = shift; $text =~ s/(\\.)/eval "qq{$1}"/ge; return $text; } sub eval { $self->assert_scalar(@_); my @return = CORE::eval(shift); return $@ if $@; return @return; } sub eval_all { $self->assert_scalar(@_); my $out = ''; my $err = ''; Test::Base::tie_output(*STDOUT, $out); Test::Base::tie_output(*STDERR, $err); my $return = CORE::eval(shift); no warnings; untie *STDOUT; untie *STDERR; return $return, $@, $out, $err; } sub eval_stderr { $self->assert_scalar(@_); my $output = ''; Test::Base::tie_output(*STDERR, $output); CORE::eval(shift); no warnings; untie *STDERR; return $output; } sub eval_stdout { $self->assert_scalar(@_); my $output = ''; Test::Base::tie_output(*STDOUT, $output); CORE::eval(shift); no warnings; untie *STDOUT; return $output; } sub exec_perl_stdout { my $tmpfile = "/tmp/test-blocks-$$"; $self->_write_to($tmpfile, @_); open my $execution, "$^X $tmpfile 2>&1 |" or die "Couldn't open subprocess: $!\n"; local $/; my $output = <$execution>; close $execution; unlink($tmpfile) or die "Couldn't unlink $tmpfile: $!\n"; return $output; } sub flatten { $self->assert_scalar(@_); my $ref = shift; if (ref($ref) eq 'HASH') { return map { ($_, $ref->{$_}); } sort keys %$ref; } if (ref($ref) eq 'ARRAY') { return @$ref; } die "Can only flatten a hash or array ref"; } sub get_url { $self->assert_scalar(@_); my $url = shift; CORE::chomp($url); require LWP::Simple; LWP::Simple::get($url); } sub hash { return +{ @_ }; } sub head { my $size = $self->current_arguments || 1; return splice(@_, 0, $size); } sub join { my $string = $self->current_arguments; $string = '' unless defined $string; CORE::join $string, @_; } sub lines { $self->assert_scalar(@_); my $text = shift; return () unless length $text; my @lines = ($text =~ /^(.*\n?)/gm); return @lines; } sub norm { $self->assert_scalar(@_); my $text = shift; $text = '' unless defined $text; $text =~ s/\015\012/\n/g; $text =~ s/\r/\n/g; return $text; } sub prepend { my $prefix = $self->current_arguments; map { $prefix . $_ } @_; } sub read_file { $self->assert_scalar(@_); my $file = shift; CORE::chomp $file; open my $fh, $file or die "Can't open '$file' for input:\n$!"; CORE::join '', <$fh>; } sub regexp { $self->assert_scalar(@_); my $text = shift; my $flags = $self->current_arguments; if ($text =~ /\n.*?\n/s) { $flags = 'xism' unless defined $flags; } else { CORE::chomp($text); } $flags ||= ''; my $regexp = eval "qr{$text}$flags"; die $@ if $@; return $regexp; } sub reverse { CORE::reverse(@_); } sub slice { die "Invalid args for slice" unless $self->current_arguments =~ /^(\d+)(?:,(\d))?$/; my ($x, $y) = ($1, $2); $y = $x if not defined $y; die "Invalid args for slice" if $x > $y; return splice(@_, $x, 1 + $y - $x); } sub sort { CORE::sort(@_); } sub split { $self->assert_scalar(@_); my $separator = $self->current_arguments; if (defined $separator and $separator =~ s{^/(.*)/$}{$1}) { my $regexp = $1; $separator = qr{$regexp}; } $separator = qr/\s+/ unless $separator; CORE::split $separator, shift; } sub strict { $self->assert_scalar(@_); <<'...' . shift; use strict; use warnings; ... } sub tail { my $size = $self->current_arguments || 1; return splice(@_, @_ - $size, $size); } sub trim { map { s/\A([ \t]*\n)+//; s/(?<=\n)\s*\z//g; $_; } @_; } sub unchomp { map { $_ . "\n" } @_; } sub write_file { my $file = $self->current_arguments or die "No file specified for write_file filter"; if ($file =~ /(.*)[\\\/]/) { my $dir = $1; if (not -e $dir) { require File::Path; File::Path::mkpath($dir) or die "Can't create $dir"; } } open my $fh, ">$file" or die "Can't open '$file' for output\n:$!"; print $fh @_; close $fh; return $file; } sub yaml { $self->assert_scalar(@_); require YAML; return YAML::Load(shift); } sub _write_to { my $filename = shift; open my $script, ">$filename" or die "Couldn't open $filename: $!\n"; print $script @_; close $script or die "Couldn't close $filename: $!\n"; } 1; Module-Compile-0.35/inc/Test/Base.pm0000644000175000017500000004332212446625715015672 0ustar ingyingypackage Test::Base; our $VERSION = '0.88'; use Spiffy -Base; use Spiffy ':XXX'; my $HAS_PROVIDER; BEGIN { $HAS_PROVIDER = eval "require Test::Builder::Provider; 1"; if ($HAS_PROVIDER) { Test::Builder::Provider->import('provides'); } else { *provides = sub { 1 }; } } my @test_more_exports; BEGIN { @test_more_exports = qw( ok isnt like unlike is_deeply cmp_ok skip todo_skip pass fail eq_array eq_hash eq_set plan can_ok isa_ok diag use_ok $TODO ); } use Test::More import => \@test_more_exports; use Carp; our @EXPORT = (@test_more_exports, qw( is no_diff blocks next_block first_block delimiters spec_file spec_string filters filters_delay filter_arguments run run_compare run_is run_is_deeply run_like run_unlike skip_all_unless_require is_deep run_is_deep WWW XXX YYY ZZZ tie_output no_diag_on_only find_my_self default_object croak carp cluck confess )); field '_spec_file'; field '_spec_string'; field _filters => [qw(norm trim)]; field _filters_map => {}; field spec => -init => '$self->_spec_init'; field block_list => -init => '$self->_block_list_init'; field _next_list => []; field block_delim => -init => '$self->block_delim_default'; field data_delim => -init => '$self->data_delim_default'; field _filters_delay => 0; field _no_diag_on_only => 0; field block_delim_default => '==='; field data_delim_default => '---'; my $default_class; my $default_object; my $reserved_section_names = {}; sub default_object { $default_object ||= $default_class->new; return $default_object; } my $import_called = 0; sub import() { $import_called = 1; my $class = (grep /^-base$/i, @_) ? scalar(caller) : $_[0]; if (not defined $default_class) { $default_class = $class; } # else { # croak "Can't use $class after using $default_class" # unless $default_class->isa($class); # } unless (grep /^-base$/i, @_) { my @args; for (my $ii = 1; $ii <= $#_; ++$ii) { if ($_[$ii] eq '-package') { ++$ii; } else { push @args, $_[$ii]; } } Test::More->import(import => \@test_more_exports, @args) if @args; } _strict_warnings(); goto &Spiffy::import; } # Wrap Test::Builder::plan my $plan_code = \&Test::Builder::plan; my $Have_Plan = 0; { no warnings 'redefine'; *Test::Builder::plan = sub { $Have_Plan = 1; goto &$plan_code; }; } my $DIED = 0; $SIG{__DIE__} = sub { $DIED = 1; die @_ }; sub block_class { $self->find_class('Block') } sub filter_class { $self->find_class('Filter') } sub find_class { my $suffix = shift; my $class = ref($self) . "::$suffix"; return $class if $class->can('new'); $class = __PACKAGE__ . "::$suffix"; return $class if $class->can('new'); eval "require $class"; return $class if $class->can('new'); die "Can't find a class for $suffix"; } sub check_late { if ($self->{block_list}) { my $caller = (caller(1))[3]; $caller =~ s/.*:://; croak "Too late to call $caller()" } } sub find_my_self() { my $self = ref($_[0]) eq $default_class ? splice(@_, 0, 1) : default_object(); return $self, @_; } sub blocks() { (my ($self), @_) = find_my_self(@_); croak "Invalid arguments passed to 'blocks'" if @_ > 1; croak sprintf("'%s' is invalid argument to blocks()", shift(@_)) if @_ && $_[0] !~ /^[a-zA-Z]\w*$/; my $blocks = $self->block_list; my $section_name = shift || ''; my @blocks = $section_name ? (grep { exists $_->{$section_name} } @$blocks) : (@$blocks); return scalar(@blocks) unless wantarray; return (@blocks) if $self->_filters_delay; for my $block (@blocks) { $block->run_filters unless $block->is_filtered; } return (@blocks); } sub next_block() { (my ($self), @_) = find_my_self(@_); my $list = $self->_next_list; if (@$list == 0) { $list = [@{$self->block_list}, undef]; $self->_next_list($list); } my $block = shift @$list; if (defined $block and not $block->is_filtered) { $block->run_filters; } return $block; } sub first_block() { (my ($self), @_) = find_my_self(@_); $self->_next_list([]); $self->next_block; } sub filters_delay() { (my ($self), @_) = find_my_self(@_); $self->_filters_delay(defined $_[0] ? shift : 1); } sub no_diag_on_only() { (my ($self), @_) = find_my_self(@_); $self->_no_diag_on_only(defined $_[0] ? shift : 1); } sub delimiters() { (my ($self), @_) = find_my_self(@_); $self->check_late; my ($block_delimiter, $data_delimiter) = @_; $block_delimiter ||= $self->block_delim_default; $data_delimiter ||= $self->data_delim_default; $self->block_delim($block_delimiter); $self->data_delim($data_delimiter); return $self; } sub spec_file() { (my ($self), @_) = find_my_self(@_); $self->check_late; $self->_spec_file(shift); return $self; } sub spec_string() { (my ($self), @_) = find_my_self(@_); $self->check_late; $self->_spec_string(shift); return $self; } sub filters() { (my ($self), @_) = find_my_self(@_); if (ref($_[0]) eq 'HASH') { $self->_filters_map(shift); } else { my $filters = $self->_filters; push @$filters, @_; } return $self; } sub filter_arguments() { $Test::Base::Filter::arguments; } sub have_text_diff { eval { require Text::Diff; 1 } && $Text::Diff::VERSION >= 0.35 && $Algorithm::Diff::VERSION >= 1.15; } provides 'is'; sub is($$;$) { (my ($self), @_) = find_my_self(@_); my ($actual, $expected, $name) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1 unless $HAS_PROVIDER; if ($ENV{TEST_SHOW_NO_DIFFS} or not defined $actual or not defined $expected or $actual eq $expected or not($self->have_text_diff) or $expected !~ /\n./s ) { Test::More::is($actual, $expected, $name); } else { $name = '' unless defined $name; ok $actual eq $expected, $name; diag Text::Diff::diff(\$expected, \$actual); } } sub run(&;$) { (my ($self), @_) = find_my_self(@_); my $callback = shift; for my $block (@{$self->block_list}) { $block->run_filters unless $block->is_filtered; &{$callback}($block); } } my $name_error = "Can't determine section names"; sub _section_names { return @_ if @_ == 2; my $block = $self->first_block or croak $name_error; my @names = grep { $_ !~ /^(ONLY|LAST|SKIP)$/; } @{$block->{_section_order}[0] || []}; croak "$name_error. Need two sections in first block" unless @names == 2; return @names; } sub _assert_plan { plan('no_plan') unless $Have_Plan; } sub END { run_compare() unless $Have_Plan or $DIED or not $import_called; } sub run_compare() { (my ($self), @_) = find_my_self(@_); $self->_assert_plan; my ($x, $y) = $self->_section_names(@_); local $Test::Builder::Level = $Test::Builder::Level + 1; for my $block (@{$self->block_list}) { next unless exists($block->{$x}) and exists($block->{$y}); $block->run_filters unless $block->is_filtered; if (ref $block->$x) { is_deeply($block->$x, $block->$y, $block->name ? $block->name : ()); } elsif (ref $block->$y eq 'Regexp') { my $regexp = ref $y ? $y : $block->$y; like($block->$x, $regexp, $block->name ? $block->name : ()); } else { is($block->$x, $block->$y, $block->name ? $block->name : ()); } } } sub run_is() { (my ($self), @_) = find_my_self(@_); $self->_assert_plan; my ($x, $y) = $self->_section_names(@_); local $Test::Builder::Level = $Test::Builder::Level + 1; for my $block (@{$self->block_list}) { next unless exists($block->{$x}) and exists($block->{$y}); $block->run_filters unless $block->is_filtered; is($block->$x, $block->$y, $block->name ? $block->name : () ); } } sub run_is_deeply() { (my ($self), @_) = find_my_self(@_); $self->_assert_plan; my ($x, $y) = $self->_section_names(@_); for my $block (@{$self->block_list}) { next unless exists($block->{$x}) and exists($block->{$y}); $block->run_filters unless $block->is_filtered; is_deeply($block->$x, $block->$y, $block->name ? $block->name : () ); } } sub run_like() { (my ($self), @_) = find_my_self(@_); $self->_assert_plan; my ($x, $y) = $self->_section_names(@_); for my $block (@{$self->block_list}) { next unless exists($block->{$x}) and defined($y); $block->run_filters unless $block->is_filtered; my $regexp = ref $y ? $y : $block->$y; like($block->$x, $regexp, $block->name ? $block->name : () ); } } sub run_unlike() { (my ($self), @_) = find_my_self(@_); $self->_assert_plan; my ($x, $y) = $self->_section_names(@_); for my $block (@{$self->block_list}) { next unless exists($block->{$x}) and defined($y); $block->run_filters unless $block->is_filtered; my $regexp = ref $y ? $y : $block->$y; unlike($block->$x, $regexp, $block->name ? $block->name : () ); } } sub skip_all_unless_require() { (my ($self), @_) = find_my_self(@_); my $module = shift; eval "require $module; 1" or Test::More::plan( skip_all => "$module failed to load" ); } sub is_deep() { (my ($self), @_) = find_my_self(@_); require Test::Deep; Test::Deep::cmp_deeply(@_); } sub run_is_deep() { (my ($self), @_) = find_my_self(@_); $self->_assert_plan; my ($x, $y) = $self->_section_names(@_); for my $block (@{$self->block_list}) { next unless exists($block->{$x}) and exists($block->{$y}); $block->run_filters unless $block->is_filtered; is_deep($block->$x, $block->$y, $block->name ? $block->name : () ); } } sub _pre_eval { my $spec = shift; return $spec unless $spec =~ s/\A\s*<<<(.*?)>>>\s*$//sm; my $eval_code = $1; eval "package main; $eval_code"; croak $@ if $@; return $spec; } sub _block_list_init { my $spec = $self->spec; $spec = $self->_pre_eval($spec); my $cd = $self->block_delim; my @hunks = ($spec =~ /^(\Q${cd}\E.*?(?=^\Q${cd}\E|\z))/msg); my $blocks = $self->_choose_blocks(@hunks); $self->block_list($blocks); # Need to set early for possible filter use my $seq = 1; for my $block (@$blocks) { $block->blocks_object($self); $block->seq_num($seq++); } return $blocks; } sub _choose_blocks { my $blocks = []; for my $hunk (@_) { my $block = $self->_make_block($hunk); if (exists $block->{ONLY}) { diag "I found ONLY: maybe you're debugging?" unless $self->_no_diag_on_only; return [$block]; } next if exists $block->{SKIP}; push @$blocks, $block; if (exists $block->{LAST}) { return $blocks; } } return $blocks; } sub _check_reserved { my $id = shift; croak "'$id' is a reserved name. Use something else.\n" if $reserved_section_names->{$id} or $id =~ /^_/; } sub _make_block { my $hunk = shift; my $cd = $self->block_delim; my $dd = $self->data_delim; my $block = $self->block_class->new; $hunk =~ s/\A\Q${cd}\E[ \t]*(.*)\s+// or die; my $name = $1; my @parts = split /^\Q${dd}\E +\(?(\w+)\)? *(.*)?\n/m, $hunk; my $description = shift @parts; $description ||= ''; unless ($description =~ /\S/) { $description = $name; } $description =~ s/\s*\z//; $block->set_value(description => $description); my $section_map = {}; my $section_order = []; while (@parts) { my ($type, $filters, $value) = splice(@parts, 0, 3); $self->_check_reserved($type); $value = '' unless defined $value; $filters = '' unless defined $filters; if ($filters =~ /:(\s|\z)/) { croak "Extra lines not allowed in '$type' section" if $value =~ /\S/; ($filters, $value) = split /\s*:(?:\s+|\z)/, $filters, 2; $value = '' unless defined $value; $value =~ s/^\s*(.*?)\s*$/$1/; } $section_map->{$type} = { filters => $filters, }; push @$section_order, $type; $block->set_value($type, $value); } $block->set_value(name => $name); $block->set_value(_section_map => $section_map); $block->set_value(_section_order => $section_order); return $block; } sub _spec_init { return $self->_spec_string if $self->_spec_string; local $/; my $spec; if (my $spec_file = $self->_spec_file) { open FILE, $spec_file or die $!; $spec = ; close FILE; } else { $spec = do { package main; no warnings 'once'; ; }; } return $spec; } sub _strict_warnings() { require Filter::Util::Call; my $done = 0; Filter::Util::Call::filter_add( sub { return 0 if $done; my ($data, $end) = ('', ''); while (my $status = Filter::Util::Call::filter_read()) { return $status if $status < 0; if (/^__(?:END|DATA)__\r?$/) { $end = $_; last; } $data .= $_; $_ = ''; } $_ = "use strict;use warnings;$data$end"; $done = 1; } ); } sub tie_output() { my $handle = shift; die "No buffer to tie" unless @_; tie *$handle, 'Test::Base::Handle', $_[0]; } sub no_diff { $ENV{TEST_SHOW_NO_DIFFS} = 1; } package Test::Base::Handle; sub TIEHANDLE() { my $class = shift; bless \ $_[0], $class; } sub PRINT { $$self .= $_ for @_; } #=============================================================================== # Test::Base::Block # # This is the default class for accessing a Test::Base block object. #=============================================================================== package Test::Base::Block; our @ISA = qw(Spiffy); our @EXPORT = qw(block_accessor); sub AUTOLOAD { return; } sub block_accessor() { my $accessor = shift; no strict 'refs'; return if defined &$accessor; *$accessor = sub { my $self = shift; if (@_) { Carp::croak "Not allowed to set values for '$accessor'"; } my @list = @{$self->{$accessor} || []}; return wantarray ? (@list) : $list[0]; }; } block_accessor 'name'; block_accessor 'description'; Spiffy::field 'seq_num'; Spiffy::field 'is_filtered'; Spiffy::field 'blocks_object'; Spiffy::field 'original_values' => {}; sub set_value { no strict 'refs'; my $accessor = shift; block_accessor $accessor unless defined &$accessor; $self->{$accessor} = [@_]; } sub run_filters { my $map = $self->_section_map; my $order = $self->_section_order; Carp::croak "Attempt to filter a block twice" if $self->is_filtered; for my $type (@$order) { my $filters = $map->{$type}{filters}; my @value = $self->$type; $self->original_values->{$type} = $value[0]; for my $filter ($self->_get_filters($type, $filters)) { $Test::Base::Filter::arguments = $filter =~ s/=(.*)$// ? $1 : undef; my $function = "main::$filter"; no strict 'refs'; if (defined &$function) { local $_ = (@value == 1 and not defined($value[0])) ? undef : join '', @value; my $old = $_; @value = &$function(@value); if (not(@value) or @value == 1 and defined($value[0]) and $value[0] =~ /\A(\d+|)\z/ ) { if ($value[0] && $_ eq $old) { Test::Base::diag("Filters returning numbers are supposed to do munging \$_: your filter '$function' apparently doesn't."); } @value = ($_); } } else { my $filter_object = $self->blocks_object->filter_class->new; die "Can't find a function or method for '$filter' filter\n" unless $filter_object->can($filter); $filter_object->current_block($self); @value = $filter_object->$filter(@value); } # Set the value after each filter since other filters may be # introspecting. $self->set_value($type, @value); } } $self->is_filtered(1); } sub _get_filters { my $type = shift; my $string = shift || ''; $string =~ s/\s*(.*?)\s*/$1/; my @filters = (); my $map_filters = $self->blocks_object->_filters_map->{$type} || []; $map_filters = [ $map_filters ] unless ref $map_filters; my @append = (); for ( @{$self->blocks_object->_filters}, @$map_filters, split(/\s+/, $string), ) { my $filter = $_; last unless length $filter; if ($filter =~ s/^-//) { @filters = grep { $_ ne $filter } @filters; } elsif ($filter =~ s/^\+//) { push @append, $filter; } else { push @filters, $filter; } } return @filters, @append; } { %$reserved_section_names = map { ($_, 1); } keys(%Test::Base::Block::), qw( new DESTROY ); } 1;