Sub-WrapPackages-2.0/0000755000076500000240000000000011344432511013422 5ustar davidstaffSub-WrapPackages-2.0/ARTISTIC.txt0000644000076500000240000001373711203351751015420 0ustar davidstaff 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 as specified below. "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 uunet.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) give non-standard executables non-standard names, and clearly document 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. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 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 whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. 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 Sub-WrapPackages-2.0/Changes0000644000076500000240000000073111344431141014714 0ustar davidstaff2010-03-06 2.0 Slightly incompatible re-write 2010-01-09 1.31 Bugfix for 'use constant' in perl 5.10, thanks to Lee Johnson 2009-08-11 1.3 deferred wrapping of modules that aren't yet loaded; wildcards for modules 2006-08-02 1.2 changed how we detect what functions/methods a package defines 2006-07-26 1.1 added ability to wrap inherited subs 2003-11-15 initial release Sub-WrapPackages-2.0/GPL2.txt0000644000076500000240000004310311203351751014670 0ustar davidstaff GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU 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. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), 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 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 show them these terms so they know 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. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 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 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 derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 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 License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 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. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary 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 License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 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 Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing 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 for copying, distributing or modifying the Program or works based on it. 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. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. 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 this 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 this License, you may choose any version ever published by the Free Software Foundation. 10. 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 11. 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. 12. 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 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 the public, 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) 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 2 of the License, 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) year 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 is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. Sub-WrapPackages-2.0/lib/0000755000076500000240000000000011344432510014167 5ustar davidstaffSub-WrapPackages-2.0/lib/Sub/0000755000076500000240000000000011344432510014720 5ustar davidstaffSub-WrapPackages-2.0/lib/Sub/WrapPackages.pm0000644000076500000240000003015311344432104017627 0ustar davidstaffuse strict; use warnings; use Data::Dumper; package Sub::WrapPackages; use vars '$VERSION'; use vars '%ORIGINAL_SUBS'; # coderefs of what we're wrapping, keyed # by package::sub use vars '@MAGICINCS'; # list of magic INC subs, used by lib.pm hack use vars '%INHERITED'; # coderefs of inherited methods (before proxies # installed), keys by package::sub use vars '%WRAPPED_BY_WRAPPER'; # coderefs of original subs, keyed by # stringified coderef of wrapper use vars '%WRAPPER_BY_WRAPPED'; # coderefs of wrapper subs, keyed by # stringified coderef of original sub use Sub::Prototype (); use Devel::Caller::IgnoreNamespaces; Devel::Caller::IgnoreNamespaces::register(__PACKAGE__); use lib (); $VERSION = '2.0'; =head1 NAME Sub::WrapPackages - add pre- and post-execution wrappers around all the subroutines in packages or around individual subs =head1 SYNOPSIS use Sub::WrapPackages packages => [qw(Foo Bar Baz::*)], # wrap all subs in Foo and Bar # and any Baz::* packages subs => [qw(Barf::a, Barf::b)], # wrap these two subs as well wrap_inherited => 1, # and wrap any methods # inherited by Foo, Bar, or # Baz::* pre => sub { print "called $_[0] with params ". join(', ', @_[1..$#_])."\n"; }, post => sub { print "$_[0] returned $_[1]\n"; }; =head1 COMPATIBILITY While this module does broadly the same job as the 1.x versions did, the interface may have changed incompatibly. Sorry. Hopefully it'll be more maintainable and slightly less crazily magical. Also, caller() should now work properly, ignoring wrappings. =head1 DESCRIPTION This module installs pre- and post- execution subroutines for the subroutines or packages you specify. The pre-execution subroutine is passed the wrapped subroutine's name and all its arguments. The post-execution subroutine is passed the wrapped sub's name and its results. The return values from the pre- and post- subs are ignored, and they are called in the same context (void, scalar or list) as the calling code asked for. Normal usage is to pass a bunch of parameters when the module is used. However, you can also call Sub::WrapPackages::wrapsubs with the same parameters. =head1 PARAMETERS Either pass parameters on loading the module, as above, or pass them to ... =head2 the wrapsubs subroutine =over 4 =item the subs arrayref In the synopsis above, you will see two named parameters, C and C. Any subroutine mentioned in C will be wrapped. Any subroutines mentioned in 'subs' must already exist - ie their modules must be loaded - at the time you try to wrap them. =item the packages arrayref Any package mentioned here will have all its subroutines wrapped, including any that it imports at load-time. Packages can be loaded in any order - they don't have to already be loaded for Sub::WrapPackages to work its magic. You can specify wildcard packages. Anything ending in ::* is assumed to be such. For example, if you specify Orchard::Tree::*, then that matches Orchard::Tree, Orchard::Tree::Pear, Orchard::Apple::KingstonBlack etc, but not - of course - Pine::Tree or My::Orchard::Tree. Note, however, that if a module exports a subroutine at load-time using C then that sub will be wrapped in the exporting module but not in the importing module. This is because import() runs before we get a chance to fiddle with things. Sorry. Deferred wrapping of subs in packages that aren't yet loaded works via a subroutine inserted in @INC. This means that if you mess around with @INC, eg by inserting a directoy at the beginning of the path, the magic might not get a chance to run. If you C to mess with @INC though, it should work, as I've over-ridden lib's import() method. That said, code this funky has no right to work. Use with caution! =item wrap_inherited In conjunction with the C arrayref, this wraps all calls to inherited methods made through those packages. If you call those methods directly in the superclass then they are not affected - unless they're wrapped in the superclass of course. =item pre and post References to the subroutines you want to use as wrappers. =back =head1 BUGS AUTOLOAD and DESTROY are not treated as being special. I'm not sure whether they should be or not. If you use wrap_inherited but classes change their inheritance tree at run-time, then very bad things will happen. VERY BAD THINGS. So don't do that. You shouldn't be doing that anyway. Mind you, you shouldn't be doing the things that this module does either. BAD PROGRAMMER, NO BIKKIT! If you find any other lurking horrors, please report them using L. =head1 FEEDBACK I like to know who's using my code. All comments, including constructive criticism, are welcome. Please email me. =head1 SOURCE CODE REPOSITORY L =head1 COPYRIGHT and LICENCE Copyright 2003-2009 David Cantrell EFE This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. =head1 THANKS TO Thanks to Tom Hukins for sending in a test case for the situation when a class and a subclass are both defined in the same file, and for prompting me to support inherited methods; to Dagfinn Ilmari Mannsaker for help with the craziness for fiddling with modules that haven't yet been loaded; to Lee Johnson for reporting a bug caused by perl 5.10's constant.pm being Far Too Clever, and providing a patch and test; to Adam Trickett who thought this was a jolly good idea; and to Ed Summers, whose code for figgering out what functions a package contains I borrowed out of L. =cut sub import { shift; wrapsubs(@_) if(@_); } sub _subs_in_packages { my @targets = map { $_.'::' } @_; my @subs; foreach my $package (@targets) { no strict; while(my($k, $v) = each(%{$package})) { push @subs, $package.$k if(ref($v) ne 'SCALAR' && defined(&{$v})); } } return @subs; } sub _make_magic_inc { my %params = @_; my $wildcard_packages = [map { s/::.//; $_; } grep { /::\*$/ } @{$params{packages}}]; my $nonwildcard_packages = [grep { $_ !~ /::\*$/ } @{$params{packages}}]; push @MAGICINCS, sub { my($me, $file) = @_; (my $module = $file) =~ s{/}{::}g; $module =~ s/\.pm//; return undef unless( (grep { $module =~ /^$_(::|$)/ } @{$wildcard_packages}) || (grep { $module eq $_ } @{$nonwildcard_packages}) ); local @INC = grep { $_ ne $me } @INC; local $/; my @files = grep { -e $_ } map { join('/', $_, $file) } @INC; open(my $fh, $files[0]) || die("Can't locate $file in \@INC\n"); my $text = <$fh>; close($fh); %Sub::WrapPackages::params = %params; $text =~ /(.*?)(__DATA__.*|__END__.*|$)/s; my($code, $trailer) = ($1, $2); $text = $code.qq[ ; Sub::WrapPackages::wrapsubs( %Sub::WrapPackages::params, packages => [qw($module)] ); 1; ]."\n$trailer"; open($fh, '<', \$text); $fh; }; unshift @INC, $MAGICINCS[-1]; } sub _getparents { my $package = shift; my @parents = eval '@'.$package.'::ISA'; return @parents, (map { _getparents($_) } @parents); } sub wrapsubs { my %params = @_; if(exists($params{packages}) && ref($params{packages}) =~ /^ARRAY/) { my $wildcard_packages = [map { (my $foo = $_) =~ s/::.$//; $foo; } grep { /::\*$/ } @{$params{packages}}]; my $nonwildcard_packages = [grep { $_ !~ /::\*$/ } @{$params{packages}}]; # defer wrapping stuff that's not yet loaded _make_magic_inc(%params); # wrap wildcards that are loaded if(@{$wildcard_packages}) { foreach my $loaded (map { (my $f = $_) =~ s!/!::!g; $f =~ s/\.pm$//; $f } keys %INC) { my $pattern = '^('.join('|', map { (my $f = $_) =~ s/::\*$/::/; $f } @{$wildcard_packages} ).')'; wrapsubs(%params, packages => [$loaded]) if($loaded =~ /$pattern/); } } # wrap non-wildcards that are loaded if($params{wrap_inherited}) { foreach my $package (@{$nonwildcard_packages}) { my @parents = _getparents($package); # get inherited (but not over-ridden!) subs my %subs_in_package = map { s/.*:://; ($_, 1); } _subs_in_packages($package); my @subs_to_define = grep { !exists($subs_in_package{$_}) } map { s/.*:://; $_; } _subs_in_packages(@parents); # define proxy method that just does a goto to get # to the right place. We then later wrap the proxy foreach my $sub (@subs_to_define) { next if(exists($INHERITED{$package."::$sub"})); $INHERITED{$package."::$sub"} = $package->can($sub); # if the inherited method is already wrapped, # point this proxy at the original method # so we don't wrap a wrapper if(exists($WRAPPED_BY_WRAPPER{$INHERITED{$package."::$sub"}})) { $INHERITED{$package."::$sub"} = $WRAPPED_BY_WRAPPER{$INHERITED{$package."::$sub"}}; } eval qq{ sub ${package}::$sub { goto &{\$Sub::WrapPackages::INHERITED{"${package}::$sub"}}; } }; die($@) if($@); } } } push @{$params{subs}}, _subs_in_packages(@{$params{packages}}); } elsif(exists($params{packages})) { die("Bad param 'packages'"); } return undef if(!$params{pre} && !$params{post}); $params{pre} ||= sub {}; $params{post} ||= sub {}; foreach my $sub (@{$params{subs}}) { next if(exists($ORIGINAL_SUBS{$sub})); $ORIGINAL_SUBS{$sub} = \&{$sub}; my $imposter = sub { local *__ANON__ = $sub; my(@r, $r) = (); my $wa = wantarray(); if(!defined($wa)) { $params{pre}->($sub, @_); $ORIGINAL_SUBS{$sub}->(@_); $params{post}->($sub); } elsif($wa) { my @f = $params{pre}->($sub, @_); @r = $ORIGINAL_SUBS{$sub}->(@_); @f = $params{post}->($sub, @r); } else { my $f = $params{pre}->($sub, @_); $r = $ORIGINAL_SUBS{$sub}->(@_); $f = $params{post}->($sub, $r); } return wantarray() ? @r : $r; }; Sub::Prototype::set_prototype($imposter, prototype($ORIGINAL_SUBS{$sub})) if(prototype($ORIGINAL_SUBS{$sub})); { no strict 'refs'; no warnings 'redefine'; $WRAPPED_BY_WRAPPER{$imposter} = $ORIGINAL_SUBS{$sub}; $WRAPPER_BY_WRAPPED{$ORIGINAL_SUBS{$sub}} = $imposter; *{$sub} = $imposter; }; } } package lib; use strict; no strict 'refs'; use warnings; no warnings 'redefine'; my $originallibimport = \&{'lib::import'}; my $newimport = sub { $originallibimport->(@_); my %magicincs = map { $_, 1 } @Sub::WrapPackages::MAGICINCS; @INC = ( (grep { exists($magicincs{$_}); } @INC), (grep { !exists($magicincs{$_}); } @INC) ); }; *{'lib::import'} = $newimport; 1; Sub-WrapPackages-2.0/Makefile.PL0000644000076500000240000000042711344430666015410 0ustar davidstaffuse ExtUtils::MakeMaker; WriteMakefile( NAME => 'Sub::WrapPackages', VERSION_FROM => 'lib/Sub/WrapPackages.pm', PREREQ_PM => { 'Sub::Prototype' => 0.02, # 'Sub::Uplevel' => 0.22, 'Devel::Caller::IgnoreNamespaces' => 1.0, } ); Sub-WrapPackages-2.0/MANIFEST0000644000076500000240000000175511344432511014563 0ustar davidstafflib/Sub/WrapPackages.pm t/lib/a.pm t/lib/b.pm MANIFEST README TODO Changes Makefile.PL t/lib/Banana.pm t/lib/Banana/Tree.pm ARTISTIC.txt GPL2.txt t/lib/Orchard/Tree/Pear/Conference.pm t/lib/Module/With/Data/Segment.pm t/lib/Module/With/END/Segment.pm t/lib/Module/With/Both/Segments.pm t/lib/Prototyped.pm t/lib/c.pm t/00_wrap_as_subs.t t/01_wrap_as_packages.t t/01b_wrap_as_packages_late_loading.t t/02_wrap_inherited.t t/02b_inh_late_loading.t t/02c_inh_from_grandparent.t t/02d_inh_from_grandparent_parent_also_wrapped.t t/02e_inh_from_grandparent_parent_also_wrapped_order_rev.t t/03_inh_in_same_file.t t/03b_inh_in_same_file_late_loading.t t/04_wrap_tree_of_packages.t t/04b_wrap_tree_of_packages_late_loading.t t/05___DATA__.t t/06_prototypes.t t/07_use_lib.t t/pod-coverage.t t/pod.t t/08_caller.t t/02f_point_inh_proxies_at_original.t t/coverage.sh t/lib/breakuseconstant.pm t/09_5.10_use_constant.t t/10_prototypes.t META.yml Module meta-data (added by MakeMaker) Sub-WrapPackages-2.0/META.yml0000644000076500000240000000103411344432511014671 0ustar davidstaff--- #YAML:1.0 name: Sub-WrapPackages version: 2.0 abstract: ~ author: [] license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Devel::Caller::IgnoreNamespaces: 1 Sub::Prototype: 0.02 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.50 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Sub-WrapPackages-2.0/README0000644000076500000240000000046311154516463014315 0ustar davidstaffThs module makes it easy to surround large numbers of subroutines and methods with pre- and post-execution code. To install, do the usual: perl Makefile.PL make make test make install You may use, modify and distribute this code under the same terms as you may use, modify and distribute perl itself. Sub-WrapPackages-2.0/t/0000755000076500000240000000000011344432510013664 5ustar davidstaffSub-WrapPackages-2.0/t/00_wrap_as_subs.t0000644000076500000240000000264011241132025017034 0ustar davidstaff#!/usr/bin/perl -w use strict; my $pre; my $post; use Test::More tests => 10; use lib 't/lib'; use a; use Sub::WrapPackages ( subs => [qw(a::a_scalar a::a_list a::a_context_sensitive)], pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(", ", @_); } ); my $r = a::a_scalar(1..3); is($pre, 'a::a_scalar, 1, 2, 3', 'pre-wrapper works in scalar context'); is($post, 'a::a_scalar, in sub a_scalar', 'post-wrapper works in scalar context'); is($r, 'in sub a_scalar', 'return scalar in scalar context'); $pre = $post = ''; my @r = a::a_list(4,6,8); is($pre, 'a::a_list, 4, 6, 8', 'pre-wrapper works in list context'); is($post, 'a::a_list, in, sub, a_list', 'post-wrapper works in list context'); is(join(', ', @r), 'in, sub, a_list', 'return list in list context'); a::a_context_sensitive(); ok($main::voidcontext, 'wantarray() undef in void context'); is_deeply(my $foo = a::a_context_sensitive(), [qw(in sub a_context_sensitive)], 'wantarray() false in scalar context'); is_deeply([my @foo = a::a_context_sensitive()], [qw(in sub a_context_sensitive)], 'wantarray() true in list context'); Sub::WrapPackages::wrapsubs( subs => [qw(a::a_scalar a::a_list a::a_context_sensitive)], pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(", ", @_); } ); $pre = ''; $r = a::a_scalar(1..3); is($pre, 'a::a_scalar, 1, 2, 3', "subs can't be re-wrapped"); Sub-WrapPackages-2.0/t/01_wrap_as_packages.t0000644000076500000240000000135311241132041017635 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 4; use lib 't/lib'; use a; my $pre; my $post; use Sub::WrapPackages ( packages => [qw(a)], pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(", ", @_); } ); my $r = a::a_scalar(1..3); is($pre, 'a::a_scalar, 1, 2, 3', 'package pre-wrapper works'); is($post, 'a::a_scalar, in sub a_scalar', 'package post-wrapper works'); is($r, 'in sub a_scalar', 'package-wrapped sub returns correctly'); Sub::WrapPackages::wrapsubs( packages => [qw(a)], pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(", ", @_); } ); $pre = ''; $r = a::a_scalar(1..3); is($pre, 'a::a_scalar, 1, 2, 3', "subs can't be re-wrapped via a package"); Sub-WrapPackages-2.0/t/01b_wrap_as_packages_late_loading.t0000644000076500000240000000075111241132573022514 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 3; my $pre; my $post; use lib 't/lib'; use Sub::WrapPackages ( packages => [qw(a)], pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(", ", @_); } ); use a; my $r = a::a_scalar(1..3); is($pre, 'a::a_scalar, 1, 2, 3', 'package pre-wrapper works'); is($post, 'a::a_scalar, in sub a_scalar', 'package post-wrapper works'); is($r, 'in sub a_scalar', 'package-wrapped sub returns correctly'); Sub-WrapPackages-2.0/t/02_wrap_inherited.t0000644000076500000240000000232711241336770017371 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 8; use Data::Dumper; my $pre; my $post; use lib 't/lib'; use b; use Sub::WrapPackages ( packages => [qw(b)], wrap_inherited => 1, pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(', ', @_); } ); my $r = b->b_function(94); is($pre, 'b::b_function, b, 94', "when wrapping inherited methods, normal methods' pre-wrappers are OK"); is($post, 'b::b_function, i like pie', "when wrapping inherited methods, normal methods' post-wrappers are OK"); is($r, 'i like pie', "when wrapping inherited methods, normal methods' return the right value"); $pre = $post = ''; my @r = b->a_list(4,6,8); is($pre, 'b::a_list, b, 4, 6, 8', "when wrapping inherited methods, pre-wrapper is OK"); is($post, 'b::a_list, in, sub, a_list', "when wrapping inherited methods, post-wrapper is OK"); is_deeply(\@r, [qw(in sub a_list)], "wrapped inherited method returns the right value"); $pre = $post = ''; @r = a->a_list(4,6,8); ok($pre eq $post && $post eq '', "calling the superclass method directly avoids wrapping shenanigans"); is_deeply(\@r, [qw(in sub a_list)], "non-wrapped super-class method returns the right value"); Sub-WrapPackages-2.0/t/02b_inh_late_loading.t0000644000076500000240000000236511241336770020011 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 8; use Data::Dumper; my $pre; my $post; use lib 't/lib'; use Sub::WrapPackages ( packages => [qw(b)], wrap_inherited => 1, pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(', ', @_); } ); use b; my $r = b->b_function(94); is($pre, 'b::b_function, b, 94', "when wrapping inherited methods late, normal methods' pre-wrappers are OK"); is($post, 'b::b_function, i like pie', "when wrapping inherited methods late, normal methods' post-wrappers are OK"); is($r, 'i like pie', "when wrapping inherited methods late, normal methods' return the right value"); $pre = $post = ''; my @r = b->a_list(4,6,8); is($pre, 'b::a_list, b, 4, 6, 8', "when wrapping inherited methods late, pre-wrapper is OK"); is($post, 'b::a_list, in, sub, a_list', "when wrapping inherited methods late, post-wrapper is OK"); is_deeply(\@r, [qw(in sub a_list)], "late-wrapped inherited method returns the right value"); $pre = $post = ''; @r = a->a_list(4,6,8); ok($pre eq $post && $post eq '', "calling the superclass method directly avoids wrapping shenanigans"); is_deeply(\@r, [qw(in sub a_list)], "non-wrapped super-class method returns the right value"); Sub-WrapPackages-2.0/t/02c_inh_from_grandparent.t0000644000076500000240000000150611241504556020713 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 5; use Data::Dumper; my $pre; my $post; use lib 't/lib'; use c; use Sub::WrapPackages ( packages => [qw(c)], wrap_inherited => 1, pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(', ', @_); } ); my $r = c->a_scalar(94); is($pre, 'c::a_scalar, c, 94', "when wrapping methods inherited from grandparent, pre is good"); is($post, 'c::a_scalar, in sub a_scalar', "when wrapping methods inherited from grandparent, post is good"); is($r, 'in sub a_scalar', "when wrapping methods inherited from grandparent, return value is good"); is(c->a_context_sensitive(), 'not redefined', 'overridden grandparent method not redefined'); is(c->b_function(), 'not redefined', 'overridden parent method not redefined'); Sub-WrapPackages-2.0/t/02d_inh_from_grandparent_parent_also_wrapped.t0000644000076500000240000000151011242016303025005 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 5; use Data::Dumper; my $pre; my $post; use lib 't/lib'; use c; use Sub::WrapPackages ( packages => [qw(b c)], wrap_inherited => 1, pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(', ', @_); } ); my $r = c->a_scalar(94); is($pre, 'c::a_scalar, c, 94', "when wrapping methods inherited from grandparent, pre is good"); is($post, 'c::a_scalar, in sub a_scalar', "when wrapping methods inherited from grandparent, post is good"); is($r, 'in sub a_scalar', "when wrapping methods inherited from grandparent, return value is good"); is(c->a_context_sensitive(), 'not redefined', 'overridden grandparent method not redefined'); is(c->b_function(), 'not redefined', 'overridden parent method not redefined'); Sub-WrapPackages-2.0/t/02e_inh_from_grandparent_parent_also_wrapped_order_rev.t0000644000076500000240000000151011242016723027063 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 5; use Data::Dumper; my $pre; my $post; use lib 't/lib'; use c; use Sub::WrapPackages ( packages => [qw(c b)], wrap_inherited => 1, pre => sub { $pre .= join(", ", @_); }, post => sub { $post .= join(', ', @_); } ); my $r = c->a_scalar(94); is($pre, 'c::a_scalar, c, 94', "when wrapping methods inherited from grandparent, pre is good"); is($post, 'c::a_scalar, in sub a_scalar', "when wrapping methods inherited from grandparent, post is good"); is($r, 'in sub a_scalar', "when wrapping methods inherited from grandparent, return value is good"); is(c->a_context_sensitive(), 'not redefined', 'overridden grandparent method not redefined'); is(c->b_function(), 'not redefined', 'overridden parent method not redefined'); Sub-WrapPackages-2.0/t/02f_point_inh_proxies_at_original.t0000644000076500000240000000200511243342705022631 0ustar davidstaff#!/usr/bin/perl -w # What if b inherits from a, a::foo is wrapped, and then # b::* are wrapped with wrap_inherited? use strict; use Test::More tests => 4; use Data::Dumper; my $pre; my $post; use lib 't/lib'; use a; # first wrap everything in a ... use Sub::WrapPackages ( packages => [qw(a)], wrap_inherited => 1, pre => sub { $pre++ }, post => sub { $post++ }, ); a->a_list(1,2,3); ok($pre == $post && $post == 1, "pre and post are working"); # now load b and wrap everything in it, including inherited methods eval 'use b'; Sub::WrapPackages::wrapsubs ( packages => [qw(b)], wrap_inherited => 1, pre => sub { $pre++ }, post => sub { $post++ }, ); $pre = $post = 0; b->b_function(); ok($pre == $post && $post == 1, "pre and post work in the child for a non-inherited method"); $pre = $post = 0; is_deeply([b->a_list()], [qw(in sub a_list)], "inherited method returns OK"); ok($pre == $post && $pre == 1, "and pre/post only get run once"); Sub-WrapPackages-2.0/t/03_inh_in_same_file.t0000644000076500000240000000074211241360671017632 0ustar davidstaff#!perl use strict; use Test::More tests => 4; use lib 't/lib'; use Banana; my $post = ''; use Sub::WrapPackages ( packages => [qw(Banana)], post => sub { $post .= $_[0]; }, wrap_inherited => 1, ); ok(Banana->peel() eq 'ready to eat', "got right response"); is($post, 'Banana::peel', 'post is good for non-inherited method'); $post = ''; ok(Banana->eat() eq 'yum yum', "got right response"); is($post, 'Banana::eat', 'post is good for inherited method'); Sub-WrapPackages-2.0/t/03b_inh_in_same_file_late_loading.t0000644000076500000240000000074211241401456022473 0ustar davidstaff#!perl use strict; use Test::More tests => 4; use lib 't/lib'; my $post = ''; use Sub::WrapPackages ( packages => [qw(Banana)], post => sub { $post .= $_[0]; }, wrap_inherited => 1, ); use Banana; ok(Banana->peel() eq 'ready to eat', "got right response"); is($post, 'Banana::peel', 'post is good for non-inherited method'); $post = ''; ok(Banana->eat() eq 'yum yum', "got right response"); is($post, 'Banana::eat', 'post is good for inherited method'); Sub-WrapPackages-2.0/t/04_wrap_tree_of_packages.t0000644000076500000240000000066011240332662020672 0ustar davidstaffuse strict; use warnings; use lib 't/lib'; use Test::More tests => 8; use Banana::Tree; use Orchard::Tree::Pear::Conference; use Sub::WrapPackages ( packages => [qw(Banana::Tree Orchard::*)], pre => sub { ok(1, "$_[0] pre-wrapper") }, post => sub { ok(1, "$_[0] post-wrapper") } ); ok(Orchard::Tree::Pear::Conference::tastes_nasty, "Conference pears are BAD"); Banana::Tree::foo(); Sub-WrapPackages-2.0/t/04b_wrap_tree_of_packages_late_loading.t0000644000076500000240000000105411240332662023534 0ustar davidstaffuse strict; use warnings; use lib 't/lib'; # FIXME uncomment, and fix prototype problems # BEGIN { $SIG{__WARN__} = sub { die(@_) }; } use Test::More tests => 8; use Sub::WrapPackages ( packages => [qw(Banana::Tree Orchard::*)], pre => sub { ok(1, "$_[0] pre-wrapper") }, post => sub { ok(1, "$_[0] post-wrapper") } ); use Banana::Tree; # load after Sub::WrapPackages use Orchard::Tree::Pear::Conference; ok(Orchard::Tree::Pear::Conference::tastes_nasty, "Conference pears are BAD"); Banana::Tree::foo(); Sub-WrapPackages-2.0/t/05___DATA__.t0000644000076500000240000000162711242647260015677 0ustar davidstaffuse strict; use warnings; use lib 't/lib'; use Test::More tests => 15; use Sub::WrapPackages ( packages => [qw( Module::With::Data::Segment Module::With::Both::Segments Module::With::END::Segment )], pre => sub { ok(1, "$_[0] pre-wrapper") }, post => sub { ok(1, "$_[0] post-wrapper") } ); use Module::With::Data::Segment; use Module::With::Both::Segments; use Module::With::END::Segment; ok(Module::With::Data::Segment::foo(), "wrapped sub in a module with a __DATA__ segment works"); ok(Module::With::Data::Segment::data() =~ 'wibble', "and the __DATA__ is read OK"); ok(Module::With::Both::Segments::foo(), "wrapped sub in a module with __DATA__ and __END__ works"); ok(Module::With::Both::Segments::data() =~ 'wibble', "and the __DATA__ is read OK"); ok(Module::With::END::Segment::foo(), "wrapped sub in a module with __END__ works"); Sub-WrapPackages-2.0/t/06_prototypes.t0000644000076500000240000000111511241372614016610 0ustar davidstaff#!/usr/bin/perl -w use strict; my $pre; my $post; use Test::More tests => 3; use lib 't/lib'; use Prototyped; use Sub::WrapPackages ( packages => [qw(Prototyped)], pre => sub { $pre = \@_; }, post => sub { $post = \@_; } ); my @foo = (1,2,3); my $r = [Prototyped::prototyped(@foo, 'cow')]; is_deeply($r, [ [1, 2, 3], 'cow'], "prototyped subs work right"); is_deeply($pre, [ 'Prototyped::prototyped', [1, 2, 3], 'cow' ], "pre gets the right prototype-ish data"); is_deeply($post, [ 'Prototyped::prototyped', [1, 2, 3], 'cow' ], "post gets the right data"); Sub-WrapPackages-2.0/t/07_use_lib.t0000644000076500000240000000042611241507724016011 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 1; my $pre; use Sub::WrapPackages ( packages => [qw(a)], pre => sub { $pre .= join(", ", @_); }, ); use lib 't/lib'; use a; my $r = a::a_scalar(1..3); is($pre, 'a::a_scalar, 1, 2, 3', "can 'use lib' late too"); Sub-WrapPackages-2.0/t/08_caller.t0000644000076500000240000000365311344427374015645 0ustar davidstaff#!/usr/bin/perl -w use strict; use Test::More tests => 8; my $pre; use Sub::WrapPackages; use lib 't/lib'; use a; my @caller_noargs = a::a_caller(); my @caller_witharg0 = a::a_caller(0); my @caller_caller_noargs = a::a_caller_caller(); my @caller_caller_witharg0 = a::a_caller_caller(0); my @caller_caller_witharg1 = a::a_caller_caller(1); my @caller_caller_witharg2 = a::a_caller_caller(2); # wrap after getting correct data to compare with Sub::WrapPackages::wrapsubs( packages => [qw(a)], pre => sub { $pre .= join(", ", @_); }, ); my @wrapped_caller_noargs = a::a_caller(); $wrapped_caller_noargs[2] = $caller_noargs[2]; is($pre, 'a::a_caller', "pre works for no args"); is_deeply(\@wrapped_caller_noargs, \@caller_noargs, "wrapped -> caller() works"); $pre = ''; my @wrapped_caller_witharg0 = a::a_caller(0); $wrapped_caller_witharg0[2] = $caller_witharg0[2]; is($pre, 'a::a_caller, 0', "pre works with an arg"); is_deeply(\@wrapped_caller_witharg0, \@caller_witharg0, "wrapped -> caller(0) works"); my @wrapped_caller_caller_noargs = a::a_caller_caller(); $wrapped_caller_caller_noargs[2] = $caller_caller_noargs[2]; is_deeply(\@wrapped_caller_caller_noargs, \@caller_caller_noargs, "wrapped -> wrapped -> caller() works"); my @wrapped_caller_caller_witharg0 = a::a_caller_caller(0); $wrapped_caller_caller_witharg0[2] = $caller_caller_witharg0[2]; is_deeply(\@wrapped_caller_caller_witharg0, \@caller_caller_witharg0, "wrapped -> wrapped -> caller(0) works"); my @wrapped_caller_caller_witharg1 = a::a_caller_caller(1); $wrapped_caller_caller_witharg1[2] = $caller_caller_witharg1[2]; is_deeply(\@wrapped_caller_caller_witharg1, \@caller_caller_witharg1, "wrapped -> wrapped -> caller(1) works"); my @wrapped_caller_caller_witharg2 = a::a_caller_caller(2); # expect an empty list here, so no munging! is_deeply(\@wrapped_caller_caller_witharg2, \@caller_caller_witharg2, "wrapped -> wrapped -> caller(2) works"); Sub-WrapPackages-2.0/t/09_5.10_use_constant.t0000644000076500000240000000114411334337617017544 0ustar davidstaff#!/usr/bin/perl -w my $r; my $skip; use strict; BEGIN { eval 'use 5.010'; $skip = $@; $| = 1; print "1..1\n" unless($skip); } if ($skip) { $skip =~ s/--.*$//xs; print "1..0\n"; print "skip ... $skip\n"; exit; } eval ' use lib "t/lib"; use breakuseconstant; use Sub::WrapPackages ( packages => [qw(breakuseconstant)], pre => sub { $r .= "before"; }, post => sub { $r .= "after"; } ); my $test = 0; $r .= breakuseconstant::FOO; print "not " unless($r eq "i am a constant i am i am"); print "ok ".(++$test)." use constant does not wrap\n"; '; Sub-WrapPackages-2.0/t/10_prototypes.t0000644000076500000240000000110711343340554016605 0ustar davidstaff#!/usr/bin/perl -w use strict; my $pre; my $post; use Test::More tests => 4; sub mypush(\@@) { @{$_[0]} = (@{$_[0]}, @_[1..$#_]); } BEGIN { my @array = (); mypush @array, (1,2); is_deeply(\@array, [1, 2], "without wrapping, prototyped function works"); ok(!$pre, "... and yes, it really wasn't wrapped"); } use Sub::WrapPackages ( subs => [qw(main::mypush)], pre => sub { $pre = 'pre' } ); my @array = (); mypush @array, (1,2); is_deeply(\@array, [1, 2], "with wrapping, prototyped function still works"); ok($pre eq 'pre', "... and yes, it really was wrapped"); Sub-WrapPackages-2.0/t/coverage.sh0000755000076500000240000000021011243352436016015 0ustar davidstaff#!/bin/sh # $Id: coverage.sh,v 1.1 2008/02/26 21:54:55 drhyde Exp $ cover -delete HARNESS_PERL_SWITCHES=-MDevel::Cover make test cover Sub-WrapPackages-2.0/t/lib/0000755000076500000240000000000011344432510014432 5ustar davidstaffSub-WrapPackages-2.0/t/lib/a.pm0000644000076500000240000000057511344313165015223 0ustar davidstaffpackage a; sub a_scalar { return 'in sub a_scalar'; } sub a_list { return qw(in sub a_list); } sub a_context_sensitive { $main::voidcontext = 1 if(!defined(wantarray())); my @rval = qw(in sub a_context_sensitive); wantarray() ? @rval : \@rval; } sub a_caller { return caller(shift()) if(@_); return caller(); } sub a_caller_caller { a_caller(@_); } 1; Sub-WrapPackages-2.0/t/lib/b.pm0000644000076500000240000000010211241503264015203 0ustar davidstaffpackage b; use base qw(a); sub b_function { 'i like pie'; } 1; Sub-WrapPackages-2.0/t/lib/Banana/0000755000076500000240000000000011344432510015612 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Banana/Tree.pm0000644000076500000240000000014111236357730017055 0ustar davidstaffpackage Banana::Tree; use Test::More; sub foo { ok(1, "imported sub in Foo::* works"); } 1 Sub-WrapPackages-2.0/t/lib/Banana.pm0000644000076500000240000000015111154516463016156 0ustar davidstaffpackage Fruit; sub eat { 'yum yum' } package Banana; use base 'Fruit'; sub peel { 'ready to eat' } 1; Sub-WrapPackages-2.0/t/lib/breakuseconstant.pm0000644000076500000240000000011711334333702020344 0ustar davidstaffpackage breakuseconstant; use constant FOO => 'i am a constant i am i am'; 1; Sub-WrapPackages-2.0/t/lib/c.pm0000644000076500000240000000015711241504545015221 0ustar davidstaffpackage c; use base qw(b); sub a_context_sensitive { 'not redefined' } sub b_function { 'not redefined'} 1; Sub-WrapPackages-2.0/t/lib/Module/0000755000076500000240000000000011344432510015657 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Module/With/0000755000076500000240000000000011344432510016572 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Module/With/Both/0000755000076500000240000000000011344432510017466 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Module/With/Both/Segments.pm0000644000076500000240000000016411242646502021617 0ustar davidstaffpackage Module::With::Both::Segments; sub foo { return 1; } sub data { return ; } 1; __DATA__ wibble __END__ Sub-WrapPackages-2.0/t/lib/Module/With/Data/0000755000076500000240000000000011344432510017443 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Module/With/Data/Segment.pm0000644000076500000240000000015311242646677021424 0ustar davidstaffpackage Module::With::Data::Segment; sub foo { return 1; } sub data { return ; } 1; __DATA__ wibble Sub-WrapPackages-2.0/t/lib/Module/With/END/0000755000076500000240000000000011344432510017200 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Module/With/END/Segment.pm0000644000076500000240000000011511240332662021137 0ustar davidstaffpackage Module::With::END::Segment; sub foo { return 1; } 1; __END__ wibble Sub-WrapPackages-2.0/t/lib/Orchard/0000755000076500000240000000000011344432510016014 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Orchard/Tree/0000755000076500000240000000000011344432510016713 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Orchard/Tree/Pear/0000755000076500000240000000000011344432510017602 5ustar davidstaffSub-WrapPackages-2.0/t/lib/Orchard/Tree/Pear/Conference.pm0000644000076500000240000000011411236401561022205 0ustar davidstaffpackage Orchard::Tree::Pear::Conference; sub tastes_nasty { return 1; } 1; Sub-WrapPackages-2.0/t/lib/Prototyped.pm0000644000076500000240000000020211241371647017144 0ustar davidstaffpackage Prototyped; use strict; use warnings; sub prototyped(\@@) { my($ref, @array) = @_; return ($ref, @array); } 1; Sub-WrapPackages-2.0/t/pod-coverage.t0000644000076500000240000000036311154516463016437 0ustar davidstaff# $Id: pod-coverage.t,v 1.1 2007/07/30 12:49:39 drhyde Exp $ use strict; $^W=1; use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Sub-WrapPackages-2.0/t/pod.t0000644000076500000240000000031211154516463014640 0ustar davidstaff# $Id: pod.t,v 1.1 2007/07/30 12:49:39 drhyde Exp $ use strict; $^W=1; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Sub-WrapPackages-2.0/TODO0000644000076500000240000000030011243353154014106 0ustar davidstaffCan we do something funky with AUTOLOAD? use PPI to find __DATA__ / __END__ perl -MPPI -MPPI::Dumper -e 'PPI::Dumper->new(PPI::Document->new("t/lib/Module/With/Data/Segment.pm"))->print()'