]> git.vpit.fr Git - perl/modules/Variable-Temp.git/commitdiff
Test applying temp() to lvalue subs
authorVincent Pit <vince@profvince.com>
Mon, 9 Mar 2015 17:24:20 +0000 (14:24 -0300)
committerVincent Pit <vince@profvince.com>
Mon, 9 Mar 2015 17:24:20 +0000 (14:24 -0300)
MANIFEST
t/15-lvalue-sub.t [new file with mode: 0644]

index d6d63d8dc1ff625694a0df4f1277728b0dbe26a2..76041cc8701d4af2a9cf7fede80cd000a4bd61f2 100644 (file)
--- 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 (file)
index 0000000..baae5e4
--- /dev/null
@@ -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);