Memoize-Once
view release on metacpan or search on metacpan
our($b, @b);
is $b, undef;
for(my $i = 0; $i != 0; $i++) {
push @b, [ $i, once(10 + ++$b) ];
}
is $b, undef;
is_deeply \@b, [];
our $c;
BEGIN { $c = 1; }
sub cc() { once($c) }
$c = 2;
is cc(), 2;
$c = 3;
is cc(), 2;
1;
t/exception.t view on Meta::CPAN
use warnings;
use strict;
use Test::More tests => 14;
BEGIN { use_ok "Memoize::Once", qw(once); }
our($a, $i);
sub aa() { once(do { $i++; die "wibble" if $i < 3; $a }) }
is $i, undef;
$a = 11;
is eval { aa() }, undef;
like $@, qr/\Awibble/;
is $i, 1;
$a = 22;
is eval { aa() }, undef;
like $@, qr/\Awibble/;
t/hint_in.t view on Meta::CPAN
use warnings;
use strict;
package Foo;
use Test::More tests => 3;
BEGIN { use_ok "Memoize::Once", qw(once); }
sub cc() { once(__PACKAGE__) }
is cc(), "Foo";
is cc(), "Foo";
1;
use warnings;
use strict;
use Test::More tests => 4;
BEGIN { use_ok "Memoize::Once", qw(once); }
sub cc($) {
my($v) = @_;
my $z = once($v);
$v = undef;
return $z;
}
is cc(2), 2;
is cc(3), 2;
is cc(4), 2;
1;
use warnings;
use strict;
use Test::More tests => 10;
BEGIN { use_ok "Memoize::Once", qw(once); }
our($a, $i);
BEGIN { $a = 2; }
sub aa() { [ "x", once(($i++, $a)), "y" ] }
is $i, undef;
is_deeply aa(), [ "x", 2, "y" ];
is $i, 1;
$a = 3;
is_deeply aa(), [ "x", 2, "y" ];
is $i, 1;
sub bb() { no warnings "void"; [ "x", once((11, 12)), "y" ] }
is_deeply bb(), [ "x", 12, "y" ];
is_deeply bb(), [ "x", 12, "y" ];
sub cc() { [ "x", once(()), "y" ] }
is_deeply cc(), [ "x", undef, "y" ];
is_deeply cc(), [ "x", undef, "y" ];
1;
t/precedence.t view on Meta::CPAN
use warnings;
use strict;
use Test::More tests => 9;
BEGIN { use_ok "Memoize::Once", qw(once); }
our($a, $b);
BEGIN { $a = 20; $b = 1; }
sub aa() { once($a) + $b }
sub bb() { once $a + $b }
sub cc() { once($a) | $b }
sub dd() { once $a | $b }
is aa(), 21;
is bb(), 21;
is cc(), 21;
is dd(), 21;
$a = 40; $b = 2;
is aa(), 22;
is bb(), 21;
is cc(), 22;
is dd(), 22;
use warnings;
use strict;
use Test::More tests => 6;
BEGIN { use_ok "Memoize::Once", qw(once); }
our($a, $i);
BEGIN { $a = 1; }
sub aa() { once(do { $i++; $a }) }
is $i, undef;
$a = undef;
is aa(), undef;
is $i, 1;
$a = 3;
is aa(), undef;
is $i, 1;
1;
( run in 1.420 second using v1.01-cache-2.11-cpan-524268b4103 )