Lexical-Persistence-1.022/000755 000765 000024 00000000000 12202157737 015501 5ustar00trocstaff000000 000000 Lexical-Persistence-1.022/CHANGES000644 000765 000024 00000002444 12202157737 016500 0ustar00trocstaff000000 000000 ================================================== Changes from 2012-08-12 00:00:00 +0000 to present. ================================================== ------------------------------------------ version 1.021 at 2013-08-11 20:02:26 +0000 ------------------------------------------ Change: 930f3b70a5ff468ed48ae218638fcfd5d6e34838 Author: Rocco Caputo Date : 2013-08-11 16:02:26 +0000 Update copyright date. Change: 42a9e410cedd1a656fc88f5d2db4fee9706c1ec6 Author: Rocco Caputo Date : 2013-08-11 15:57:08 +0000 Merge branch 'master' of github.com:rcaputo/lexical-persistence Change: 5288e78f14d4459af3e1e48556909aa6c01e3ef1 Author: Rocco Caputo Date : 2013-08-11 15:54:44 +0000 Switch to Dist::Zilla. Change: e59502b75249ab6f0c902f876003cb3119e3612c Author: Rocco Caputo Date : 2013-08-03 20:16:42 +0000 Merge pull request #2 from dsteinbrunner/patch-1 Documentation typo fix. Change: 804c7f59f50be69d7ae6091b02f1c5a93dafcf18 Author: David Steinbrunner Date : 2013-07-21 20:21:49 +0000 typo fix ================================================ Plus 6 releases after 2012-08-12 00:00:00 +0000. ================================================ Lexical-Persistence-1.022/dist.ini000644 000765 000024 00000001413 12202157737 017144 0ustar00trocstaff000000 000000 name = Lexical-Persistence author = Rocco Caputo copyright_holder = Rocco Caputo license = Perl_5 [AutoMetaResources] bugtracker.rt = 1 license = http://dev.perl.org/licenses/ repository.github = user:rcaputo [AutoPrereqs] [CheckPrereqsIndexed] [Prereqs::MatchInstalled::All] exclude = bytes exclude = constant exclude = lib exclude = perl exclude = strict exclude = vars exclude = warnings [Homepage] [ReadmeFromPod] [ReadmeMarkdownFromPod] [ReportVersions] [Repository] git_remote = gh [Git::Check] [Git::NextVersion] first_version = 1.021 version_regexp = ^v(\d+\.\d+)$ [ChangelogFromGit] tag_regexp = v(\d+[_.]\d+) [Git::Tag] tag_format = v%v tag_message = Release %v. [@Classic] [MetaJSON] Lexical-Persistence-1.022/dist.ini~000644 000765 000024 00000002171 12202157737 017344 0ustar00trocstaff000000 000000 name = Lexical-Persistence author = Rocco Caputo copyright_holder = Rocco Caputo license = Perl_5 [Prereqs] Devel::LexAlias = 0.04 PadWalker = 1.1 [MetaResources] bugtracker.mailto = bug-lexical-persistence@rt.cpan.org bugtracker.web = http://rt.cpan.org/Public/Dist/Display.html?Name=lexical-persistence homepage = http://search.cpan.org/dist/Lexical-Persistence/ license = http://dev.perl.org/licenses/ repository.type = git repository.url = git://github.com/rcaputo/lexical-persistence repository.web = http://github.com/rcaputo/lexical-persistence [Repository] git_remote = gh [ReadmeFromPod] [ReadmeMarkdownFromPod] [ReportVersions] ; Require everything to be checked in. ; Must exclude tarball directories from .gitignore. [Git::Check] ; Calculate the release version. [Git::NextVersion] first_version = 1.021 version_regexp = ^v(\d+\.\d+)$ ; Generate the changelog. [ChangelogFromGit] tag_regexp = v(\d+[_.]\d+) ; Tag the repository after release. [Git::Tag] tag_format = v%v tag_message = Release %v. [@Classic] Lexical-Persistence-1.022/eg/000755 000765 000024 00000000000 12202157737 016074 5ustar00trocstaff000000 000000 Lexical-Persistence-1.022/greedy.pl~000644 000765 000024 00000000417 12202157737 017515 0ustar00trocstaff000000 000000 use strict; use warnings; use Lexical::Persistence; my $environment = Lexical::Persistence->new; $environment->call( sub { my $foo = shift; { my $abc = 10 }; return $foo; } ); use Devel::Peek; print Devel::Peek::Dump($environment->get_context('_')->{'$abc'}); Lexical-Persistence-1.022/lib/000755 000765 000024 00000000000 12202157737 016247 5ustar00trocstaff000000 000000 Lexical-Persistence-1.022/LICENSE000644 000765 000024 00000043744 12202157737 016522 0ustar00trocstaff000000 000000 This software is copyright (c) 2013 by Rocco Caputo . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Rocco Caputo . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Rocco Caputo . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Lexical-Persistence-1.022/Makefile.old000644 000765 000024 00000057614 12202157737 017733 0ustar00trocstaff000000 000000 # This Makefile is for the Lexical::Persistence extension to perl. # # It was generated automatically by MakeMaker version # 6.54 (Revision: 65400) from the contents of # Makefile.PL. Don't edit this file, edit Makefile.PL instead. # # ANY CHANGES MADE HERE WILL BE LOST! # # MakeMaker ARGV: () # # MakeMaker Parameters: # ABSTRACT => q[Persistent, continuation-like contexts for lexical variables.] # AUTHOR => q[Rocco Caputo ] # LICENSE => q[perl] # META_ADD => { resources=>{ repository=>q[http://thirdlobe.com/svn/lex-per/trunk], license=>q[http://dev.perl.org/licenses/] } } # NAME => q[Lexical::Persistence] # PREREQ_PM => { PadWalker=>q[1.1], Devel::LexAlias=>q[0.04] } # VERSION_FROM => q[lib/Lexical/Persistence.pm] # dist => { COMPRESS=>q[gzip -9f], PREOP=>q[git-log.pl | /usr/bin/tee ./$(DISTNAME)-$(VERSION)/CHANGES > ./CHANGES; LANG=C perldoc lib/Lexical/Persistence.pm | /usr/bin/tee ./$(DISTNAME)-$(VERSION)/README > ./README], SUFFIX=>q[gz] } # --- MakeMaker post_initialize section: # --- MakeMaker const_config section: # These definitions are from config.sh (via /sw/lib/perl5-core/5.10.0/darwin-thread-multi-2level/Config.pm). # They may have been overridden via Makefile.PL or on the command line. AR = ar CC = gcc CCCDLFLAGS = CCDLFLAGS = DLEXT = bundle DLSRC = dl_dlopen.xs EXE_EXT = FULL_AR = /usr/bin/ar LD = env MACOSX_DEPLOYMENT_TARGET=10.3 cc LDDLFLAGS = -L/sw/lib -bundle -undefined dynamic_lookup LDFLAGS = -L/sw/lib LIBC = /usr/lib/libc.dylib LIB_EXT = .a OBJ_EXT = .o OSNAME = darwin OSVERS = 9.8.0 RANLIB = ranlib SITELIBEXP = /sw/lib/perl5/site_perl/5.10.0 SITEARCHEXP = /sw/lib/perl5/site_perl/5.10.0/darwin-thread-multi-2level SO = dylib VENDORARCHEXP = VENDORLIBEXP = # --- MakeMaker constants section: AR_STATIC_ARGS = cr DIRFILESEP = / DFSEP = $(DIRFILESEP) NAME = Lexical::Persistence NAME_SYM = Lexical_Persistence VERSION = 1.020 VERSION_MACRO = VERSION VERSION_SYM = 1_020 DEFINE_VERSION = -D$(VERSION_MACRO)=\"$(VERSION)\" XS_VERSION = 1.020 XS_VERSION_MACRO = XS_VERSION XS_DEFINE_VERSION = -D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\" INST_ARCHLIB = blib/arch INST_SCRIPT = blib/script INST_BIN = blib/bin INST_LIB = blib/lib INST_MAN1DIR = blib/man1 INST_MAN3DIR = blib/man3 MAN1EXT = 1 MAN3EXT = 3pm INSTALLDIRS = site DESTDIR = PREFIX = $(SITEPREFIX) PERLPREFIX = /sw SITEPREFIX = /sw VENDORPREFIX = INSTALLPRIVLIB = /sw/lib/perl5-core/5.10.0 DESTINSTALLPRIVLIB = $(DESTDIR)$(INSTALLPRIVLIB) INSTALLSITELIB = /sw/lib/perl5/site_perl/5.10.0 DESTINSTALLSITELIB = $(DESTDIR)$(INSTALLSITELIB) INSTALLVENDORLIB = DESTINSTALLVENDORLIB = $(DESTDIR)$(INSTALLVENDORLIB) INSTALLARCHLIB = /sw/lib/perl5-core/5.10.0/darwin-thread-multi-2level DESTINSTALLARCHLIB = $(DESTDIR)$(INSTALLARCHLIB) INSTALLSITEARCH = /sw/lib/perl5/site_perl/5.10.0/darwin-thread-multi-2level DESTINSTALLSITEARCH = $(DESTDIR)$(INSTALLSITEARCH) INSTALLVENDORARCH = DESTINSTALLVENDORARCH = $(DESTDIR)$(INSTALLVENDORARCH) INSTALLBIN = /sw/bin DESTINSTALLBIN = $(DESTDIR)$(INSTALLBIN) INSTALLSITEBIN = /sw/bin DESTINSTALLSITEBIN = $(DESTDIR)$(INSTALLSITEBIN) INSTALLVENDORBIN = DESTINSTALLVENDORBIN = $(DESTDIR)$(INSTALLVENDORBIN) INSTALLSCRIPT = /sw/bin DESTINSTALLSCRIPT = $(DESTDIR)$(INSTALLSCRIPT) INSTALLSITESCRIPT = /sw/bin DESTINSTALLSITESCRIPT = $(DESTDIR)$(INSTALLSITESCRIPT) INSTALLVENDORSCRIPT = DESTINSTALLVENDORSCRIPT = $(DESTDIR)$(INSTALLVENDORSCRIPT) INSTALLMAN1DIR = /sw/share/man/man1 DESTINSTALLMAN1DIR = $(DESTDIR)$(INSTALLMAN1DIR) INSTALLSITEMAN1DIR = /sw/share/man/man1 DESTINSTALLSITEMAN1DIR = $(DESTDIR)$(INSTALLSITEMAN1DIR) INSTALLVENDORMAN1DIR = DESTINSTALLVENDORMAN1DIR = $(DESTDIR)$(INSTALLVENDORMAN1DIR) INSTALLMAN3DIR = /sw/lib/perl5-core/5.10.0/man/man3 DESTINSTALLMAN3DIR = $(DESTDIR)$(INSTALLMAN3DIR) INSTALLSITEMAN3DIR = /sw/lib/perl5-core/5.10.0/man/man3 DESTINSTALLSITEMAN3DIR = $(DESTDIR)$(INSTALLSITEMAN3DIR) INSTALLVENDORMAN3DIR = DESTINSTALLVENDORMAN3DIR = $(DESTDIR)$(INSTALLVENDORMAN3DIR) PERL_LIB = /sw/lib/perl5-core/5.10.0 PERL_ARCHLIB = /sw/lib/perl5-core/5.10.0/darwin-thread-multi-2level LIBPERL_A = libperl.a FIRST_MAKEFILE = Makefile MAKEFILE_OLD = Makefile.old MAKE_APERL_FILE = Makefile.aperl PERLMAINCC = $(CC) PERL_INC = /sw/lib/perl5-core/5.10.0/darwin-thread-multi-2level/CORE PERL = /sw/bin/perl FULLPERL = /sw/bin/perl ABSPERL = $(PERL) PERLRUN = $(PERL) FULLPERLRUN = $(FULLPERL) ABSPERLRUN = $(ABSPERL) PERLRUNINST = $(PERLRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" FULLPERLRUNINST = $(FULLPERLRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" ABSPERLRUNINST = $(ABSPERLRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" PERL_CORE = 0 PERM_DIR = 755 PERM_RW = 644 PERM_RWX = 755 MAKEMAKER = /sw/lib/perl5-core/5.10.0/ExtUtils/MakeMaker.pm MM_VERSION = 6.54 MM_REVISION = 65400 # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle). # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle) # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar) # DLBASE = Basename part of dynamic library. May be just equal BASEEXT. MAKE = make FULLEXT = Lexical/Persistence BASEEXT = Persistence PARENT_NAME = Lexical DLBASE = $(BASEEXT) VERSION_FROM = lib/Lexical/Persistence.pm OBJECT = LDFROM = $(OBJECT) LINKTYPE = dynamic BOOTDEP = # Handy lists of source code files: XS_FILES = C_FILES = O_FILES = H_FILES = MAN1PODS = MAN3PODS = lib/Lexical/Persistence.pm # Where is the Config information that we are using/depend on CONFIGDEP = $(PERL_ARCHLIB)$(DFSEP)Config.pm $(PERL_INC)$(DFSEP)config.h # Where to build things INST_LIBDIR = $(INST_LIB)/Lexical INST_ARCHLIBDIR = $(INST_ARCHLIB)/Lexical INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT) INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT) INST_STATIC = INST_DYNAMIC = INST_BOOT = # Extra linker info EXPORT_LIST = PERL_ARCHIVE = PERL_ARCHIVE_AFTER = TO_INST_PM = lib/Lexical/Persistence.pm PM_TO_BLIB = lib/Lexical/Persistence.pm \ blib/lib/Lexical/Persistence.pm # --- MakeMaker platform_constants section: MM_Unix_VERSION = 6.54 PERL_MALLOC_DEF = -DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc -Dfree=Perl_mfree -Drealloc=Perl_realloc -Dcalloc=Perl_calloc # --- MakeMaker tool_autosplit section: # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto AUTOSPLITFILE = $(ABSPERLRUN) -e 'use AutoSplit; autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)' -- # --- MakeMaker tool_xsubpp section: # --- MakeMaker tools_other section: SHELL = /bin/sh CHMOD = chmod CP = cp MV = mv NOOP = $(TRUE) NOECHO = @ RM_F = rm -f RM_RF = rm -rf TEST_F = test -f TOUCH = touch UMASK_NULL = umask 0 DEV_NULL = > /dev/null 2>&1 MKPATH = $(ABSPERLRUN) -MExtUtils::Command -e 'mkpath' -- EQUALIZE_TIMESTAMP = $(ABSPERLRUN) -MExtUtils::Command -e 'eqtime' -- FALSE = false TRUE = true ECHO = echo ECHO_N = echo -n UNINST = 0 VERBINST = 0 MOD_INSTALL = $(ABSPERLRUN) -MExtUtils::Install -e 'install([ from_to => {@ARGV}, verbose => '\''$(VERBINST)'\'', uninstall_shadows => '\''$(UNINST)'\'', dir_mode => '\''$(PERM_DIR)'\'' ]);' -- DOC_INSTALL = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'perllocal_install' -- UNINSTALL = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'uninstall' -- WARN_IF_OLD_PACKLIST = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'warn_if_old_packlist' -- MACROSTART = MACROEND = USEMAKEFILE = -f FIXIN = $(ABSPERLRUN) -MExtUtils::MY -e 'MY->fixin(shift)' -- # --- MakeMaker makemakerdflt section: makemakerdflt : all $(NOECHO) $(NOOP) # --- MakeMaker dist section: TAR = COPY_EXTENDED_ATTRIBUTES_DISABLE=1 COPYFILE_DISABLE=1 tar TARFLAGS = cvf ZIP = zip ZIPFLAGS = -r COMPRESS = gzip -9f SUFFIX = gz SHAR = shar PREOP = git-log.pl | /usr/bin/tee ./$(DISTNAME)-$(VERSION)/CHANGES > ./CHANGES; LANG=C perldoc lib/Lexical/Persistence.pm | /usr/bin/tee ./$(DISTNAME)-$(VERSION)/README > ./README POSTOP = $(NOECHO) $(NOOP) TO_UNIX = $(NOECHO) $(NOOP) CI = ci -u RCS_LABEL = rcs -Nv$(VERSION_SYM): -q DIST_CP = best DIST_DEFAULT = tardist DISTNAME = Lexical-Persistence DISTVNAME = Lexical-Persistence-1.020 # --- MakeMaker macro section: # --- MakeMaker depend section: # --- MakeMaker cflags section: # --- MakeMaker const_loadlibs section: # --- MakeMaker const_cccmd section: # --- MakeMaker post_constants section: # --- MakeMaker pasthru section: PASTHRU = LIBPERL_A="$(LIBPERL_A)"\ LINKTYPE="$(LINKTYPE)"\ PREFIX="$(PREFIX)" # --- MakeMaker special_targets section: .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT) .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir # --- MakeMaker c_o section: # --- MakeMaker xs_c section: # --- MakeMaker xs_o section: # --- MakeMaker top_targets section: all :: pure_all manifypods $(NOECHO) $(NOOP) pure_all :: config pm_to_blib subdirs linkext $(NOECHO) $(NOOP) subdirs :: $(MYEXTLIB) $(NOECHO) $(NOOP) config :: $(FIRST_MAKEFILE) blibdirs $(NOECHO) $(NOOP) help : perldoc ExtUtils::MakeMaker # --- MakeMaker blibdirs section: blibdirs : $(INST_LIBDIR)$(DFSEP).exists $(INST_ARCHLIB)$(DFSEP).exists $(INST_AUTODIR)$(DFSEP).exists $(INST_ARCHAUTODIR)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists $(INST_SCRIPT)$(DFSEP).exists $(INST_MAN1DIR)$(DFSEP).exists $(INST_MAN3DIR)$(DFSEP).exists $(NOECHO) $(NOOP) # Backwards compat with 6.18 through 6.25 blibdirs.ts : blibdirs $(NOECHO) $(NOOP) $(INST_LIBDIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_LIBDIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_LIBDIR) $(NOECHO) $(TOUCH) $(INST_LIBDIR)$(DFSEP).exists $(INST_ARCHLIB)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_ARCHLIB) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_ARCHLIB) $(NOECHO) $(TOUCH) $(INST_ARCHLIB)$(DFSEP).exists $(INST_AUTODIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_AUTODIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_AUTODIR) $(NOECHO) $(TOUCH) $(INST_AUTODIR)$(DFSEP).exists $(INST_ARCHAUTODIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_ARCHAUTODIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_ARCHAUTODIR) $(NOECHO) $(TOUCH) $(INST_ARCHAUTODIR)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_BIN) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_BIN) $(NOECHO) $(TOUCH) $(INST_BIN)$(DFSEP).exists $(INST_SCRIPT)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_SCRIPT) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_SCRIPT) $(NOECHO) $(TOUCH) $(INST_SCRIPT)$(DFSEP).exists $(INST_MAN1DIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_MAN1DIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_MAN1DIR) $(NOECHO) $(TOUCH) $(INST_MAN1DIR)$(DFSEP).exists $(INST_MAN3DIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_MAN3DIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_MAN3DIR) $(NOECHO) $(TOUCH) $(INST_MAN3DIR)$(DFSEP).exists # --- MakeMaker linkext section: linkext :: $(LINKTYPE) $(NOECHO) $(NOOP) # --- MakeMaker dlsyms section: # --- MakeMaker dynamic section: dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT) $(NOECHO) $(NOOP) # --- MakeMaker dynamic_bs section: BOOTSTRAP = # --- MakeMaker dynamic_lib section: # --- MakeMaker static section: ## $(INST_PM) has been moved to the all: target. ## It remains here for awhile to allow for old usage: "make static" static :: $(FIRST_MAKEFILE) $(INST_STATIC) $(NOECHO) $(NOOP) # --- MakeMaker static_lib section: # --- MakeMaker manifypods section: POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--" POD2MAN = $(POD2MAN_EXE) manifypods : pure_all \ lib/Lexical/Persistence.pm $(NOECHO) $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) \ lib/Lexical/Persistence.pm $(INST_MAN3DIR)/Lexical::Persistence.$(MAN3EXT) # --- MakeMaker processPL section: # --- MakeMaker installbin section: # --- MakeMaker subdirs section: # none # --- MakeMaker clean_subdirs section: clean_subdirs : $(NOECHO) $(NOOP) # --- MakeMaker clean section: # Delete temporary files but do not touch installed files. We don't delete # the Makefile here so a later make realclean still has a makefile to use. clean :: clean_subdirs - $(RM_F) \ *$(LIB_EXT) core \ core.[0-9] $(INST_ARCHAUTODIR)/extralibs.all \ core.[0-9][0-9] $(BASEEXT).bso \ pm_to_blib.ts core.[0-9][0-9][0-9][0-9] \ $(BASEEXT).x $(BOOTSTRAP) \ perl$(EXE_EXT) tmon.out \ *$(OBJ_EXT) pm_to_blib \ $(INST_ARCHAUTODIR)/extralibs.ld blibdirs.ts \ core.[0-9][0-9][0-9][0-9][0-9] *perl.core \ core.*perl.*.? $(MAKE_APERL_FILE) \ perl $(BASEEXT).def \ core.[0-9][0-9][0-9] mon.out \ lib$(BASEEXT).def perlmain.c \ perl.exe so_locations \ $(BASEEXT).exp - $(RM_RF) \ blib - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL) # --- MakeMaker realclean_subdirs section: realclean_subdirs : $(NOECHO) $(NOOP) # --- MakeMaker realclean section: # Delete temporary files (via clean) and also delete dist files realclean purge :: clean realclean_subdirs - $(RM_F) \ $(MAKEFILE_OLD) $(FIRST_MAKEFILE) - $(RM_RF) \ $(DISTVNAME) # --- MakeMaker metafile section: metafile : create_distdir $(NOECHO) $(ECHO) Generating META.yml $(NOECHO) $(ECHO) '--- #YAML:1.0' > META_new.yml $(NOECHO) $(ECHO) 'name: Lexical-Persistence' >> META_new.yml $(NOECHO) $(ECHO) 'version: 1.020' >> META_new.yml $(NOECHO) $(ECHO) 'abstract: Persistent, continuation-like contexts for lexical variables.' >> META_new.yml $(NOECHO) $(ECHO) 'author:' >> META_new.yml $(NOECHO) $(ECHO) ' - Rocco Caputo ' >> META_new.yml $(NOECHO) $(ECHO) 'license: perl' >> META_new.yml $(NOECHO) $(ECHO) 'distribution_type: module' >> META_new.yml $(NOECHO) $(ECHO) 'configure_requires:' >> META_new.yml $(NOECHO) $(ECHO) ' ExtUtils::MakeMaker: 0' >> META_new.yml $(NOECHO) $(ECHO) 'build_requires:' >> META_new.yml $(NOECHO) $(ECHO) ' ExtUtils::MakeMaker: 0' >> META_new.yml $(NOECHO) $(ECHO) 'requires:' >> META_new.yml $(NOECHO) $(ECHO) ' Devel::LexAlias: 0.04' >> META_new.yml $(NOECHO) $(ECHO) ' PadWalker: 1.1' >> META_new.yml $(NOECHO) $(ECHO) 'resources:' >> META_new.yml $(NOECHO) $(ECHO) ' license: http://dev.perl.org/licenses/' >> META_new.yml $(NOECHO) $(ECHO) ' repository: http://thirdlobe.com/svn/lex-per/trunk' >> META_new.yml $(NOECHO) $(ECHO) 'no_index:' >> META_new.yml $(NOECHO) $(ECHO) ' directory:' >> META_new.yml $(NOECHO) $(ECHO) ' - t' >> META_new.yml $(NOECHO) $(ECHO) ' - inc' >> META_new.yml $(NOECHO) $(ECHO) 'generated_by: ExtUtils::MakeMaker version 6.54' >> META_new.yml $(NOECHO) $(ECHO) 'meta-spec:' >> META_new.yml $(NOECHO) $(ECHO) ' url: http://module-build.sourceforge.net/META-spec-v1.4.html' >> META_new.yml $(NOECHO) $(ECHO) ' version: 1.4' >> META_new.yml -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml # --- MakeMaker signature section: signature : cpansign -s # --- MakeMaker dist_basics section: distclean :: realclean distcheck $(NOECHO) $(NOOP) distcheck : $(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck skipcheck : $(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck manifest : $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest veryclean : realclean $(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old # --- MakeMaker dist_core section: dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE) $(NOECHO) $(ABSPERLRUN) -l -e 'print '\''Warning: Makefile possibly out of date with $(VERSION_FROM)'\''' \ -e ' if -e '\''$(VERSION_FROM)'\'' and -M '\''$(VERSION_FROM)'\'' < -M '\''$(FIRST_MAKEFILE)'\'';' -- tardist : $(DISTVNAME).tar$(SUFFIX) $(NOECHO) $(NOOP) uutardist : $(DISTVNAME).tar$(SUFFIX) uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu $(DISTVNAME).tar$(SUFFIX) : distdir $(PREOP) $(TO_UNIX) $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME) $(RM_RF) $(DISTVNAME) $(COMPRESS) $(DISTVNAME).tar $(POSTOP) zipdist : $(DISTVNAME).zip $(NOECHO) $(NOOP) $(DISTVNAME).zip : distdir $(PREOP) $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME) $(RM_RF) $(DISTVNAME) $(POSTOP) shdist : distdir $(PREOP) $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar $(RM_RF) $(DISTVNAME) $(POSTOP) # --- MakeMaker distdir section: create_distdir : $(RM_RF) $(DISTVNAME) $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \ -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');" distdir : create_distdir distmeta $(NOECHO) $(NOOP) # --- MakeMaker dist_test section: disttest : distdir cd $(DISTVNAME) && $(ABSPERLRUN) Makefile.PL cd $(DISTVNAME) && $(MAKE) $(PASTHRU) cd $(DISTVNAME) && $(MAKE) test $(PASTHRU) # --- MakeMaker dist_ci section: ci : $(PERLRUN) "-MExtUtils::Manifest=maniread" \ -e "@all = keys %{ maniread() };" \ -e "print(qq{Executing $(CI) @all\n}); system(qq{$(CI) @all});" \ -e "print(qq{Executing $(RCS_LABEL) ...\n}); system(qq{$(RCS_LABEL) @all});" # --- MakeMaker distmeta section: distmeta : create_distdir metafile $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) } ' \ -e ' or print "Could not add META.yml to MANIFEST: $${'\''@'\''}\n"' -- # --- MakeMaker distsignature section: distsignature : create_distdir $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) } ' \ -e ' or print "Could not add SIGNATURE to MANIFEST: $${'\''@'\''}\n"' -- $(NOECHO) cd $(DISTVNAME) && $(TOUCH) SIGNATURE cd $(DISTVNAME) && cpansign -s # --- MakeMaker install section: install :: pure_install doc_install $(NOECHO) $(NOOP) install_perl :: pure_perl_install doc_perl_install $(NOECHO) $(NOOP) install_site :: pure_site_install doc_site_install $(NOECHO) $(NOOP) install_vendor :: pure_vendor_install doc_vendor_install $(NOECHO) $(NOOP) pure_install :: pure_$(INSTALLDIRS)_install $(NOECHO) $(NOOP) doc_install :: doc_$(INSTALLDIRS)_install $(NOECHO) $(NOOP) pure__install : pure_site_install $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site doc__install : doc_site_install $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site pure_perl_install :: all $(NOECHO) $(MOD_INSTALL) \ read $(PERL_ARCHLIB)/auto/$(FULLEXT)/.packlist \ write $(DESTINSTALLARCHLIB)/auto/$(FULLEXT)/.packlist \ $(INST_LIB) $(DESTINSTALLPRIVLIB) \ $(INST_ARCHLIB) $(DESTINSTALLARCHLIB) \ $(INST_BIN) $(DESTINSTALLBIN) \ $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \ $(INST_MAN1DIR) $(DESTINSTALLMAN1DIR) \ $(INST_MAN3DIR) $(DESTINSTALLMAN3DIR) $(NOECHO) $(WARN_IF_OLD_PACKLIST) \ $(SITEARCHEXP)/auto/$(FULLEXT) pure_site_install :: all $(NOECHO) $(MOD_INSTALL) \ read $(SITEARCHEXP)/auto/$(FULLEXT)/.packlist \ write $(DESTINSTALLSITEARCH)/auto/$(FULLEXT)/.packlist \ $(INST_LIB) $(DESTINSTALLSITELIB) \ $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \ $(INST_BIN) $(DESTINSTALLSITEBIN) \ $(INST_SCRIPT) $(DESTINSTALLSITESCRIPT) \ $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \ $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR) $(NOECHO) $(WARN_IF_OLD_PACKLIST) \ $(PERL_ARCHLIB)/auto/$(FULLEXT) pure_vendor_install :: all $(NOECHO) $(MOD_INSTALL) \ read $(VENDORARCHEXP)/auto/$(FULLEXT)/.packlist \ write $(DESTINSTALLVENDORARCH)/auto/$(FULLEXT)/.packlist \ $(INST_LIB) $(DESTINSTALLVENDORLIB) \ $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \ $(INST_BIN) $(DESTINSTALLVENDORBIN) \ $(INST_SCRIPT) $(DESTINSTALLVENDORSCRIPT) \ $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \ $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR) doc_perl_install :: all $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) -$(NOECHO) $(DOC_INSTALL) \ "Module" "$(NAME)" \ "installed into" "$(INSTALLPRIVLIB)" \ LINKTYPE "$(LINKTYPE)" \ VERSION "$(VERSION)" \ EXE_FILES "$(EXE_FILES)" \ >> $(DESTINSTALLARCHLIB)/perllocal.pod doc_site_install :: all $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) -$(NOECHO) $(DOC_INSTALL) \ "Module" "$(NAME)" \ "installed into" "$(INSTALLSITELIB)" \ LINKTYPE "$(LINKTYPE)" \ VERSION "$(VERSION)" \ EXE_FILES "$(EXE_FILES)" \ >> $(DESTINSTALLARCHLIB)/perllocal.pod doc_vendor_install :: all $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) -$(NOECHO) $(DOC_INSTALL) \ "Module" "$(NAME)" \ "installed into" "$(INSTALLVENDORLIB)" \ LINKTYPE "$(LINKTYPE)" \ VERSION "$(VERSION)" \ EXE_FILES "$(EXE_FILES)" \ >> $(DESTINSTALLARCHLIB)/perllocal.pod uninstall :: uninstall_from_$(INSTALLDIRS)dirs $(NOECHO) $(NOOP) uninstall_from_perldirs :: $(NOECHO) $(UNINSTALL) $(PERL_ARCHLIB)/auto/$(FULLEXT)/.packlist uninstall_from_sitedirs :: $(NOECHO) $(UNINSTALL) $(SITEARCHEXP)/auto/$(FULLEXT)/.packlist uninstall_from_vendordirs :: $(NOECHO) $(UNINSTALL) $(VENDORARCHEXP)/auto/$(FULLEXT)/.packlist # --- MakeMaker force section: # Phony target to force checking subdirectories. FORCE : $(NOECHO) $(NOOP) # --- MakeMaker perldepend section: # --- MakeMaker makefile section: # We take a very conservative approach here, but it's worth it. # We move Makefile to Makefile.old here to avoid gnu make looping. $(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP) $(NOECHO) $(ECHO) "Makefile out-of-date with respect to $?" $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..." -$(NOECHO) $(RM_F) $(MAKEFILE_OLD) -$(NOECHO) $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) - $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL) $(PERLRUN) Makefile.PL $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <==" $(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command. <==" $(FALSE) # --- MakeMaker staticmake section: # --- MakeMaker makeaperl section --- MAP_TARGET = perl FULLPERL = /sw/bin/perl $(MAP_TARGET) :: static $(MAKE_APERL_FILE) $(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@ $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET) $(NOECHO) $(PERLRUNINST) \ Makefile.PL DIR= \ MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \ MAKEAPERL=1 NORECURS=1 CCCDLFLAGS= # --- MakeMaker test section: TEST_VERBOSE=0 TEST_TYPE=test_$(LINKTYPE) TEST_FILE = test.pl TEST_FILES = t/*.t TESTDB_SW = -d testdb :: testdb_$(LINKTYPE) test :: $(TEST_TYPE) subdirs-test subdirs-test :: $(NOECHO) $(NOOP) test_dynamic :: pure_all PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(TEST_FILES) testdb_dynamic :: pure_all PERL_DL_NONLAZY=1 $(FULLPERLRUN) $(TESTDB_SW) "-I$(INST_LIB)" "-I$(INST_ARCHLIB)" $(TEST_FILE) test_ : test_dynamic test_static :: test_dynamic testdb_static :: testdb_dynamic # --- MakeMaker ppd section: # Creates a PPD (Perl Package Description) for a binary distribution. ppd : $(NOECHO) $(ECHO) '' > $(DISTNAME).ppd $(NOECHO) $(ECHO) ' Persistent, continuation-like contexts for lexical variables.' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' Rocco Caputo <rcaputo@cpan.org>' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' ' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' ' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' ' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' ' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' ' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) ' ' >> $(DISTNAME).ppd $(NOECHO) $(ECHO) '' >> $(DISTNAME).ppd # --- MakeMaker pm_to_blib section: pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM) $(NOECHO) $(ABSPERLRUN) -MExtUtils::Install -e 'pm_to_blib({@ARGV}, '\''$(INST_LIB)/auto'\'', q[$(PM_FILTER)], '\''$(PERM_DIR)'\'')' -- \ lib/Lexical/Persistence.pm blib/lib/Lexical/Persistence.pm $(NOECHO) $(TOUCH) pm_to_blib # --- MakeMaker selfdocument section: # --- MakeMaker postamble section: # End. Lexical-Persistence-1.022/Makefile.PL000644 000765 000024 00000003047 12202157737 017457 0ustar00trocstaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Persistent lexical variable values for arbitrary calls.", "AUTHOR" => "Rocco Caputo ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Lexical-Persistence", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Lexical::Persistence", "PREREQ_PM" => { "Devel::LexAlias" => "0.05", "PadWalker" => "1.96", "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Carp" => "1.26", "Scalar::Util" => "1.29", "Test::More" => "0.98", "constant" => 0 }, "VERSION" => "1.022", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Lexical-Persistence-1.022/Makefile.PL~000644 000765 000024 00000002121 12202157737 017645 0ustar00trocstaff000000 000000 use warnings; use strict; use ExtUtils::MakeMaker; ### Touch files that will be generated at "make dist" time. ### ExtUtils::MakeMaker and Module::Build will complain about them if ### they aren't present now. foreach my $touched (qw(CHANGES META.yml README)) { open TOUCH, ">>", $touched and close TOUCH; } ### Generate Makefile.PL. WriteMakefile( NAME => 'Lexical::Persistence', AUTHOR => 'Rocco Caputo ', ABSTRACT => 'Persistent, continuation-like contexts for lexical variables.', VERSION_FROM => 'lib/Lexical/Persistence.pm', LICENSE => 'perl', META_ADD => { resources => { license => 'http://dev.perl.org/licenses/', repository => 'http://thirdlobe.com/svn/lex-per/trunk' }, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', PREOP => ( 'git-log.pl | ' . '/usr/bin/tee ./$(DISTNAME)-$(VERSION)/CHANGES > ./CHANGES; ' . 'LANG=C perldoc lib/Lexical/Persistence.pm | ' . '/usr/bin/tee ./$(DISTNAME)-$(VERSION)/README > ./README' ), }, PREREQ_PM => { 'Devel::LexAlias' => 0.04, 'PadWalker' => 1.1, }, ); 1; Lexical-Persistence-1.022/MANIFEST000644 000765 000024 00000000704 12202157737 016633 0ustar00trocstaff000000 000000 CHANGES LICENSE MANIFEST META.json META.yml Makefile.PL Makefile.PL~ Makefile.old README README.mkdn dist.ini dist.ini~ eg/persistence.perl eg/persistence.perl~ eg/repl-mst.perl eg/repl-mst.perl~ greedy.pl~ lib/Lexical/Persistence.pm lib/Lexical/Persistence.pm~ t/000-report-versions.t t/01_basics.t t/01_basics.t~ t/02_pod.t t/02_pod.t~ t/03_pod_coverage.t t/03_pod_coverage.t~ t/04_eval.t t/04_eval.t~ t/release-pod-coverage.t t/release-pod-syntax.t Lexical-Persistence-1.022/META.json000644 000765 000024 00000003351 12202157737 017124 0ustar00trocstaff000000 000000 { "abstract" : "Persistent lexical variable values for arbitrary calls.", "author" : [ "Rocco Caputo " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300035, CPAN::Meta::Converter version 2.132140", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Lexical-Persistence", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Devel::LexAlias" : "0.05", "PadWalker" : "1.96", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Carp" : "1.26", "Scalar::Util" : "1.29", "Test::More" : "0.98", "constant" : "0", "perl" : "5.004" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Lexical-Persistence@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Lexical-Persistence" }, "homepage" : "http://search.cpan.org/dist/Lexical-Persistence/", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/rcaputo/lexical-persistence.git", "web" : "https://github.com/rcaputo/lexical-persistence" } }, "version" : "1.022" } Lexical-Persistence-1.022/META.yml000644 000765 000024 00000001520 12202157737 016750 0ustar00trocstaff000000 000000 --- abstract: 'Persistent lexical variable values for arbitrary calls.' author: - 'Rocco Caputo ' build_requires: Carp: 1.26 Scalar::Util: 1.29 Test::More: 0.98 constant: 0 perl: 5.004 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300035, CPAN::Meta::Converter version 2.132140' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Lexical-Persistence requires: Devel::LexAlias: 0.05 PadWalker: 1.96 strict: 0 warnings: 0 resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Lexical-Persistence homepage: http://search.cpan.org/dist/Lexical-Persistence/ license: http://dev.perl.org/licenses/ repository: git://github.com/rcaputo/lexical-persistence.git version: 1.022 Lexical-Persistence-1.022/README000644 000765 000024 00000035507 12202157737 016373 0ustar00trocstaff000000 000000 NAME Lexical::Persistence - Persistent lexical variable values for arbitrary calls. VERSION version 1.022 SYNOPSIS #!/usr/bin/perl use Lexical::Persistence; my $persistence = Lexical::Persistence->new(); foreach my $number (qw(one two three four five)) { $persistence->call(\&target, number => $number); } exit; sub target { my $arg_number; # Argument. my $narf_x++; # Persistent. my $_i++; # Dynamic. my $j++; # Persistent. print "arg_number = $arg_number\n"; print "\tnarf_x = $narf_x\n"; print "\t_i = $_i\n"; print "\tj = $j\n"; } DESCRIPTION Lexical::Persistence does a few things, all related. Note that all the behaviors listed here are the defaults. Subclasses can override nearly every aspect of Lexical::Persistence's behavior. Lexical::Persistence lets your code access persistent data through lexical variables. This example prints "some value" because the value of $x persists in the $lp object between setter() and getter(). use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->call(\&setter); $lp->call(\&getter); sub setter { my $x = "some value" } sub getter { print my $x, "\n" } Lexicals with leading underscores are not persistent. By default, Lexical::Persistence supports accessing data from multiple sources through the use of variable prefixes. The set_context() member sets each data source. It takes a prefix name and a hash of key/value pairs. By default, the keys must have sigils representing their variable types. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( pi => { '$member' => 3.141 } ); $lp->set_context( e => { '@member' => [ 2, '.', 7, 1, 8 ] } ); $lp->set_context( animal => { '%member' => { cat => "meow", dog => "woof" } } ); $lp->call(\&display); sub display { my ($pi_member, @e_member, %animal_member); print "pi = $pi_member\n"; print "e = @e_member\n"; while (my ($animal, $sound) = each %animal_member) { print "The $animal goes... $sound!\n"; } } And the corresponding output: pi = 3.141 e = 2 . 7 1 8 The cat goes... meow! The dog goes... woof! By default, call() takes a single subroutine reference and an optional list of named arguments. The arguments will be passed directly to the called subroutine, but Lexical::Persistence also makes the values available from the "arg" prefix. use Lexical::Persistence; my %animals = ( snake => "hiss", plane => "I'm Cartesian", ); my $lp = Lexical::Persistence->new(); while (my ($animal, $sound) = each %animals) { $lp->call(\&display, animal => $animal, sound => $sound); } sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The plane goes... I'm Cartesian! The snake goes... hiss! Sometimes you want to call functions normally. The wrap() method will wrap your function in a small thunk that does the call() for you, returning a coderef. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); my $thunk = $lp->wrap(\&display); $thunk->(animal => "squirrel", sound => "nuts"); sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The squirrel goes... nuts! Prefixes are the characters leading up to the first underscore in a lexical variable's name. However, there's also a default context named underscore. It's literally "_" because the underscore is not legal in a context name by default. Variables without prefixes, or with prefixes that have not been previously defined by set_context(), are stored in that context. The get_context() member returns a hash for a named context. This allows your code to manipulate the values within a persistent context. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( _ => { '@mind' => [qw(My mind is going. I can feel it.)] } ); while (1) { $lp->call(\&display); my $mind = $lp->get_context("_")->{'@mind'}; splice @$mind, rand(@$mind), 1; last unless @$mind; } sub display { my @mind; print "@mind\n"; } Displays something like: My mind is going. I can feel it. My is going. I can feel it. My is going. I feel it. My going. I feel it. My going. I feel My I feel My I My It's possible to create multiple Lexical::Persistence objects, each with a unique state. use Lexical::Persistence; my $lp_1 = Lexical::Persistence->new(); $lp_1->set_context( _ => { '$foo' => "context 1's foo" } ); my $lp_2 = Lexical::Persistence->new(); $lp_2->set_context( _ => { '$foo' => "the foo in context 2" } ); $lp_1->call(\&display); $lp_2->call(\&display); sub display { print my $foo, "\n"; } Gets you this output: context 1's foo the foo in context 2 You can also compile and execute perl code contained in plain strings in a a lexical environment that already contains the persisted variables. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do( 'my $message = "Hello, world" ); $lp->do( 'print "$message\n"' ); Which gives the output: Hello, world If you come up with other fun uses, let us know. new Create a new lexical persistence object. This object will store one or more persistent contexts. When called by this object, lexical variables will take on the values kept in this object. initialize_contexts This method is called by new() to declare the initial contexts for a new Lexical::Persistence object. The default implementation declares the default "_" context. Override or extend it to create others as needed. set_context NAME, HASH Store a context HASH within the persistence object, keyed on a NAME. Members of the context HASH are unprefixed versions of the lexicals they'll persist, including the sigil. For example, this set_context() call declares a "request" context with predefined values for three variables: $request_foo, @request_foo, and %request_foo: $lp->set_context( request => { '$foo' => 'value of $request_foo', '@foo' => [qw( value of @request_foo )], '%foo' => { key => 'value of $request_foo{key}' } } ); See parse_variable() for information about how Lexical::Persistence decides which context a lexical belongs to and how you can change that. get_context NAME Returns a context hash associated with a particular context name. Autovivifies the context if it doesn't already exist, so be careful there. call CODEREF, ARGUMENT_LIST Call CODEREF with lexical persistence and an optional ARGUMENT_LIST, consisting of name => value pairs. Unlike with set_context(), however, argument names do not need sigils. This may change in the future, however, as it's easy to access an argument with the wrong variable type. The ARGUMENT_LIST is passed to the called CODEREF through @_ in the usual way. They're also available as $arg_name variables for convenience. See push_arg_context() for information about how $arg_name works, and what you can do to change that behavior. invoke OBJECT, METHOD, ARGUMENT_LIST Invoke OBJECT->METHOD(ARGUMENT_LIST) while maintaining state for the METHOD's lexical variables. Written in terms of call(), except that it takes OBJECT and METHOD rather than CODEREF. See call() for more details. May have issues with methods invoked via AUTOLOAD, as invoke() uses can() to find the method's CODEREF for call(). wrap CODEREF Wrap a function or anonymous CODEREF so that it's transparently called via call(). Returns a coderef which can be called directly. Named arguments to the call will automatically become available as $arg_name lexicals within the called CODEREF. See call() and push_arg_context() for more details. prepare CODE Wrap a CODE string in a subroutine definition, and prepend declarations for all the variables stored in the Lexical::Persistence default context. This avoids having to declare variables explicitly in the code using 'my'. Returns a new code string ready for Perl's built-in eval(). From there, a program may $lp->call() the code or $lp->wrap() it. Also see "compile()", which is a convenient wrapper for prepare() and Perl's built-in eval(). Also see "do()", which is a convenient way to prepare(), eval() and call() in one step. compile CODE compile() is a convenience method to prepare() a CODE string, eval() it, and then return the resulting coderef. If it fails, it returns false, and $@ will explain why. do CODE do() is a convenience method to compile() a CODE string and execute it. It returns the result of CODE's execution, or it throws an exception on failure. This example prints the numbers 1 through 10. Note, however, that do() compiles the same code each time. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); $lp->do('print ++$count, "\\n"') for 1..10; Lexical declarations are preserved across do() invocations, such as with $count in the surrounding examples. This behavior is part of prepare(), which do() uses via compile(). The previous example may be rewritten in terms of compile() and call() to avoid recompiling code every iteration. Lexical declarations are preserved between do() and compile() as well: use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); my $coderef = $lp->compile('print ++$count, "\\n"'); $lp->call($coderef) for 1..10; do() inherits some limitations from PadWalker's peek_sub(). For instance, it cannot alias lexicals within sub() definitions in the supplied CODE string. However, Lexical::Persistence can do this with careful use of eval() and some custom CODE preparation. parse_variable VARIABLE_NAME This method determines whether VARIABLE_NAME should be persistent. If it should, parse_variable() will return three values: the variable's sigil ('$', '@' or '%'), the context name in which the variable persists (see set_context()), and the name of the member within that context where the value is stored. parse_variable() returns nothing if VARIABLE_NAME should not be persistent. parse_variable() also determines whether the member name includes its sigil. By default, the "arg" context is the only one with members that have no sigils. This is done to support the unadorned argument names used by call(). This method implements a default behavior. It's intended to be overridden or extended by subclasses. get_member_ref SIGIL, CONTEXT, MEMBER This method fetches a reference to the named MEMBER of a particular named CONTEXT. The returned value type will be governed by the given SIGIL. Scalar values are stored internally as scalars to be consistent with how most people store scalars. The persistent value is created if it doesn't exist. The initial value is undef or empty, depending on its type. This method implements a default behavior. It's intended to be overridden or extended by subclasses. push_arg_context ARGUMENT_LIST Convert a named ARGUMENT_LIST into members of an argument context, and call set_context() to declare that context. This is how $arg_foo variables are supported. This method returns the previous context, fetched by get_context() before the new context is set. This method implements a default behavior. It's intended to be overridden or extended by subclasses. For example, to redefine the parameters as $param_foo. See pop_arg_context() for the other side of this coin. pop_arg_context OLD_ARG_CONTEXT Restores OLD_ARG_CONTEXT after a target function has returned. The OLD_ARG_CONTEXT is the return value from the push_arg_context() call just prior to the target function's call. This method implements a default behavior. It's intended to be overridden or extended by subclasses. SEE ALSO POE::Stage, Devel::LexAlias, PadWalker, Catalyst::Controller::BindLex. BUG TRACKER https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Lexical-Persis tence REPOSITORY http://github.com/rcaputo/lexical-persistence http://gitorious.org/lexical-persistence OTHER RESOURCES http://search.cpan.org/dist/Lexical-Persistence/ COPYRIGHT Lexical::Persistence in copyright 2006-2013 by Rocco Caputo. All rights reserved. Lexical::Persistence is free software. It is released under the same terms as Perl itself. ACKNOWLEDGEMENTS Thanks to Matt Trout and Yuval Kogman for lots of inspiration. They were the demon and the other demon sitting on my shoulders. Nick Perez convinced me to make this a class rather than persist with the original, functional design. While Higher Order Perl is fun for development, I have to say the move to OO was a good one. Paul "LeoNerd" Evans contributed the compile() and eval() methods. The South Florida Perl Mongers, especially Jeff Bisbee and Marlon Bailey, for documentation feedback. irc://irc.perl.org/poe for support and feedback. Lexical-Persistence-1.022/README.mkdn000644 000765 000024 00000031635 12202157737 017321 0ustar00trocstaff000000 000000 # NAME Lexical::Persistence - Persistent lexical variable values for arbitrary calls. # VERSION version 1.022 # SYNOPSIS #!/usr/bin/perl use Lexical::Persistence; my $persistence = Lexical::Persistence->new(); foreach my $number (qw(one two three four five)) { $persistence->call(\&target, number => $number); } exit; sub target { my $arg_number; # Argument. my $narf_x++; # Persistent. my $_i++; # Dynamic. my $j++; # Persistent. print "arg_number = $arg_number\n"; print "\tnarf_x = $narf_x\n"; print "\t_i = $_i\n"; print "\tj = $j\n"; } # DESCRIPTION Lexical::Persistence does a few things, all related. Note that all the behaviors listed here are the defaults. Subclasses can override nearly every aspect of Lexical::Persistence's behavior. Lexical::Persistence lets your code access persistent data through lexical variables. This example prints "some value" because the value of $x persists in the $lp object between setter() and getter(). use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->call(\&setter); $lp->call(\&getter); sub setter { my $x = "some value" } sub getter { print my $x, "\n" } Lexicals with leading underscores are not persistent. By default, Lexical::Persistence supports accessing data from multiple sources through the use of variable prefixes. The set\_context() member sets each data source. It takes a prefix name and a hash of key/value pairs. By default, the keys must have sigils representing their variable types. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( pi => { '$member' => 3.141 } ); $lp->set_context( e => { '@member' => [ 2, '.', 7, 1, 8 ] } ); $lp->set_context( animal => { '%member' => { cat => "meow", dog => "woof" } } ); $lp->call(\&display); sub display { my ($pi_member, @e_member, %animal_member); print "pi = $pi_member\n"; print "e = @e_member\n"; while (my ($animal, $sound) = each %animal_member) { print "The $animal goes... $sound!\n"; } } And the corresponding output: pi = 3.141 e = 2 . 7 1 8 The cat goes... meow! The dog goes... woof! By default, call() takes a single subroutine reference and an optional list of named arguments. The arguments will be passed directly to the called subroutine, but Lexical::Persistence also makes the values available from the "arg" prefix. use Lexical::Persistence; my %animals = ( snake => "hiss", plane => "I'm Cartesian", ); my $lp = Lexical::Persistence->new(); while (my ($animal, $sound) = each %animals) { $lp->call(\&display, animal => $animal, sound => $sound); } sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The plane goes... I'm Cartesian! The snake goes... hiss! Sometimes you want to call functions normally. The wrap() method will wrap your function in a small thunk that does the call() for you, returning a coderef. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); my $thunk = $lp->wrap(\&display); $thunk->(animal => "squirrel", sound => "nuts"); sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The squirrel goes... nuts! Prefixes are the characters leading up to the first underscore in a lexical variable's name. However, there's also a default context named underscore. It's literally "\_" because the underscore is not legal in a context name by default. Variables without prefixes, or with prefixes that have not been previously defined by set\_context(), are stored in that context. The get\_context() member returns a hash for a named context. This allows your code to manipulate the values within a persistent context. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( _ => { '@mind' => [qw(My mind is going. I can feel it.)] } ); while (1) { $lp->call(\&display); my $mind = $lp->get_context("_")->{'@mind'}; splice @$mind, rand(@$mind), 1; last unless @$mind; } sub display { my @mind; print "@mind\n"; } Displays something like: My mind is going. I can feel it. My is going. I can feel it. My is going. I feel it. My going. I feel it. My going. I feel My I feel My I My It's possible to create multiple Lexical::Persistence objects, each with a unique state. use Lexical::Persistence; my $lp_1 = Lexical::Persistence->new(); $lp_1->set_context( _ => { '$foo' => "context 1's foo" } ); my $lp_2 = Lexical::Persistence->new(); $lp_2->set_context( _ => { '$foo' => "the foo in context 2" } ); $lp_1->call(\&display); $lp_2->call(\&display); sub display { print my $foo, "\n"; } Gets you this output: context 1's foo the foo in context 2 You can also compile and execute perl code contained in plain strings in a a lexical environment that already contains the persisted variables. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do( 'my $message = "Hello, world" ); $lp->do( 'print "$message\n"' ); Which gives the output: Hello, world If you come up with other fun uses, let us know. ## new Create a new lexical persistence object. This object will store one or more persistent contexts. When called by this object, lexical variables will take on the values kept in this object. ## initialize\_contexts This method is called by new() to declare the initial contexts for a new Lexical::Persistence object. The default implementation declares the default "\_" context. Override or extend it to create others as needed. ## set\_context NAME, HASH Store a context HASH within the persistence object, keyed on a NAME. Members of the context HASH are unprefixed versions of the lexicals they'll persist, including the sigil. For example, this set\_context() call declares a "request" context with predefined values for three variables: $request\_foo, @request\_foo, and %request\_foo: $lp->set_context( request => { '$foo' => 'value of $request_foo', '@foo' => [qw( value of @request_foo )], '%foo' => { key => 'value of $request_foo{key}' } } ); See parse\_variable() for information about how Lexical::Persistence decides which context a lexical belongs to and how you can change that. ## get\_context NAME Returns a context hash associated with a particular context name. Autovivifies the context if it doesn't already exist, so be careful there. ## call CODEREF, ARGUMENT\_LIST Call CODEREF with lexical persistence and an optional ARGUMENT\_LIST, consisting of name => value pairs. Unlike with set\_context(), however, argument names do not need sigils. This may change in the future, however, as it's easy to access an argument with the wrong variable type. The ARGUMENT\_LIST is passed to the called CODEREF through @\_ in the usual way. They're also available as $arg\_name variables for convenience. See push\_arg\_context() for information about how $arg\_name works, and what you can do to change that behavior. ## invoke OBJECT, METHOD, ARGUMENT\_LIST Invoke OBJECT->METHOD(ARGUMENT\_LIST) while maintaining state for the METHOD's lexical variables. Written in terms of call(), except that it takes OBJECT and METHOD rather than CODEREF. See call() for more details. May have issues with methods invoked via AUTOLOAD, as invoke() uses can() to find the method's CODEREF for call(). ## wrap CODEREF Wrap a function or anonymous CODEREF so that it's transparently called via call(). Returns a coderef which can be called directly. Named arguments to the call will automatically become available as $arg\_name lexicals within the called CODEREF. See call() and push\_arg\_context() for more details. ## prepare CODE Wrap a CODE string in a subroutine definition, and prepend declarations for all the variables stored in the Lexical::Persistence default context. This avoids having to declare variables explicitly in the code using 'my'. Returns a new code string ready for Perl's built-in eval(). From there, a program may $lp->call() the code or $lp->wrap() it. Also see ["compile()"](#compile()), which is a convenient wrapper for prepare() and Perl's built-in eval(). Also see ["do()"](#do()), which is a convenient way to prepare(), eval() and call() in one step. ## compile CODE compile() is a convenience method to prepare() a CODE string, eval() it, and then return the resulting coderef. If it fails, it returns false, and $@ will explain why. ## do CODE do() is a convenience method to compile() a CODE string and execute it. It returns the result of CODE's execution, or it throws an exception on failure. This example prints the numbers 1 through 10. Note, however, that do() compiles the same code each time. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); $lp->do('print ++$count, "\\n"') for 1..10; Lexical declarations are preserved across do() invocations, such as with $count in the surrounding examples. This behavior is part of prepare(), which do() uses via compile(). The previous example may be rewritten in terms of compile() and call() to avoid recompiling code every iteration. Lexical declarations are preserved between do() and compile() as well: use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); my $coderef = $lp->compile('print ++$count, "\\n"'); $lp->call($coderef) for 1..10; do() inherits some limitations from PadWalker's peek\_sub(). For instance, it cannot alias lexicals within sub() definitions in the supplied CODE string. However, Lexical::Persistence can do this with careful use of eval() and some custom CODE preparation. ## parse\_variable VARIABLE\_NAME This method determines whether VARIABLE\_NAME should be persistent. If it should, parse\_variable() will return three values: the variable's sigil ('$', '@' or '%'), the context name in which the variable persists (see set\_context()), and the name of the member within that context where the value is stored. parse\_variable() returns nothing if VARIABLE\_NAME should not be persistent. parse\_variable() also determines whether the member name includes its sigil. By default, the "arg" context is the only one with members that have no sigils. This is done to support the unadorned argument names used by call(). This method implements a default behavior. It's intended to be overridden or extended by subclasses. ## get\_member\_ref SIGIL, CONTEXT, MEMBER This method fetches a reference to the named MEMBER of a particular named CONTEXT. The returned value type will be governed by the given SIGIL. Scalar values are stored internally as scalars to be consistent with how most people store scalars. The persistent value is created if it doesn't exist. The initial value is undef or empty, depending on its type. This method implements a default behavior. It's intended to be overridden or extended by subclasses. ## push\_arg\_context ARGUMENT\_LIST Convert a named ARGUMENT\_LIST into members of an argument context, and call set\_context() to declare that context. This is how $arg\_foo variables are supported. This method returns the previous context, fetched by get\_context() before the new context is set. This method implements a default behavior. It's intended to be overridden or extended by subclasses. For example, to redefine the parameters as $param\_foo. See pop\_arg\_context() for the other side of this coin. ## pop\_arg\_context OLD\_ARG\_CONTEXT Restores OLD\_ARG\_CONTEXT after a target function has returned. The OLD\_ARG\_CONTEXT is the return value from the push\_arg\_context() call just prior to the target function's call. This method implements a default behavior. It's intended to be overridden or extended by subclasses. # SEE ALSO [POE::Stage](http://search.cpan.org/perldoc?POE::Stage), [Devel::LexAlias](http://search.cpan.org/perldoc?Devel::LexAlias), [PadWalker](http://search.cpan.org/perldoc?PadWalker), [Catalyst::Controller::BindLex](http://search.cpan.org/perldoc?Catalyst::Controller::BindLex). ## BUG TRACKER https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Lexical-Persistence ## REPOSITORY http://github.com/rcaputo/lexical-persistence http://gitorious.org/lexical-persistence ## OTHER RESOURCES http://search.cpan.org/dist/Lexical-Persistence/ # COPYRIGHT Lexical::Persistence in copyright 2006-2013 by Rocco Caputo. All rights reserved. Lexical::Persistence is free software. It is released under the same terms as Perl itself. # ACKNOWLEDGEMENTS Thanks to Matt Trout and Yuval Kogman for lots of inspiration. They were the demon and the other demon sitting on my shoulders. Nick Perez convinced me to make this a class rather than persist with the original, functional design. While Higher Order Perl is fun for development, I have to say the move to OO was a good one. Paul "LeoNerd" Evans contributed the compile() and eval() methods. The South Florida Perl Mongers, especially Jeff Bisbee and Marlon Bailey, for documentation feedback. irc://irc.perl.org/poe for support and feedback. Lexical-Persistence-1.022/t/000755 000765 000024 00000000000 12202157737 015744 5ustar00trocstaff000000 000000 Lexical-Persistence-1.022/t/000-report-versions.t000644 000765 000024 00000031270 12202157737 021612 0ustar00trocstaff000000 000000 #!perl use warnings; use strict; use Test::More 0.94; # Include a cut-down version of YAML::Tiny so we don't introduce unnecessary # dependencies ourselves. package Local::YAML::Tiny; use strict; use Carp 'croak'; # UTF Support? sub HAVE_UTF8 () { $] >= 5.007003 } BEGIN { if ( HAVE_UTF8 ) { # The string eval helps hide this from Test::MinimumVersion eval "require utf8;"; die "Failed to load UTF-8 support" if $@; } # Class structure require 5.004; $YAML::Tiny::VERSION = '1.40'; # Error storage $YAML::Tiny::errstr = ''; } # Printable characters for escapes my %UNESCAPES = ( z => "\x00", a => "\x07", t => "\x09", n => "\x0a", v => "\x0b", f => "\x0c", r => "\x0d", e => "\x1b", '\\' => '\\', ); ##################################################################### # Implementation # Create an empty YAML::Tiny object sub new { my $class = shift; bless [ @_ ], $class; } # Create an object from a file sub read { my $class = ref $_[0] ? ref shift : shift; # Check the file my $file = shift or return $class->_error( 'You did not specify a file name' ); return $class->_error( "File '$file' does not exist" ) unless -e $file; return $class->_error( "'$file' is a directory, not a file" ) unless -f _; return $class->_error( "Insufficient permissions to read '$file'" ) unless -r _; # Slurp in the file local $/ = undef; local *CFG; unless ( open(CFG, $file) ) { return $class->_error("Failed to open file '$file': $!"); } my $contents = ; unless ( close(CFG) ) { return $class->_error("Failed to close file '$file': $!"); } $class->read_string( $contents ); } # Create an object from a string sub read_string { my $class = ref $_[0] ? ref shift : shift; my $self = bless [], $class; my $string = $_[0]; unless ( defined $string ) { return $self->_error("Did not provide a string to load"); } # Byte order marks # NOTE: Keeping this here to educate maintainers # my %BOM = ( # "\357\273\277" => 'UTF-8', # "\376\377" => 'UTF-16BE', # "\377\376" => 'UTF-16LE', # "\377\376\0\0" => 'UTF-32LE' # "\0\0\376\377" => 'UTF-32BE', # ); if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) { return $self->_error("Stream has a non UTF-8 BOM"); } else { # Strip UTF-8 bom if found, we'll just ignore it $string =~ s/^\357\273\277//; } # Try to decode as utf8 utf8::decode($string) if HAVE_UTF8; # Check for some special cases return $self unless length $string; unless ( $string =~ /[\012\015]+\z/ ) { return $self->_error("Stream does not end with newline character"); } # Split the file into lines my @lines = grep { ! /^\s*(?:\#.*)?\z/ } split /(?:\015{1,2}\012|\015|\012)/, $string; # Strip the initial YAML header @lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/ and shift @lines; # A nibbling parser while ( @lines ) { # Do we have a document header? if ( $lines[0] =~ /^---\s*(?:(.+)\s*)?\z/ ) { # Handle scalar documents shift @lines; if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) { push @$self, $self->_read_scalar( "$1", [ undef ], \@lines ); next; } } if ( ! @lines or $lines[0] =~ /^(?:---|\.\.\.)/ ) { # A naked document push @$self, undef; while ( @lines and $lines[0] !~ /^---/ ) { shift @lines; } } elsif ( $lines[0] =~ /^\s*\-/ ) { # An array at the root my $document = [ ]; push @$self, $document; $self->_read_array( $document, [ 0 ], \@lines ); } elsif ( $lines[0] =~ /^(\s*)\S/ ) { # A hash at the root my $document = { }; push @$self, $document; $self->_read_hash( $document, [ length($1) ], \@lines ); } else { croak("YAML::Tiny failed to classify the line '$lines[0]'"); } } $self; } # Deparse a scalar string to the actual scalar sub _read_scalar { my ($self, $string, $indent, $lines) = @_; # Trim trailing whitespace $string =~ s/\s*\z//; # Explitic null/undef return undef if $string eq '~'; # Quotes if ( $string =~ /^\'(.*?)\'\z/ ) { return '' unless defined $1; $string = $1; $string =~ s/\'\'/\'/g; return $string; } if ( $string =~ /^\"((?:\\.|[^\"])*)\"\z/ ) { # Reusing the variable is a little ugly, # but avoids a new variable and a string copy. $string = $1; $string =~ s/\\"/"/g; $string =~ s/\\([never\\fartz]|x([0-9a-fA-F]{2}))/(length($1)>1)?pack("H2",$2):$UNESCAPES{$1}/gex; return $string; } # Special cases if ( $string =~ /^[\'\"!&]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } return {} if $string eq '{}'; return [] if $string eq '[]'; # Regular unquoted string return $string unless $string =~ /^[>|]/; # Error croak("YAML::Tiny failed to find multi-line scalar content") unless @$lines; # Check the indent depth $lines->[0] =~ /^(\s*)/; $indent->[-1] = length("$1"); if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Pull the lines my @multiline = (); while ( @$lines ) { $lines->[0] =~ /^(\s*)/; last unless length($1) >= $indent->[-1]; push @multiline, substr(shift(@$lines), length($1)); } my $j = (substr($string, 0, 1) eq '>') ? ' ' : "\n"; my $t = (substr($string, 1, 1) eq '-') ? '' : "\n"; return join( $j, @multiline ) . $t; } # Parse an array sub _read_array { my ($self, $array, $indent, $lines) = @_; while ( @$lines ) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } if ( $lines->[0] =~ /^(\s*\-\s+)[^\'\"]\S*\s*:(?:\s+|$)/ ) { # Inline nested hash my $indent2 = length("$1"); $lines->[0] =~ s/-/ /; push @$array, { }; $self->_read_hash( $array->[-1], [ @$indent, $indent2 ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-(\s*)(.+?)\s*\z/ ) { # Array entry with a value shift @$lines; push @$array, $self->_read_scalar( "$2", [ @$indent, undef ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) { shift @$lines; unless ( @$lines ) { push @$array, undef; return 1; } if ( $lines->[0] =~ /^(\s*)\-/ ) { my $indent2 = length("$1"); if ( $indent->[-1] == $indent2 ) { # Null array entry push @$array, undef; } else { # Naked indenter push @$array, [ ]; $self->_read_array( $array->[-1], [ @$indent, $indent2 ], $lines ); } } elsif ( $lines->[0] =~ /^(\s*)\S/ ) { push @$array, { }; $self->_read_hash( $array->[-1], [ @$indent, length("$1") ], $lines ); } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) { # This is probably a structure like the following... # --- # foo: # - list # bar: value # # ... so lets return and let the hash parser handle it return 1; } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } return 1; } # Parse an array sub _read_hash { my ($self, $hash, $indent, $lines) = @_; while ( @$lines ) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Get the key unless ( $lines->[0] =~ s/^\s*([^\'\" ][^\n]*?)\s*:(\s+|$)// ) { if ( $lines->[0] =~ /^\s*[?\'\"]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } croak("YAML::Tiny failed to classify line '$lines->[0]'"); } my $key = $1; # Do we have a value? if ( length $lines->[0] ) { # Yes $hash->{$key} = $self->_read_scalar( shift(@$lines), [ @$indent, undef ], $lines ); } else { # An indent shift @$lines; unless ( @$lines ) { $hash->{$key} = undef; return 1; } if ( $lines->[0] =~ /^(\s*)-/ ) { $hash->{$key} = []; $self->_read_array( $hash->{$key}, [ @$indent, length($1) ], $lines ); } elsif ( $lines->[0] =~ /^(\s*)./ ) { my $indent2 = length("$1"); if ( $indent->[-1] >= $indent2 ) { # Null hash entry $hash->{$key} = undef; } else { $hash->{$key} = {}; $self->_read_hash( $hash->{$key}, [ @$indent, length($1) ], $lines ); } } } } return 1; } # Set error sub _error { $YAML::Tiny::errstr = $_[1]; undef; } # Retrieve error sub errstr { $YAML::Tiny::errstr; } ##################################################################### # Use Scalar::Util if possible, otherwise emulate it BEGIN { eval { require Scalar::Util; }; if ( $@ ) { # Failed to load Scalar::Util eval <<'END_PERL'; sub refaddr { my $pkg = ref($_[0]) or return undef; if (!!UNIVERSAL::can($_[0], 'can')) { bless $_[0], 'Scalar::Util::Fake'; } else { $pkg = undef; } "$_[0]" =~ /0x(\w+)/; my $i = do { local $^W; hex $1 }; bless $_[0], $pkg if defined $pkg; $i; } END_PERL } else { Scalar::Util->import('refaddr'); } } ##################################################################### # main test ##################################################################### package main; BEGIN { # Skip modules that either don't want to be loaded directly, such as # Module::Install, or that mess with the test count, such as the Test::* # modules listed here. # # Moose::Role conflicts if Moose is loaded as well, but Moose::Role is in # the Moose distribution and it's certain that someone who uses # Moose::Role also uses Moose somewhere, so if we disallow Moose::Role, # we'll still get the relevant version number. my %skip = map { $_ => 1 } qw( App::FatPacker Class::Accessor::Classy Devel::Cover Module::Install Moose::Role POE::Loop::Tk Template::Test Test::Kwalitee Test::Pod::Coverage Test::Portability::Files Test::YAML::Meta open ); my $Test = Test::Builder->new; $Test->plan(skip_all => "META.yml could not be found") unless -f 'META.yml' and -r _; my $meta = (Local::YAML::Tiny->read('META.yml'))->[0]; my %requires; for my $require_key (grep { /requires/ } keys %$meta) { my %h = %{ $meta->{$require_key} }; $requires{$_}++ for keys %h; } delete $requires{perl}; diag("Testing with Perl $], $^X"); for my $module (sort keys %requires) { if ($skip{$module}) { note "$module doesn't want to be loaded directly, skipping"; next; } local $SIG{__WARN__} = sub { note "$module: $_[0]" }; require_ok $module or BAIL_OUT("can't load $module"); my $version = $module->VERSION; $version = 'undefined' unless defined $version; diag(" $module version is $version"); } done_testing; } Lexical-Persistence-1.022/t/01_basics.t000644 000765 000024 00000002640 12202157737 017677 0ustar00trocstaff000000 000000 #!perl use warnings; use strict; use Lexical::Persistence; use constant CATCHALL_X => 100; use constant X => 200; use constant OTHER_X => 300; use Test::More tests => 36; sub target { my ($arg_test, $catchall_x, $x, $other_x, $_j); is ( $catchall_x++, CATCHALL_X + $arg_test, "persistent catchall $arg_test" ); is ( $x++, X + $arg_test, "persistent x $arg_test" ); is ( $other_x++, OTHER_X + $arg_test, "other x $arg_test" ); is ( $_j++, 0, "dynamic j $arg_test" ); } my $state = Lexical::Persistence->new(); $state->set_context( other => { '$x' => OTHER_X } ); $state->set_context( _ => { '$catchall_x' => CATCHALL_X, '$x' => X } ); ### Test plain old calling. for my $test (0..2) { $state->call(\&target, test => $test); } ### Test calling via wrapper. my $thunk = $state->wrap(\&target); for my $test (3..5) { $thunk->(test => $test); } ### Test method invocation. { package TestObject; use Test::More; sub new { return bless [ ] } sub target { my ($arg_test, $catchall_x, $x, $other_x, $_j); is ( $catchall_x++, ::CATCHALL_X + $arg_test, "persistent catchall (method) $arg_test" ); is ( $x++, ::X + $arg_test, "persistent x (method) $arg_test" ); is ( $other_x++, ::OTHER_X + $arg_test, "other x (method) $arg_test" ); is ( $_j++, 0, "dynamic j (method) $arg_test" ); } } my $object = TestObject->new(); for my $test (6..8) { $state->invoke($object, "target", test => $test); } Lexical-Persistence-1.022/t/01_basics.t~000600 000765 000024 00000002647 12202157737 020074 0ustar00trocstaff000000 000000 #!perl # $Id$ use warnings; use strict; use Lexical::Persistence; use constant CATCHALL_X => 100; use constant X => 200; use constant OTHER_X => 300; use Test::More tests => 36; sub target { my ($arg_test, $catchall_x, $x, $other_x, $_j); is ( $catchall_x++, CATCHALL_X + $arg_test, "persistent catchall $arg_test" ); is ( $x++, X + $arg_test, "persistent x $arg_test" ); is ( $other_x++, OTHER_X + $arg_test, "other x $arg_test" ); is ( $_j++, 0, "dynamic j $arg_test" ); } my $state = Lexical::Persistence->new(); $state->set_context( other => { '$x' => OTHER_X } ); $state->set_context( _ => { '$catchall_x' => CATCHALL_X, '$x' => X } ); ### Test plain old calling. for my $test (0..2) { $state->call(\&target, test => $test); } ### Test calling via wrapper. my $thunk = $state->wrap(\&target); for my $test (3..5) { $thunk->(test => $test); } ### Test method invocation. { package TestObject; use Test::More; sub new { return bless [ ] } sub target { my ($arg_test, $catchall_x, $x, $other_x, $_j); is ( $catchall_x++, ::CATCHALL_X + $arg_test, "persistent catchall (method) $arg_test" ); is ( $x++, ::X + $arg_test, "persistent x (method) $arg_test" ); is ( $other_x++, ::OTHER_X + $arg_test, "other x (method) $arg_test" ); is ( $_j++, 0, "dynamic j (method) $arg_test" ); } } my $object = TestObject->new(); for my $test (6..8) { $state->invoke($object, "target", test => $test); } Lexical-Persistence-1.022/t/02_pod.t000644 000765 000024 00000000227 12202157737 017215 0ustar00trocstaff000000 000000 # vim: filetype=perl 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(); Lexical-Persistence-1.022/t/02_pod.t~000600 000765 000024 00000000236 12202157737 017403 0ustar00trocstaff000000 000000 # $Id$ # vim: filetype=perl 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(); Lexical-Persistence-1.022/t/03_pod_coverage.t000644 000765 000024 00000000267 12202157737 021075 0ustar00trocstaff000000 000000 # vim: filetype=perl 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(); Lexical-Persistence-1.022/t/03_pod_coverage.t~000600 000765 000024 00000000364 12202157737 021261 0ustar00trocstaff000000 000000 # $Id: 02_pod_coverage.t 2139 2006-10-01 17:07:59Z rcaputo $ # vim: filetype=perl 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(); Lexical-Persistence-1.022/t/04_eval.t000644 000765 000024 00000001624 12202157737 017366 0ustar00trocstaff000000 000000 #!perl use warnings; use strict; use Lexical::Persistence; use Test::More tests => 9; my $lp = Lexical::Persistence->new(); is( $lp->do( '1 + 2' ), 3, 'constant do' ); $lp->do( 'my $three = 3' ); is_deeply( $lp->get_context('_'), { '$three' => 3 }, 'do sets context' ); my $code = $lp->compile( '$three' ); is( ref $code, 'CODE', 'compile yields a CODE ref' ); is( $lp->call( $code ), 3, 'CODE ref yields the right result' ); is( $lp->do( '$three + 4' ), 7, 'do still persists' ); $lp->do( '$three = 10' ); is( $lp->do( '$three' ), 10, 'do updates' ); $lp->do( 'my @list' ); is_deeply( $lp->get_context('_'), { '$three' => 10, '@list' => [], }, 'do can add new variables' ); $code = $lp->compile( '$four' ); my $err = "$@"; is( $code, undef, 'syntax error makes do return undef' ); like( $err, qr/^Global symbol "\$four" requires explicit package name/, 'syntax error complains about variable names' ); Lexical-Persistence-1.022/t/04_eval.t~000600 000765 000024 00000001633 12202157737 017554 0ustar00trocstaff000000 000000 #!perl # $Id$ use warnings; use strict; use Lexical::Persistence; use Test::More tests => 9; my $lp = Lexical::Persistence->new(); is( $lp->do( '1 + 2' ), 3, 'constant do' ); $lp->do( 'my $three = 3' ); is_deeply( $lp->get_context('_'), { '$three' => 3 }, 'do sets context' ); my $code = $lp->compile( '$three' ); is( ref $code, 'CODE', 'compile yields a CODE ref' ); is( $lp->call( $code ), 3, 'CODE ref yields the right result' ); is( $lp->do( '$three + 4' ), 7, 'do still persists' ); $lp->do( '$three = 10' ); is( $lp->do( '$three' ), 10, 'do updates' ); $lp->do( 'my @list' ); is_deeply( $lp->get_context('_'), { '$three' => 10, '@list' => [], }, 'do can add new variables' ); $code = $lp->compile( '$four' ); my $err = "$@"; is( $code, undef, 'syntax error makes do return undef' ); like( $err, qr/^Global symbol "\$four" requires explicit package name/, 'syntax error complains about variable names' ); Lexical-Persistence-1.022/t/release-pod-coverage.t000644 000765 000024 00000000765 12202157737 022132 0ustar00trocstaff000000 000000 #!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Lexical-Persistence-1.022/t/release-pod-syntax.t000644 000765 000024 00000000450 12202157737 021654 0ustar00trocstaff000000 000000 #!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Lexical-Persistence-1.022/lib/Lexical/000755 000765 000024 00000000000 12202157737 017630 5ustar00trocstaff000000 000000 Lexical-Persistence-1.022/lib/Lexical/Persistence.pm000644 000765 000024 00000040240 12202157737 022452 0ustar00trocstaff000000 000000 =head1 NAME Lexical::Persistence - Persistent lexical variable values for arbitrary calls. =head1 VERSION version 1.022 =head1 SYNOPSIS #!/usr/bin/perl use Lexical::Persistence; my $persistence = Lexical::Persistence->new(); foreach my $number (qw(one two three four five)) { $persistence->call(\&target, number => $number); } exit; sub target { my $arg_number; # Argument. my $narf_x++; # Persistent. my $_i++; # Dynamic. my $j++; # Persistent. print "arg_number = $arg_number\n"; print "\tnarf_x = $narf_x\n"; print "\t_i = $_i\n"; print "\tj = $j\n"; } =head1 DESCRIPTION Lexical::Persistence does a few things, all related. Note that all the behaviors listed here are the defaults. Subclasses can override nearly every aspect of Lexical::Persistence's behavior. Lexical::Persistence lets your code access persistent data through lexical variables. This example prints "some value" because the value of $x persists in the $lp object between setter() and getter(). use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->call(\&setter); $lp->call(\&getter); sub setter { my $x = "some value" } sub getter { print my $x, "\n" } Lexicals with leading underscores are not persistent. By default, Lexical::Persistence supports accessing data from multiple sources through the use of variable prefixes. The set_context() member sets each data source. It takes a prefix name and a hash of key/value pairs. By default, the keys must have sigils representing their variable types. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( pi => { '$member' => 3.141 } ); $lp->set_context( e => { '@member' => [ 2, '.', 7, 1, 8 ] } ); $lp->set_context( animal => { '%member' => { cat => "meow", dog => "woof" } } ); $lp->call(\&display); sub display { my ($pi_member, @e_member, %animal_member); print "pi = $pi_member\n"; print "e = @e_member\n"; while (my ($animal, $sound) = each %animal_member) { print "The $animal goes... $sound!\n"; } } And the corresponding output: pi = 3.141 e = 2 . 7 1 8 The cat goes... meow! The dog goes... woof! By default, call() takes a single subroutine reference and an optional list of named arguments. The arguments will be passed directly to the called subroutine, but Lexical::Persistence also makes the values available from the "arg" prefix. use Lexical::Persistence; my %animals = ( snake => "hiss", plane => "I'm Cartesian", ); my $lp = Lexical::Persistence->new(); while (my ($animal, $sound) = each %animals) { $lp->call(\&display, animal => $animal, sound => $sound); } sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The plane goes... I'm Cartesian! The snake goes... hiss! Sometimes you want to call functions normally. The wrap() method will wrap your function in a small thunk that does the call() for you, returning a coderef. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); my $thunk = $lp->wrap(\&display); $thunk->(animal => "squirrel", sound => "nuts"); sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The squirrel goes... nuts! Prefixes are the characters leading up to the first underscore in a lexical variable's name. However, there's also a default context named underscore. It's literally "_" because the underscore is not legal in a context name by default. Variables without prefixes, or with prefixes that have not been previously defined by set_context(), are stored in that context. The get_context() member returns a hash for a named context. This allows your code to manipulate the values within a persistent context. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( _ => { '@mind' => [qw(My mind is going. I can feel it.)] } ); while (1) { $lp->call(\&display); my $mind = $lp->get_context("_")->{'@mind'}; splice @$mind, rand(@$mind), 1; last unless @$mind; } sub display { my @mind; print "@mind\n"; } Displays something like: My mind is going. I can feel it. My is going. I can feel it. My is going. I feel it. My going. I feel it. My going. I feel My I feel My I My It's possible to create multiple Lexical::Persistence objects, each with a unique state. use Lexical::Persistence; my $lp_1 = Lexical::Persistence->new(); $lp_1->set_context( _ => { '$foo' => "context 1's foo" } ); my $lp_2 = Lexical::Persistence->new(); $lp_2->set_context( _ => { '$foo' => "the foo in context 2" } ); $lp_1->call(\&display); $lp_2->call(\&display); sub display { print my $foo, "\n"; } Gets you this output: context 1's foo the foo in context 2 You can also compile and execute perl code contained in plain strings in a a lexical environment that already contains the persisted variables. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do( 'my $message = "Hello, world" ); $lp->do( 'print "$message\n"' ); Which gives the output: Hello, world If you come up with other fun uses, let us know. =cut package Lexical::Persistence; use warnings; use strict; our $VERSION = '1.020'; use Devel::LexAlias qw(lexalias); use PadWalker qw(peek_sub); =head2 new Create a new lexical persistence object. This object will store one or more persistent contexts. When called by this object, lexical variables will take on the values kept in this object. =cut sub new { my $class = shift; my $self = bless { context => { }, }, $class; $self->initialize_contexts(); return $self; } =head2 initialize_contexts This method is called by new() to declare the initial contexts for a new Lexical::Persistence object. The default implementation declares the default "_" context. Override or extend it to create others as needed. =cut sub initialize_contexts { my $self = shift; $self->set_context( _ => { } ); } =head2 set_context NAME, HASH Store a context HASH within the persistence object, keyed on a NAME. Members of the context HASH are unprefixed versions of the lexicals they'll persist, including the sigil. For example, this set_context() call declares a "request" context with predefined values for three variables: $request_foo, @request_foo, and %request_foo: $lp->set_context( request => { '$foo' => 'value of $request_foo', '@foo' => [qw( value of @request_foo )], '%foo' => { key => 'value of $request_foo{key}' } } ); See parse_variable() for information about how Lexical::Persistence decides which context a lexical belongs to and how you can change that. =cut sub set_context { my ($self, $context_name, $context_hash) = @_; $self->{context}{$context_name} = $context_hash; } =head2 get_context NAME Returns a context hash associated with a particular context name. Autovivifies the context if it doesn't already exist, so be careful there. =cut sub get_context { my ($self, $context_name) = @_; $self->{context}{$context_name} ||= { }; } =head2 call CODEREF, ARGUMENT_LIST Call CODEREF with lexical persistence and an optional ARGUMENT_LIST, consisting of name => value pairs. Unlike with set_context(), however, argument names do not need sigils. This may change in the future, however, as it's easy to access an argument with the wrong variable type. The ARGUMENT_LIST is passed to the called CODEREF through @_ in the usual way. They're also available as $arg_name variables for convenience. See push_arg_context() for information about how $arg_name works, and what you can do to change that behavior. =cut sub call { my ($self, $sub, @args) = @_; my $old_arg_context = $self->push_arg_context(@args); my $pad = peek_sub($sub); while (my ($var, $ref) = each %$pad) { next unless my ($sigil, $context, $member) = $self->parse_variable($var); lexalias( $sub, $var, $self->get_member_ref($sigil, $context, $member) ); } unless (defined wantarray) { $sub->(@args); $self->pop_arg_context($old_arg_context); return; } if (wantarray) { my @return = $sub->(@args); $self->pop_arg_context($old_arg_context); return @return; } my $return = $sub->(@args); $self->pop_arg_context($old_arg_context); return $return; } =head2 invoke OBJECT, METHOD, ARGUMENT_LIST Invoke OBJECT->METHOD(ARGUMENT_LIST) while maintaining state for the METHOD's lexical variables. Written in terms of call(), except that it takes OBJECT and METHOD rather than CODEREF. See call() for more details. May have issues with methods invoked via AUTOLOAD, as invoke() uses can() to find the method's CODEREF for call(). =cut sub invoke { my ($self, $object, $method, @args) = @_; return unless defined( my $sub = $object->can($method) ); $self->call($sub, @args); } =head2 wrap CODEREF Wrap a function or anonymous CODEREF so that it's transparently called via call(). Returns a coderef which can be called directly. Named arguments to the call will automatically become available as $arg_name lexicals within the called CODEREF. See call() and push_arg_context() for more details. =cut sub wrap { my ($self, $invocant, $method) = @_; if (ref($invocant) eq 'CODE') { return sub { $self->call($invocant, @_); }; } # FIXME - Experimental method wrapper. # TODO - Make it resolve the method at call time. # TODO - Possibly make it generate dynamic facade classes. return sub { $self->invoke($invocant, $method, @_); }; } =head2 prepare CODE Wrap a CODE string in a subroutine definition, and prepend declarations for all the variables stored in the Lexical::Persistence default context. This avoids having to declare variables explicitly in the code using 'my'. Returns a new code string ready for Perl's built-in eval(). From there, a program may $lp->call() the code or $lp->wrap() it. Also see L, which is a convenient wrapper for prepare() and Perl's built-in eval(). Also see L, which is a convenient way to prepare(), eval() and call() in one step. =cut sub prepare { my ($self, $code) = @_; # Don't worry about values because $self->call() will deal with them my $vars = join( " ", map { "my $_;" } keys %{ $self->get_context('_') } ); # Declare the variables OUTSIDE the actual sub. The compiler will # pull any into the sub that are actually used. Any that aren't will # just get dropped at this point return "$vars sub { $code }"; } =head2 compile CODE compile() is a convenience method to prepare() a CODE string, eval() it, and then return the resulting coderef. If it fails, it returns false, and $@ will explain why. =cut sub compile { my ($self, $code) = @_; return eval($self->prepare($code)); } =head2 do CODE do() is a convenience method to compile() a CODE string and execute it. It returns the result of CODE's execution, or it throws an exception on failure. This example prints the numbers 1 through 10. Note, however, that do() compiles the same code each time. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); $lp->do('print ++$count, "\\n"') for 1..10; Lexical declarations are preserved across do() invocations, such as with $count in the surrounding examples. This behavior is part of prepare(), which do() uses via compile(). The previous example may be rewritten in terms of compile() and call() to avoid recompiling code every iteration. Lexical declarations are preserved between do() and compile() as well: use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); my $coderef = $lp->compile('print ++$count, "\\n"'); $lp->call($coderef) for 1..10; do() inherits some limitations from PadWalker's peek_sub(). For instance, it cannot alias lexicals within sub() definitions in the supplied CODE string. However, Lexical::Persistence can do this with careful use of eval() and some custom CODE preparation. =cut sub do { my ($self, $code) = @_; my $sub = $self->compile( $code ) or die $@; $self->call( $sub ); } =head2 parse_variable VARIABLE_NAME This method determines whether VARIABLE_NAME should be persistent. If it should, parse_variable() will return three values: the variable's sigil ('$', '@' or '%'), the context name in which the variable persists (see set_context()), and the name of the member within that context where the value is stored. parse_variable() returns nothing if VARIABLE_NAME should not be persistent. parse_variable() also determines whether the member name includes its sigil. By default, the "arg" context is the only one with members that have no sigils. This is done to support the unadorned argument names used by call(). This method implements a default behavior. It's intended to be overridden or extended by subclasses. =cut sub parse_variable { my ($self, $var) = @_; return unless ( my ($sigil, $context, $member) = ( $var =~ /^([\$\@\%])(?!_)(?:([^_]*)_)?(\S+)/ ) ); if (defined $context) { if (exists $self->{context}{$context}) { return $sigil, $context, $member if $context eq "arg"; return $sigil, $context, "$sigil$member"; } return $sigil, "_", "$sigil$context\_$member"; } return $sigil, "_", "$sigil$member"; } =head2 get_member_ref SIGIL, CONTEXT, MEMBER This method fetches a reference to the named MEMBER of a particular named CONTEXT. The returned value type will be governed by the given SIGIL. Scalar values are stored internally as scalars to be consistent with how most people store scalars. The persistent value is created if it doesn't exist. The initial value is undef or empty, depending on its type. This method implements a default behavior. It's intended to be overridden or extended by subclasses. =cut sub get_member_ref { my ($self, $sigil, $context, $member) = @_; my $hash = $self->{context}{$context}; if ($sigil eq '$') { $hash->{$member} = undef unless exists $hash->{$member}; return \$hash->{$member}; } if ($sigil eq '@') { $hash->{$member} = [ ] unless exists $hash->{$member}; } elsif ($sigil eq '%') { $hash->{$member} = { } unless exists $hash->{$member}; } return $hash->{$member}; } =head2 push_arg_context ARGUMENT_LIST Convert a named ARGUMENT_LIST into members of an argument context, and call set_context() to declare that context. This is how $arg_foo variables are supported. This method returns the previous context, fetched by get_context() before the new context is set. This method implements a default behavior. It's intended to be overridden or extended by subclasses. For example, to redefine the parameters as $param_foo. See pop_arg_context() for the other side of this coin. =cut sub push_arg_context { my $self = shift; my $old_arg_context = $self->get_context("arg"); $self->set_context( arg => { @_ } ); return $old_arg_context; } =head2 pop_arg_context OLD_ARG_CONTEXT Restores OLD_ARG_CONTEXT after a target function has returned. The OLD_ARG_CONTEXT is the return value from the push_arg_context() call just prior to the target function's call. This method implements a default behavior. It's intended to be overridden or extended by subclasses. =cut sub pop_arg_context { my ($self, $old_context) = @_; $self->set_context( arg => $old_context ); } =head1 SEE ALSO L, L, L, L. =head2 BUG TRACKER https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Lexical-Persistence =head2 REPOSITORY http://github.com/rcaputo/lexical-persistence http://gitorious.org/lexical-persistence =head2 OTHER RESOURCES http://search.cpan.org/dist/Lexical-Persistence/ =head1 COPYRIGHT Lexical::Persistence in copyright 2006-2013 by Rocco Caputo. All rights reserved. Lexical::Persistence is free software. It is released under the same terms as Perl itself. =head1 ACKNOWLEDGEMENTS Thanks to Matt Trout and Yuval Kogman for lots of inspiration. They were the demon and the other demon sitting on my shoulders. Nick Perez convinced me to make this a class rather than persist with the original, functional design. While Higher Order Perl is fun for development, I have to say the move to OO was a good one. Paul "LeoNerd" Evans contributed the compile() and eval() methods. The South Florida Perl Mongers, especially Jeff Bisbee and Marlon Bailey, for documentation feedback. irc://irc.perl.org/poe for support and feedback. =cut 1; Lexical-Persistence-1.022/lib/Lexical/Persistence.pm~000644 000765 000024 00000040201 12202157737 022645 0ustar00trocstaff000000 000000 =head1 NAME Lexical::Persistence - Persistent lexical variable values for arbitrary calls. =head1 SYNOPSIS #!/usr/bin/perl use Lexical::Persistence; my $persistence = Lexical::Persistence->new(); foreach my $number (qw(one two three four five)) { $persistence->call(\&target, number => $number); } exit; sub target { my $arg_number; # Argument. my $narf_x++; # Persistent. my $_i++; # Dynamic. my $j++; # Persistent. print "arg_number = $arg_number\n"; print "\tnarf_x = $narf_x\n"; print "\t_i = $_i\n"; print "\tj = $j\n"; } =head1 DESCRIPTION Lexical::Persistence does a few things, all related. Note that all the behaviors listed here are the defaults. Subclasses can override nearly every aspect of Lexical::Persistence's behavior. Lexical::Persistence lets your code access persistent data through lexical variables. This example prints "some value" because the value of $x persists in the $lp object between setter() and getter(). use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->call(\&setter); $lp->call(\&getter); sub setter { my $x = "some value" } sub getter { print my $x, "\n" } Lexicals with leading underscores are not persistent. By default, Lexical::Persistence supports accessing data from multiple sources through the use of variable prefixes. The set_context() member sets each data source. It takes a prefix name and a hash of key/value pairs. By default, the keys must have sigils representing their variable types. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( pi => { '$member' => 3.141 } ); $lp->set_context( e => { '@member' => [ 2, '.', 7, 1, 8 ] } ); $lp->set_context( animal => { '%member' => { cat => "meow", dog => "woof" } } ); $lp->call(\&display); sub display { my ($pi_member, @e_member, %animal_member); print "pi = $pi_member\n"; print "e = @e_member\n"; while (my ($animal, $sound) = each %animal_member) { print "The $animal goes... $sound!\n"; } } And the corresponding output: pi = 3.141 e = 2 . 7 1 8 The cat goes... meow! The dog goes... woof! By default, call() takes a single subroutine reference and an optional list of named arguments. The arguments will be passed directly to the called subroutine, but Lexical::Persistence also makes the values available from the "arg" prefix. use Lexical::Persistence; my %animals = ( snake => "hiss", plane => "I'm Cartesian", ); my $lp = Lexical::Persistence->new(); while (my ($animal, $sound) = each %animals) { $lp->call(\&display, animal => $animal, sound => $sound); } sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The plane goes... I'm Cartesian! The snake goes... hiss! Sometimes you want to call functions normally. The wrap() method will wrap your function in a small thunk that does the call() for you, returning a coderef. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); my $thunk = $lp->wrap(\&display); $thunk->(animal => "squirrel", sound => "nuts"); sub display { my ($arg_animal, $arg_sound); print "The $arg_animal goes... $arg_sound!\n"; } And the corresponding output: The squirrel goes... nuts! Prefixes are the characters leading up to the first underscore in a lexical variable's name. However, there's also a default context named underscore. It's literally "_" because the underscore is not legal in a context name by default. Variables without prefixes, or with prefixes that have not been previously defined by set_context(), are stored in that context. The get_context() member returns a hash for a named context. This allows your code to manipulate the values within a persistent context. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->set_context( _ => { '@mind' => [qw(My mind is going. I can feel it.)] } ); while (1) { $lp->call(\&display); my $mind = $lp->get_context("_")->{'@mind'}; splice @$mind, rand(@$mind), 1; last unless @$mind; } sub display { my @mind; print "@mind\n"; } Displays something like: My mind is going. I can feel it. My is going. I can feel it. My is going. I feel it. My going. I feel it. My going. I feel My I feel My I My It's possible to create multiple Lexical::Persistence objects, each with a unique state. use Lexical::Persistence; my $lp_1 = Lexical::Persistence->new(); $lp_1->set_context( _ => { '$foo' => "context 1's foo" } ); my $lp_2 = Lexical::Persistence->new(); $lp_2->set_context( _ => { '$foo' => "the foo in context 2" } ); $lp_1->call(\&display); $lp_2->call(\&display); sub display { print my $foo, "\n"; } Gets you this output: context 1's foo the foo in context 2 You can also compile and execute perl code contained in plain strings in a a lexical environment that already contains the persisted variables. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do( 'my $message = "Hello, world" ); $lp->do( 'print "$message\n"' ); Which gives the output: Hello, world If you come up with other fun uses, let us know. =cut package Lexical::Persistence; use warnings; use strict; our $VERSION = '1.020'; use Devel::LexAlias qw(lexalias); use PadWalker qw(peek_sub); =head2 new Create a new lexical persistence object. This object will store one or more persistent contexts. When called by this object, lexical variables will take on the values kept in this object. =cut sub new { my $class = shift; my $self = bless { context => { }, }, $class; $self->initialize_contexts(); return $self; } =head2 initialize_contexts This method is called by new() to declare the initial contexts for a new Lexical::Persistence object. The default implementation declares the default "_" context. Override or extend it to create others as needed. =cut sub initialize_contexts { my $self = shift; $self->set_context( _ => { } ); } =head2 set_context NAME, HASH Store a context HASH within the persistence object, keyed on a NAME. Members of the context HASH are unprefixed versions of the lexicals they'll persist, including the sigil. For example, this set_context() call declares a "request" context with predefined values for three variables: $request_foo, @request_foo, and %request_foo: $lp->set_context( request => { '$foo' => 'value of $request_foo', '@foo' => [qw( value of @request_foo )], '%foo' => { key => 'value of $request_foo{key}' } } ); See parse_variable() for information about how Lexical::Persistence decides which context a lexical belongs to and how you can change that. =cut sub set_context { my ($self, $context_name, $context_hash) = @_; $self->{context}{$context_name} = $context_hash; } =head2 get_context NAME Returns a context hash associated with a particular context name. Autovivifies the context if it doesn't already exist, so be careful there. =cut sub get_context { my ($self, $context_name) = @_; $self->{context}{$context_name} ||= { }; } =head2 call CODEREF, ARGUMENT_LIST Call CODEREF with lexical persistence and an optional ARGUMENT_LIST, consisting of name => value pairs. Unlike with set_context(), however, argument names do not need sigils. This may change in the future, however, as it's easy to access an argument with the wrong variable type. The ARGUMENT_LIST is passed to the called CODEREF through @_ in the usual way. They're also available as $arg_name variables for convenience. See push_arg_context() for information about how $arg_name works, and what you can do to change that behavior. =cut sub call { my ($self, $sub, @args) = @_; my $old_arg_context = $self->push_arg_context(@args); my $pad = peek_sub($sub); while (my ($var, $ref) = each %$pad) { next unless my ($sigil, $context, $member) = $self->parse_variable($var); lexalias( $sub, $var, $self->get_member_ref($sigil, $context, $member) ); } unless (defined wantarray) { $sub->(@args); $self->pop_arg_context($old_arg_context); return; } if (wantarray) { my @return = $sub->(@args); $self->pop_arg_context($old_arg_context); return @return; } my $return = $sub->(@args); $self->pop_arg_context($old_arg_context); return $return; } =head2 invoke OBJECT, METHOD, ARGUMENT_LIST Invoke OBJECT->METHOD(ARGUMENT_LIST) while maintaining state for the METHOD's lexical variables. Written in terms of call(), except that it takes OBJECT and METHOD rather than CODEREF. See call() for more details. May have issues with methods invoked via AUTOLOAD, as invoke() uses can() to find the method's CODEREF for call(). =cut sub invoke { my ($self, $object, $method, @args) = @_; return unless defined( my $sub = $object->can($method) ); $self->call($sub, @args); } =head2 wrap CODEREF Wrap a function or anonymous CODEREF so that it's transparently called via call(). Returns a coderef which can be called directly. Named arguments to the call will automatically become available as $arg_name lexicals within the called CODEREF. See call() and push_arg_context() for more details. =cut sub wrap { my ($self, $invocant, $method) = @_; if (ref($invocant) eq 'CODE') { return sub { $self->call($invocant, @_); }; } # FIXME - Experimental method wrapper. # TODO - Make it resolve the method at call time. # TODO - Possibly make it generate dynamic facade classes. return sub { $self->invoke($invocant, $method, @_); }; } =head2 prepare CODE Wrap a CODE string in a subroutine definition, and prepend declarations for all the variables stored in the Lexical::Persistence default context. This avoids having to declare variables explicitly in the code using 'my'. Returns a new code string ready for Perl's built-in eval(). From there, a program may $lp->call() the code or $lp->wrap() it. Also see L, which is a convenient wrapper for prepare() and Perl's built-in eval(). Also see L, which is a convenient way to prepare(), eval() and call() in one step. =cut sub prepare { my ($self, $code) = @_; # Don't worry about values because $self->call() will deal with them my $vars = join( " ", map { "my $_;" } keys %{ $self->get_context('_') } ); # Declare the variables OUTSIDE the actual sub. The compiler will # pull any into the sub that are actually used. Any that aren't will # just get dropped at this point return "$vars sub { $code }"; } =head2 compile CODE compile() is a convenience method to prepare() a CODE string, eval() it, and then return the resulting coderef. If it fails, it returns false, and $@ will explain why. =cut sub compile { my ($self, $code) = @_; return eval($self->prepare($code)); } =head2 do CODE do() is a convenience method to compile() a CODE string and execute it. It returns the result of CODE's execution, or it throws an exception on failure. This example prints the numbers 1 through 10. Note, however, that do() compiles the same code each time. use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); $lp->do('print ++$count, "\\n"') for 1..10; Lexical declarations are preserved across do() invocations, such as with $count in the surrounding examples. This behavior is part of prepare(), which do() uses via compile(). The previous example may be rewritten in terms of compile() and call() to avoid recompiling code every iteration. Lexical declarations are preserved between do() and compile() as well: use Lexical::Persistence; my $lp = Lexical::Persistence->new(); $lp->do('my $count = 0'); my $coderef = $lp->compile('print ++$count, "\\n"'); $lp->call($coderef) for 1..10; do() inherits some limitations from PadWalker's peek_sub(). For instance, it cannot alias lexicals within sub() definitions in the supplied CODE string. However, Lexical::Persistence can do this with careful use of eval() and some custom CODE preparation. =cut sub do { my ($self, $code) = @_; my $sub = $self->compile( $code ) or die $@; $self->call( $sub ); } =head2 parse_variable VARIABLE_NAME This method determines whether VARIABLE_NAME should be persistent. If it should, parse_variable() will return three values: the variable's sigil ('$', '@' or '%'), the context name in which the variable persists (see set_context()), and the name of the member within that context where the value is stored. parse_variable() returns nothing if VARIABLE_NAME should not be persistent. parse_variable() also determines whether the member name includes its sigil. By default, the "arg" context is the only one with members that have no sigils. This is done to support the unadorned argument names used by call(). This method implements a default behavior. It's intended to be overridden or extended by subclasses. =cut sub parse_variable { my ($self, $var) = @_; return unless ( my ($sigil, $context, $member) = ( $var =~ /^([\$\@\%])(?!_)(?:([^_]*)_)?(\S+)/ ) ); if (defined $context) { if (exists $self->{context}{$context}) { return $sigil, $context, $member if $context eq "arg"; return $sigil, $context, "$sigil$member"; } return $sigil, "_", "$sigil$context\_$member"; } return $sigil, "_", "$sigil$member"; } =head2 get_member_ref SIGIL, CONTEXT, MEMBER This method fetches a reference to the named MEMBER of a particular named CONTEXT. The returned value type will be governed by the given SIGIL. Scalar values are stored internally as scalars to be consistent with how most people store scalars. The persistent value is created if it doesn't exist. The initial value is undef or empty, depending on its type. This method implements a default behavior. It's intended to be overridden or extended by subclasses. =cut sub get_member_ref { my ($self, $sigil, $context, $member) = @_; my $hash = $self->{context}{$context}; if ($sigil eq '$') { $hash->{$member} = undef unless exists $hash->{$member}; return \$hash->{$member}; } if ($sigil eq '@') { $hash->{$member} = [ ] unless exists $hash->{$member}; } elsif ($sigil eq '%') { $hash->{$member} = { } unless exists $hash->{$member}; } return $hash->{$member}; } =head2 push_arg_context ARGUMENT_LIST Convert a named ARGUMENT_LIST into members of an argument context, and call set_context() to declare that context. This is how $arg_foo variables are supported. This method returns the previous context, fetched by get_context() before the new context is set. This method implements a default behavior. It's intended to be overridden or extended by subclasses. For example, to redefine the parameters as $param_foo. See pop_arg_context() for the other side of this coin. =cut sub push_arg_context { my $self = shift; my $old_arg_context = $self->get_context("arg"); $self->set_context( arg => { @_ } ); return $old_arg_context; } =head2 pop_arg_context OLD_ARG_CONTEXT Restores OLD_ARG_CONTEXT after a target function has returned. The OLD_ARG_CONTEXT is the return value from the push_arg_context() call just prior to the target function's call. This method implements a default behavior. It's intended to be overridden or extended by subclasses. =cut sub pop_arg_context { my ($self, $old_context) = @_; $self->set_context( arg => $old_context ); } =head1 SEE ALSO L, L, L, L. =head2 BUG TRACKER https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=Lexical-Persistence =head2 REPOSITORY http://github.com/rcaputo/lexical-persistence http://gitorious.org/lexical-persistence =head2 OTHER RESOURCES http://search.cpan.org/dist/Lexical-Persistence/ =head1 COPYRIGHT Lexical::Persistence in copyright 2006-2010 by Rocco Caputo. All rights reserved. Lexical::Persistence is free software. It is released under the same terms as Perl itself. =head1 ACKNOWLEDGEMENTS Thanks to Matt Trout and Yuval Kogman for lots of inspiration. They were the demon and the other demon sitting on my shoulders. Nick Perez convinced me to make this a class rather than persist with the original, functional design. While Higher Order Perl is fun for development, I have to say the move to OO was a good one. Paul "LeoNerd" Evans contributed the compile() and eval() methods. The South Florida Perl Mongers, especially Jeff Bisbee and Marlon Bailey, for documentation feedback. irc://irc.perl.org/poe for support and feedback. =cut 1; Lexical-Persistence-1.022/eg/persistence.perl000644 000765 000024 00000006332 12202157737 021310 0ustar00trocstaff000000 000000 #!/usr/bin/env perl # An OO form of genlex.perl. See Persistence.pm for the magic, or # __END__ for sample output. use warnings; use strict; use Lexical::Persistence; # A handy target to show off persistence and not. sub target { my $arg_number; # Parameter. my $narf_x++; # Persistent. my $_i++; # Dynamic. my $j++; # Persistent. print " target arg_number($arg_number) narf_x($narf_x) _i($_i) j($j)\n"; } ### Create a context, and call something within it. { print "The call() way:\n"; my $persistence = Lexical::Persistence->new(); foreach my $number (qw(one two three four five)) { $persistence->call(\&target, number => $number); } } ### Create a context, and wrap a function call in it. { print "The wrap() way:\n"; my $persistence = Lexical::Persistence->new(); my $thunk = $persistence->wrap(\&target); foreach my $number (qw(one two three four five)) { $thunk->(number => $number); } } =for POE ### Subclass to handle some of POE's function call argument rules. { package PoeLex; our @ISA = qw(Lexical::Persistence); # TODO - Make these lazy so the work isn't done every call? sub push_arg_context { my $self = shift; use POE::Session; my %param = map { $_ - ARG0, $_[$_] } (ARG0..$#_); my $old_arg_context = $self->get_context("arg"); $self->set_context(arg => \%param); # Modify the catch-all context so it contains other arguments. my $catch_all = $self->get_context("_"); @$catch_all{qw($kernel $heap $session $sender)} = @_[ KERNEL, HEAP, SESSION, SENDER ]; return $old_arg_context; } } ### Wrap a POE handler in PoeLex. { print "Using POE:\n"; use POE; spawn(); POE::Kernel->run(); sub spawn { my $persistence = PoeLex->new(); my %heap; $persistence->set_context( heap => \%heap ); POE::Session->create( heap => \%heap, inline_states => { _start => sub { $_[KERNEL]->yield(moo => 0); }, moo => $persistence->wrap(\&handle_moo), }, ); } # Here's a sample handler with persistence. $arg_0 has been aliased # to $_[ARG0]. $heap_foo has been aliased to $_[HEAP]{foo}. sub handle_moo { my $arg_0++; # magic my $heap_foo++; # more magic my ($kernel, $heap); # also magic print " moo: $arg_0 ... heap = $heap_foo ... heap b = $heap->{'$foo'}\n"; $kernel->yield(moo => $arg_0) if $arg_0 < 10; } } =cut exit; __END__ The call() way: target arg_number(one) narf_x(1) _i(1) j(1) target arg_number(two) narf_x(2) _i(1) j(2) target arg_number(three) narf_x(3) _i(1) j(3) target arg_number(four) narf_x(4) _i(1) j(4) target arg_number(five) narf_x(5) _i(1) j(5) The wrap() way: target arg_number(one) narf_x(1) _i(1) j(1) target arg_number(two) narf_x(2) _i(1) j(2) target arg_number(three) narf_x(3) _i(1) j(3) target arg_number(four) narf_x(4) _i(1) j(4) target arg_number(five) narf_x(5) _i(1) j(5) Using POE: moo: 1 ... heap = 1 ... heap b = 1 moo: 2 ... heap = 2 ... heap b = 2 moo: 3 ... heap = 3 ... heap b = 3 moo: 4 ... heap = 4 ... heap b = 4 moo: 5 ... heap = 5 ... heap b = 5 moo: 6 ... heap = 6 ... heap b = 6 moo: 7 ... heap = 7 ... heap b = 7 moo: 8 ... heap = 8 ... heap b = 8 moo: 9 ... heap = 9 ... heap b = 9 moo: 10 ... heap = 10 ... heap b = 10 Lexical-Persistence-1.022/eg/persistence.perl~000600 000765 000024 00000006425 12202157737 021501 0ustar00trocstaff000000 000000 #!/usr/bin/env perl # $Id: persistence.perl 133 2006-11-13 08:25:49Z rcaputo $ # An OO form of genlex.perl. See Persistence.pm for the magic, or # __END__ for sample output. use warnings; use strict; use Lexical::Persistence; # A handy target to show off persistence and not. sub target { my $arg_number; # Parameter. my $narf_x++; # Persistent. my $_i++; # Dynamic. my $j++; # Persistent. print " target arg_number($arg_number) narf_x($narf_x) _i($_i) j($j)\n"; } ### Create a context, and call something within it. { print "The call() way:\n"; my $persistence = Lexical::Persistence->new(); foreach my $number (qw(one two three four five)) { $persistence->call(\&target, number => $number); } } ### Create a context, and wrap a function call in it. { print "The wrap() way:\n"; my $persistence = Lexical::Persistence->new(); my $thunk = $persistence->wrap(\&target); foreach my $number (qw(one two three four five)) { $thunk->(number => $number); } } =for POE ### Subclass to handle some of POE's function call argument rules. { package PoeLex; our @ISA = qw(Lexical::Persistence); # TODO - Make these lazy so the work isn't done every call? sub push_arg_context { my $self = shift; use POE::Session; my %param = map { $_ - ARG0, $_[$_] } (ARG0..$#_); my $old_arg_context = $self->get_context("arg"); $self->set_context(arg => \%param); # Modify the catch-all context so it contains other arguments. my $catch_all = $self->get_context("_"); @$catch_all{qw($kernel $heap $session $sender)} = @_[ KERNEL, HEAP, SESSION, SENDER ]; return $old_arg_context; } } ### Wrap a POE handler in PoeLex. { print "Using POE:\n"; use POE; spawn(); POE::Kernel->run(); sub spawn { my $persistence = PoeLex->new(); my %heap; $persistence->set_context( heap => \%heap ); POE::Session->create( heap => \%heap, inline_states => { _start => sub { $_[KERNEL]->yield(moo => 0); }, moo => $persistence->wrap(\&handle_moo), }, ); } # Here's a sample handler with persistence. $arg_0 has been aliased # to $_[ARG0]. $heap_foo has been aliased to $_[HEAP]{foo}. sub handle_moo { my $arg_0++; # magic my $heap_foo++; # more magic my ($kernel, $heap); # also magic print " moo: $arg_0 ... heap = $heap_foo ... heap b = $heap->{'$foo'}\n"; $kernel->yield(moo => $arg_0) if $arg_0 < 10; } } =cut exit; __END__ The call() way: target arg_number(one) narf_x(1) _i(1) j(1) target arg_number(two) narf_x(2) _i(1) j(2) target arg_number(three) narf_x(3) _i(1) j(3) target arg_number(four) narf_x(4) _i(1) j(4) target arg_number(five) narf_x(5) _i(1) j(5) The wrap() way: target arg_number(one) narf_x(1) _i(1) j(1) target arg_number(two) narf_x(2) _i(1) j(2) target arg_number(three) narf_x(3) _i(1) j(3) target arg_number(four) narf_x(4) _i(1) j(4) target arg_number(five) narf_x(5) _i(1) j(5) Using POE: moo: 1 ... heap = 1 ... heap b = 1 moo: 2 ... heap = 2 ... heap b = 2 moo: 3 ... heap = 3 ... heap b = 3 moo: 4 ... heap = 4 ... heap b = 4 moo: 5 ... heap = 5 ... heap b = 5 moo: 6 ... heap = 6 ... heap b = 6 moo: 7 ... heap = 7 ... heap b = 7 moo: 8 ... heap = 8 ... heap b = 8 moo: 9 ... heap = 9 ... heap b = 9 moo: 10 ... heap = 10 ... heap b = 10 Lexical-Persistence-1.022/eg/repl-mst.perl000644 000765 000024 00000002123 12202157737 020521 0ustar00trocstaff000000 000000 #!/usr/bin/env perl # A brief REPL (read/eval/print loop) by Matt S. Trout. use strict; use warnings; use Term::ReadLine; use Lexical::Persistence; my $term = new Term::ReadLine 'Perl REPL'; my $prompt = '$ '; my $OUT = $term->OUT || \*STDOUT; my $lp = Lexical::Persistence->new(); while ( defined (my $line = $term->readline($prompt)) ) { print "\n", next unless $line =~ /\S/; # Re-declare all the lexicals we've previously seen. Lexicals # accumulate in the "_" context from one call to the next. my $sub = eval( qq!sub { \n!. join('', map { "my $_;\n" } keys %{$lp->get_context('_')}). ${line}.qq!\n}\n! ); my @res; if ($@) { warn "Compile error: $@"; } else { @res = eval { $lp->call($sub); }; warn "Runtime error: $@" if $@; } print $OUT "@res" unless $@; $term->addhistory($line); } __END__ 1) poerbook:~/projects/lex-per/eg% perl repl-mst.perl $ my $x = "declared and initialized in eval #1"; declared and initialized in eval #1 $ "evaluated in eval #2: $x"; evaluated in eval #2: declared and initialized in eval #1 $ exit 1) poerbook:~/projects/lex-per/eg% Lexical-Persistence-1.022/eg/repl-mst.perl~000600 000765 000024 00000002132 12202157737 020707 0ustar00trocstaff000000 000000 #!/usr/bin/env perl # $Id$ # A brief REPL (read/eval/print loop) by Matt S. Trout. use strict; use warnings; use Term::ReadLine; use Lexical::Persistence; my $term = new Term::ReadLine 'Perl REPL'; my $prompt = '$ '; my $OUT = $term->OUT || \*STDOUT; my $lp = Lexical::Persistence->new(); while ( defined (my $line = $term->readline($prompt)) ) { print "\n", next unless $line =~ /\S/; # Re-declare all the lexicals we've previously seen. Lexicals # accumulate in the "_" context from one call to the next. my $sub = eval( qq!sub { \n!. join('', map { "my $_;\n" } keys %{$lp->get_context('_')}). ${line}.qq!\n}\n! ); my @res; if ($@) { warn "Compile error: $@"; } else { @res = eval { $lp->call($sub); }; warn "Runtime error: $@" if $@; } print $OUT "@res" unless $@; $term->addhistory($line); } __END__ 1) poerbook:~/projects/lex-per/eg% perl repl-mst.perl $ my $x = "declared and initialized in eval #1"; declared and initialized in eval #1 $ "evaluated in eval #2: $x"; evaluated in eval #2: declared and initialized in eval #1 $ exit 1) poerbook:~/projects/lex-per/eg%