[Rt-commit] r5606 - in Scalar-Defer: . t

audreyt at bestpractical.com audreyt at bestpractical.com
Wed Jul 19 12:03:57 EDT 2006


Author: audreyt
Date: Wed Jul 19 12:03:54 2006
New Revision: 5606

Modified:
   Scalar-Defer/Changes
   Scalar-Defer/lib/Scalar/Defer.pm
   Scalar-Defer/t/01-basic.t

Log:
* This be 0.04.
* Document the ->force method for getting a normal value out of a
  deferred value.
  Requested by: Nathan Gray

Modified: Scalar-Defer/Changes
==============================================================================
--- Scalar-Defer/Changes	(original)
+++ Scalar-Defer/Changes	Wed Jul 19 12:03:54 2006
@@ -1,3 +1,9 @@
+[Changes for 0.04 - 2006-07-19]
+
+* Document the ->force method for getting a normal value out of a
+  deferred value.
+  Requested by: Nathan Gray
+
 [Changes for 0.03 - 2006-07-17]
 
 * Documentation cleanup; no functional changes.

Modified: Scalar-Defer/lib/Scalar/Defer.pm
==============================================================================
--- Scalar-Defer/lib/Scalar/Defer.pm	(original)
+++ Scalar-Defer/lib/Scalar/Defer.pm	Wed Jul 19 12:03:54 2006
@@ -1,5 +1,5 @@
 package Scalar::Defer;
-$Scalar::Defer::VERSION = '0.03';
+$Scalar::Defer::VERSION = '0.04';
 
 use 5.006;
 use strict;
@@ -14,7 +14,7 @@
     $_ => \&force
 } qw( bool "" 0+ ${} @{} %{} &{} *{} );
 
-sub force (&) {
+sub force ($) {
     &{$_defer{ id $_[0] }}
 }
 
@@ -48,12 +48,16 @@
     use Scalar::Defer; # exports 'defer' and 'lazy'
 
     my ($x, $y);
-    my $dv = defer { ++$x };    # a defer-value (not memoized)
-    my $lv = lazy { ++$y };     # a lazy-value (memoized)
+    my $dv = defer { ++$x };    # a deferred value (not memoized)
+    my $lv = lazy { ++$y };     # a lazy value (memoized)
 
     print "$dv $dv $dv"; # 1 2 3
     print "$lv $lv $lv"; # 1 1 1
 
+    my $forced = $dv->force;    # force a normal value out of $dv
+
+    print "$forced $forced $forced"; # 4 4 4
+
 =head1 DESCRIPTION
 
 This module exports two functions, C<defer> and C<lazy>, for building
@@ -61,7 +65,7 @@
 
 =head2 defer {...}
 
-Takes a block or a code reference, and returns an overloaded value.
+Takes a block or a code reference, and returns a deferred value.
 Each time that value is demanded, the block is evaluated again to
 yield a fresh result.
 
@@ -70,6 +74,10 @@
 Like C<defer>, except the value is computed at most once.  Subsequent
 evaluation will simply use the cached result.
 
+=head2 $value->force
+
+Force calculation of a deferred/lazy value and return a normal value.
+
 =head1 NOTES
 
 Unlike the C<tie>-based L<Data::Lazy>, this module operates on I<values>,

Modified: Scalar-Defer/t/01-basic.t
==============================================================================
--- Scalar-Defer/t/01-basic.t	(original)
+++ Scalar-Defer/t/01-basic.t	Wed Jul 19 12:03:54 2006
@@ -1,4 +1,4 @@
-use Test::More tests => 5;
+use Test::More tests => 7;
 use ok 'Scalar::Defer';
 
 my ($x, $y);
@@ -9,3 +9,7 @@
 is($d, 2, "defer is now 2");
 is($l, 1, "but lazy stays at 1");
 isnt($d, $l, "3 != 1");
+
+my $forced = $d->force;
+is($forced, 4, "->force works");
+is($forced, 4, "->force is stable");


More information about the Rt-commit mailing list