From: Vincent Pit Date: Mon, 9 Mar 2015 17:24:20 +0000 (-0300) Subject: Test applying temp() to lvalue subs X-Git-Tag: v0.02~17 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Temp.git;a=commitdiff_plain;h=73d40783bd6b96e04e453f3cba0e8ada8ed06528 Test applying temp() to lvalue subs --- diff --git a/MANIFEST b/MANIFEST index d6d63d8..76041cc 100644 --- a/MANIFEST +++ b/MANIFEST @@ -11,4 +11,5 @@ t/10-lexical.t t/11-global.t t/12-destroy.t t/13-magic.t +t/15-lvalue-sub.t t/lib/VPIT/TestHelpers.pm diff --git a/t/15-lvalue-sub.t b/t/15-lvalue-sub.t new file mode 100644 index 0000000..baae5e4 --- /dev/null +++ b/t/15-lvalue-sub.t @@ -0,0 +1,61 @@ +#!perl + +use strict; +use warnings; + +use Variable::Temp 'temp'; + +use Test::More tests => 10; + +{ + package Variable::Temp::TestPkg; + + sub new { + my ($class, $val) = @_; + + bless { value => $val }, $class; + } + + sub value :lvalue { + $_[0]->{value} + } + + sub is_value { + my ($self, $expected, $desc) = @_; + ::is($self->{value}, $expected, $desc); + } +} + +my $x = Variable::Temp::TestPkg->new(1); +$x->is_value(1); + +{ + temp $x->value = 2; + $x->is_value(2); +} + +$x->is_value(1); + +{ + temp $x->value = 3; + $x->is_value(3); + + temp $x->value = 4; + $x->is_value(4); +} + +$x->is_value(1); + +{ + temp $x->value = 5; + $x->is_value(5); + + { + temp $x->value = 6; + $x->is_value(6); + } + + $x->is_value(5); +} + +$x->is_value(1);