r26799 - in /trunk/liblexical-persistence-perl: CHANGES MANIFEST META.yml README debian/changelog lib/Lexical/Persistence.pm t/04_eval.t

ghostbar-guest at users.alioth.debian.org ghostbar-guest at users.alioth.debian.org
Thu Nov 13 06:39:43 UTC 2008


Author: ghostbar-guest
Date: Thu Nov 13 06:39:39 2008
New Revision: 26799

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=26799
Log:
new upstream release

Added:
    trunk/liblexical-persistence-perl/t/04_eval.t
      - copied unchanged from r26798, branches/upstream/liblexical-persistence-perl/current/t/04_eval.t
Modified:
    trunk/liblexical-persistence-perl/CHANGES
    trunk/liblexical-persistence-perl/MANIFEST
    trunk/liblexical-persistence-perl/META.yml
    trunk/liblexical-persistence-perl/README
    trunk/liblexical-persistence-perl/debian/changelog
    trunk/liblexical-persistence-perl/lib/Lexical/Persistence.pm

Modified: trunk/liblexical-persistence-perl/CHANGES
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblexical-persistence-perl/CHANGES?rev=26799&op=diff
==============================================================================
--- trunk/liblexical-persistence-perl/CHANGES (original)
+++ trunk/liblexical-persistence-perl/CHANGES Thu Nov 13 06:39:39 2008
@@ -1,64 +1,29 @@
-=========================
-2007-03-18 19:27:56 v0_97
-=========================
+=================================
+2008-11-07T18:12:14.808090Z v0_98
+=================================
 
-  2007-03-18 19:27:04 (r12) by rcaputo; lib/Lexical/Persistence.pm M
+  2008-11-07 18:11:57 (r18) by rcaputo; lib/Lexical/Persistence.pm M
 
-    Bump up the version.
+    Ready for 0.98
 
-  2007-03-18 19:25:29 (r11) by rcaputo; eg/repl-mst.perl A; MANIFEST M
+  2008-11-07 04:36:12 (r17) by rcaputo; lib/Lexical/Persistence.pm M
 
-    Add a small sample REPL (read/eval/print loop) by Matt S. Trout. 
+    Replace eval() with do() in the docs. Note that lexical declarations
+    are preserved by compile(), which is used by do(), so declared
+    variables need not be redeclared all the time.
 
-  2006-11-20 04:23:59 (r10) by rcaputo
-  lib/Lexical/Persistence.pm M; t/01_basics.t M
+  2008-11-03 20:02:16 (r16) by rcaputo; t/04_eval.t M
 
-    Add invoke() for invoking methods. Its use is similar to call(), and
-    in fact it's implemented in terms of that method. 
+    Fix tests to use do() rather than eval().
 
-  2006-11-17 06:29:03 (r9) by rcaputo; README D; Makefile.PL M
+  2008-11-03 19:57:55 (r15) by rcaputo; lib/Lexical/Persistence.pm M
 
-    Automatically generate the README from perldoc at dist time. 
+    Another attempt at eval(), this time called do().
 
-=========================
-2006-11-17 06:22:05 v0_96
-=========================
+  2008-11-01 05:38:30 (r14) by rcaputo
+  t/04_eval.t A; MANIFEST M; lib/Lexical/Persistence.pm M
 
-  2006-11-17 06:20:51 (r7) by rcaputo; eg/persistence.perl M
-
-    Fix based on changes in the module and feedback from Jeff Bisbee and
-    Marlon Bailey. 
-
-  2006-11-17 06:12:07 (r6) by rcaputo
-  README M; lib/Lexical/Persistence.pm M
-
-    Doc rewrite. parse_variable() takes on the responsibility of deciding
-    whether a context member requires a sigil. 
-
-=========================
-2006-11-14 08:29:15 v0_95
-=========================
-
-  2006-11-14 08:28:37 (r4) by rcaputo; lib/Lexical/Persistence.pm M
-
-    Back down the version number for the initial release, in case there
-    are distro problems to address. 
-
-  2006-11-14 08:26:51 (r3) by rcaputo; MANIFEST M
-
-    Add the tests. D'oh! 
-
-  2006-11-14 08:25:55 (r2) by rcaputo
-  t/03_pod_coverage.t A; t/02_pod.t A
-
-    Add POD tests. Yay, kwalitee! 
-
-  2006-11-14 08:18:15 (r1) by rcaputo
-  README A; /trunk A; eg/persistence.perl A; /branches A; t A; lib A;
-  MANIFEST A; lib/Lexical/Persistence.pm A; lib/Lexical A; Makefile.PL A;
-  t/01_basics.t A; /tags A; eg A
-
-    Initial project setup. 
+    Apply Paul "LeoNerd" Evans' patch to add compile() and eval(). 
 
 ==============
 End of Excerpt

Modified: trunk/liblexical-persistence-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblexical-persistence-perl/MANIFEST?rev=26799&op=diff
==============================================================================
--- trunk/liblexical-persistence-perl/MANIFEST (original)
+++ trunk/liblexical-persistence-perl/MANIFEST Thu Nov 13 06:39:39 2008
@@ -9,3 +9,4 @@
 t/01_basics.t
 t/02_pod.t
 t/03_pod_coverage.t
+t/04_eval.t

Modified: trunk/liblexical-persistence-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblexical-persistence-perl/META.yml?rev=26799&op=diff
==============================================================================
--- trunk/liblexical-persistence-perl/META.yml (original)
+++ trunk/liblexical-persistence-perl/META.yml Thu Nov 13 06:39:39 2008
@@ -1,15 +1,15 @@
 --- #YAML:1.0
 name:                Lexical-Persistence
-version:             0.97
+version:             0.98
 abstract:            Persistent, continuation-like contexts for lexical variables.
 license:             perl
-generated_by:        ExtUtils::MakeMaker version 6.31
+author:              
+    - Rocco Caputo <rcaputo at cpan.org>
+generated_by:        ExtUtils::MakeMaker version 6.44
 distribution_type:   module
 requires:     
     Devel::LexAlias:               0.04
     PadWalker:                     1.1
 meta-spec:
-    url:     http://module-build.sourceforge.net/META-spec-v1.2.html
-    version: 1.2
-author:
-    - Rocco Caputo <rcaputo at cpan.org>
+    url:     http://module-build.sourceforge.net/META-spec-v1.3.html
+    version: 1.3

Modified: trunk/liblexical-persistence-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblexical-persistence-perl/README?rev=26799&op=diff
==============================================================================
--- trunk/liblexical-persistence-perl/README (original)
+++ trunk/liblexical-persistence-perl/README Thu Nov 13 06:39:39 2008
@@ -198,6 +198,22 @@
                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.
 
        nneeww
@@ -273,6 +289,62 @@
 
        See _c_a_l_l_(_) and _p_u_s_h___a_r_g___c_o_n_t_e_x_t_(_) for more details.
 
+       pprreeppaarree CCOODDEE
+
+       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
+       _e_v_a_l_(_).  From there, a program may $lp−>_c_a_l_l_(_) the code or $lp−>_w_r_a_p_(_)
+       it.
+
+       Also see "_c_o_m_p_i_l_e_(_)", which is a convenient wrapper for _p_r_e_p_a_r_e_(_) and
+       Perl’s built‐in _e_v_a_l_(_).
+
+       Also see "_d_o_(_)", which is a convenient way to _p_r_e_p_a_r_e_(_), _e_v_a_l_(_) and
+       _c_a_l_l_(_) in one step.
+
+       ccoommppiillee CCOODDEE
+
+       _c_o_m_p_i_l_e_(_) is a convenience method to _p_r_e_p_a_r_e_(_) a CODE string, _e_v_a_l_(_)
+       it, and then return the resulting coderef.  If it fails, it returns
+       false, and $@ will explain why.
+
+       ddoo CCOODDEE
+
+       _d_o_(_) is a convenience method to _c_o_m_p_i_l_e_(_) 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 _d_o_(_)
+       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 _d_o_(_) invocations, such as
+       with $count in the surrounding examples.  This behavior is part of
+       _p_r_e_p_a_r_e_(_), which _d_o_(_) uses via _c_o_m_p_i_l_e_(_).
+
+       The previous example may be rewritten in terms of _c_o_m_p_i_l_e_(_) and _c_a_l_l_(_)
+       to avoid recompiling code every iteration.  Lexical declarations are
+       preserved between _d_o_(_) and _c_o_m_p_i_l_e_(_) 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;
+
+       _d_o_(_) inherits some limitations from PadWalker’s _p_e_e_k___s_u_b_(_).  For
+       instance, it cannot alias lexicals within _s_u_b_(_) definitions in the
+       supplied CODE string.  However, Lexical::Persistence can do this with
+       careful use of _e_v_a_l_(_) and some custom CODE preparation.
+
        ppaarrssee__vvaarriiaabbllee VVAARRIIAABBLLEE__NNAAMMEE
 
        This method determines whether VARIABLE_NAME should be persistent.  If
@@ -350,6 +422,8 @@
        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 _c_o_m_p_i_l_e_(_) and _e_v_a_l_(_) methods.
+
        The South Florida Perl Mongers, especially Jeff Bisbee and Marlon
        Bailey, for documentation feedback.
 
@@ -357,4 +431,4 @@
 
 
 
-perl v5.8.8                       2007‐03‐18           Lexical::Persistence(3)
+perl v5.8.8                       2008‐11‐07           Lexical::Persistence(3)

Modified: trunk/liblexical-persistence-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblexical-persistence-perl/debian/changelog?rev=26799&op=diff
==============================================================================
--- trunk/liblexical-persistence-perl/debian/changelog (original)
+++ trunk/liblexical-persistence-perl/debian/changelog Thu Nov 13 06:39:39 2008
@@ -1,3 +1,9 @@
+liblexical-persistence-perl (0.98-1) UNRELEASED; urgency=low
+
+  * (NOT RELEASED YET) New upstream release
+
+ -- Jose Luis Rivas <ghostbar38 at gmail.com>  Thu, 13 Nov 2008 02:08:47 -0430
+
 liblexical-persistence-perl (0.97-2) unstable; urgency=low
 
   * debian/control: Added: Vcs-Svn field (source stanza); Vcs-Browser field

Modified: trunk/liblexical-persistence-perl/lib/Lexical/Persistence.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/liblexical-persistence-perl/lib/Lexical/Persistence.pm?rev=26799&op=diff
==============================================================================
--- trunk/liblexical-persistence-perl/lib/Lexical/Persistence.pm (original)
+++ trunk/liblexical-persistence-perl/lib/Lexical/Persistence.pm Thu Nov 13 06:39:39 2008
@@ -1,4 +1,4 @@
-# $Id: Persistence.pm 12 2007-03-18 19:27:04Z rcaputo $
+# $Id: Persistence.pm 18 2008-11-07 18:11:57Z rcaputo $
 
 =head1 NAME
 
@@ -198,6 +198,21 @@
 	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
@@ -207,7 +222,7 @@
 use warnings;
 use strict;
 
-our $VERSION = '0.97';
+our $VERSION = '0.98';
 
 use Devel::LexAlias qw(lexalias);
 use PadWalker qw(peek_sub);
@@ -381,6 +396,95 @@
 	};
 }
 
+=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</compile()>, which is a convenient wrapper for prepare()
+and Perl's built-in eval().
+
+Also see L</do()>, 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
@@ -523,6 +627,8 @@
 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.
 




More information about the Pkg-perl-cvs-commits mailing list