use Config qw<%Config>;
-use Test::More tests => (2 * 14 + 2) + 2 * (2 * 8 + 4) + 3 + 1;
+use Test::More tests => (2 * 14 + 2) + 2 * (2 * 8 + 4) + 5 + 1;
use Variable::Magic qw<wizard cast dispell>;
$b = watch { \$a } { }, 'reference';
-watch { $a = 123; () } { set => 1 }, 'assign to';
+watch { $a = 123 } { set => 1 }, 'assign to';
-watch { ++$a; () } { get => 1, set => 1 }, 'increment';
+watch { ++$a } { get => 1, set => 1 }, 'increment';
-watch { --$a; () } { get => 1, set => 1 }, 'decrement';
+watch { --$a } { get => 1, set => 1 }, 'decrement';
-watch { $a *= 1.5; () } { get => 1, set => 1 }, 'multiply in place';
+watch { $a *= 1.5 } { get => 1, set => 1 }, 'multiply in place';
-watch { $a /= 1.5; () } { get => 1, set => 1 }, 'divide in place';
+watch { $a /= 1.5 } { get => 1, set => 1 }, 'divide in place';
watch {
my $b = $n;
watch { cast $a[1], $wiz } { }, 'array element: cast';
-watch { $a[1] = 6; () } { set => 1 }, 'array element: set';
+watch { $a[1] = 6 } { set => 1 }, 'array element: set';
$b = watch { $a[1] } { get => ($is_5130_release ? 2 : 1) },'array element: get';
is $b, 6, 'scalar: array element: get correctly';
watch { cast $h{b}, $wiz } { }, 'hash element: cast';
-watch { $h{b} = 6; () } { set => 1 }, 'hash element: set';
+watch { $h{b} = 6 } { set => 1 }, 'hash element: set';
$b = watch { $h{b} } { get => ($is_5130_release ? 2 : 1) }, 'hash element: get';
is $b, 6, 'scalar: hash element: get correctly';
SKIP: {
unless (do { local $@; eval { require Tie::Array; 1 } }) {
- skip 'Tie::Array required to test clear magic on tied array values' => 3;
+ skip 'Tie::Array required to test clear magic on tied array values' => 5;
}
defined and diag "Using Tie::Array $_" for $Tie::Array::VERSION;
tie my @a, 'Tie::StdArray';
$a[0] = $$;
+ $a[1] = -$$;
eval {
cast @a, wizard copy => sub { cast $_[3], $wiz; () };
};
is $@, '', 'cast copy magic on tied array';
- watch { delete $a[0] } [ qw<get clear free> ], 'delete from tied array';
+ watch { delete $a[0] } [ qw<clear free> ],
+ 'delete from tied array in void context';
+
+ $b = watch { delete $a[1] } [ qw<get clear free> ],
+ 'delete from tied array in scalar context';
}
watch { $b = $#a } { len => 1 }, 'length $#';
is $b, 2, 'array: length $# correctly';
-watch { push @a, 'x'; () }
+watch { push @a, 'x'; () } # push looks at the static context
{ set => 1, (len => 1) x !VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID },
'push (void)';
$b = watch { pop @a } { set => 1, len => 1 }, 'pop';
is $b, 'y', 'array: pop correctly';
-watch { unshift @a, 'z'; () }
+watch { unshift @a, 'z'; () } # unshift looks at the static context
{ set => 1, (len => 1) x !VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID },
'unshift (void)';
$b = watch { shift @a } { set => 1, len => 1 }, 'shift';
is $b, 't', 'array: shift correctly';
-watch { my $i; @a = map ++$i, @a; () } { set => 5, len => 1, clear => 1}, 'map';
+watch { my $i; @a = map ++$i, @a } { set => 5, len => 1, clear => 1}, 'map';
@b = watch { grep { $_ >= 4 } @a } { len => 1 }, 'grep';
is_deeply \@b, [ 4 .. 5 ], 'array: grep correctly';
use strict;
use warnings;
-use Test::More tests => (2 * 21 + 7) + (2 * 5 + 5) + 1;
+use Test::More tests => (2 * 22 + 7) + (2 * 5 + 5) + 1;
use Variable::Magic qw<cast dispell VMG_UVAR>;
watch { %h = () } { clear => 1 }, 'empty in list context';
-watch { %h = (a => 1, d => 3); () }
+watch { %h = (a => 1, d => 3) }
+{ (store => 2, copy => 2) x VMG_UVAR, clear => 1 },
'assign from list in void context';
+@b = watch { %h = (a => 1, d => 3) }
+ +{ (exists => 2, store => 2, copy => 2) x VMG_UVAR, clear => 1 },
+ 'assign from list in void context';
+
watch { %h = map { $_ => 1 } qw<a b d>; }
- +{ (exists => 3, store => 3, copy => 3) x VMG_UVAR, clear => 1 },
- 'assign from map in list context';
+ +{ (store => 3, copy => 3) x VMG_UVAR, clear => 1 },
+ 'assign from map in void context';
-watch { $h{d} = 2; () } +{ (store => 1) x VMG_UVAR },
+watch { $h{d} = 2 } +{ (store => 1) x VMG_UVAR },
'assign old element';
-watch { $h{c} = 3; () } +{ (store => 1, copy => 1) x VMG_UVAR },
+watch { $h{c} = 3 } +{ (store => 1, copy => 1) x VMG_UVAR },
'assign new element';
$s = watch { %h } { }, 'buckets';
BEGIN {
local $@;
if (eval "use Symbol qw<gensym>; 1") {
- plan tests => 2 * 12 + 1;
+ plan tests => 2 * 17 + 1;
defined and diag "Using Symbol $_" for $Symbol::VERSION;
} else {
plan skip_all => "Symbol::gensym required for testing magic for globs";
watch { local *b = *a } +{ %get }, 'assign to';
-watch { *a = \1 } +{ %get, set => 1 }, 'assign scalar slot';
-watch { *a = [ qw<x y> ] } +{ %get, set => 1 }, 'assign array slot';
-watch { *a = { u => 1 } } +{ %get, set => 1 }, 'assign hash slot';
-watch { *a = sub { } } +{ %get, set => 1 }, 'assign code slot';
+SKIP: {
+ skip 'This failed temporarily between perls 5.13.1 and 5.13.8 (included)'
+ => 5 * 2 if "$]" >= 5.013_001 and "$]" <= 5.013_008;
-watch { *a = gensym() } +{ %get, set => 1 }, 'assign glob';
+ my $cxt = 'void contex';
+ my $exp = { set => 1 };
+
+ watch { *a = \1 } $exp, "assign scalar slot in $cxt";
+ watch { *a = [ qw<x y> ] } $exp, "assign array slot in $cxt";
+ watch { *a = { u => 1 } } $exp, "assign hash slot in $cxt";
+ watch { *a = sub { } } $exp, "assign code slot in $cxt";
+ watch { *a = gensym() } $exp, "assign glob in $cxt";
+}
+
+{
+ my $cxt = 'scalar context';
+ my $exp = { %get, set => 1 };
+ my $v;
+
+ $v = watch { *a = \1 } $exp, "assign scalar slot in $cxt";
+ $v = watch { *a = [ qw<x y> ] } $exp, "assign array slot in $cxt";
+ $v = watch { *a = { u => 1 } } $exp, "assign hash slot in $cxt";
+ $v = watch { *a = sub { } } $exp, "assign code slot in $cxt";
+ $v = watch { *a = gensym() } $exp, "assign glob in $cxt";
+}
watch {
local *b = gensym();
my @ret;
local %mg = ();
local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1;
- if (defined $want and not $want) { # scalar context
+ local $@;
+ if (not defined $want) { # void context
+ eval { $code->() };
+ } elsif (not $want) { # scalar context
$ret[0] = eval { $code->() };
} else {
@ret = eval { $code->() };