Changeset 13038
- Timestamp:
- 06/02/08 02:09:59 (5 years ago)
- Location:
- lang/perl/Scalar-Lazy/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Scalar-Lazy/trunk/Changes
r13037 r13038 2 2 # Revision history for Scalar-Lazy 3 3 # 4 # $Id: Changes,v 0. 2 2008/06/01 16:29:17 dankogai Exp$4 # $Id: Changes,v 0.3 2008/06/01 17:09:08 dankogai Exp dankogai $ 5 5 # 6 $Revision: 0.2 $ $Date: 2008/06/01 16:29:17 $ 6 $Revision: 0.3 $ $Date: 2008/06/01 17:09:08 $ 7 + t/04-once.t 8 ! lib/Scalar/Lazy.pm 9 Added 'once' option. 10 11 0.02 2008/06/01 16:29:17 7 12 ! lib/Scalar/Lazy.pm 8 13 POD fixes. -
lang/perl/Scalar-Lazy/trunk/MANIFEST
r13033 r13038 8 8 t/02-combinator.t 9 9 t/03-tarai.t 10 t/04-once.t 10 11 t/pod-coverage.t 11 12 t/pod.t -
lang/perl/Scalar-Lazy/trunk/README
r13037 r13038 3 3 4 4 VERSION 5 $Id: README,v 0. 2 2008/06/01 16:29:34dankogai Exp dankogai $5 $Id: README,v 0.3 2008/06/01 17:09:08 dankogai Exp dankogai $ 6 6 7 7 SYNOPSIS … … 51 51 There are various CPAN modules that does what this does. But I found 52 52 others too complicated. Hey, the whole code is only 25 lines long! 53 Nicely fits in a good-old terminal screen.53 (Well, was until 0.03) Nicely fits in a good-old terminal screen. 54 54 55 55 The closest module is Scalar::Defer, a brainchild of Audrey Tang. But I … … 72 72 73 73 Scalar::Lazy->new(sub { value }); 74 75 You can optionally set the second parameter. If set, the value becomes 76 constant. The folloing example illustrates the difference. 77 78 my $x = 0; 79 my $once = lazy { ++$x } 'init'; # $once is always 1 80 is $once, 1, 'once'; 81 is $once, 1, 'once'; 82 my $succ = lazy { ++$x }; # $succ always increments $x 83 isnt $succ, 1, 'succ'; 84 is $succ, 3, 'succ'; 74 85 75 86 delay -
lang/perl/Scalar-Lazy/trunk/lib/Scalar/Lazy.pm
r13037 r13038 2 2 use warnings; 3 3 use strict; 4 our $VERSION = sprintf "%d.%02d", q$Revision: 0. 2$ =~ /(\d+)/g;4 our $VERSION = sprintf "%d.%02d", q$Revision: 0.3 $ =~ /(\d+)/g; 5 5 use base 'Exporter'; 6 6 our @EXPORT = qw/ delay lazy /; 7 7 8 sub new($&) { bless $_[1], $_[0] } 9 sub lazy(&) { __PACKAGE__->new(@_) } 8 sub new($&;$) { 9 my ($pkg, $code, $init) = @_; 10 if ($init){ 11 my $val = $code->(); 12 $code = sub { $val }; 13 } 14 bless $code, $pkg; 15 } 16 17 sub lazy(&;$) { __PACKAGE__->new(@_) } 10 18 *delay = \&lazy; 11 19 … … 31 39 =head1 VERSION 32 40 33 $Id: Lazy.pm,v 0. 2 2008/06/01 16:29:17dankogai Exp dankogai $41 $Id: Lazy.pm,v 0.3 2008/06/01 17:09:08 dankogai Exp dankogai $ 34 42 35 43 =head1 SYNOPSIS … … 81 89 There are various CPAN modules that does what this does. But I found 82 90 others too complicated. Hey, the whole code is only 25 lines long! 83 Nicely fits in a good-old terminal screen.91 (Well, was until 0.03) Nicely fits in a good-old terminal screen. 84 92 85 93 The closest module is L<Scalar::Defer>, a brainchild of Audrey Tang. … … 105 113 106 114 Scalar::Lazy->new(sub { value }); 115 116 You can optionally set the second parameter. If set, the value 117 becomes constant. The folloing example illustrates the difference. 118 119 my $x = 0; 120 my $once = lazy { ++$x } 'init'; # $once is always 1 121 is $once, 1, 'once'; 122 is $once, 1, 'once'; 123 my $succ = lazy { ++$x }; # $succ always increments $x 124 isnt $succ, 1, 'succ'; 125 is $succ, 3, 'succ'; 107 126 108 127 =head2 delay
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)