diff --git a/lib/Template/Stash.pm b/lib/Template/Stash.pm index f5fd7956..8b98d55c 100644 --- a/lib/Template/Stash.pm +++ b/lib/Template/Stash.pm @@ -456,7 +456,7 @@ sub _dotop { } # ugly hack: only allow import vmeth to be called on root stash elsif (($value = $HASH_OPS->{ $item }) - && ! $atroot || $item eq 'import') { + && (! $atroot || $item eq 'import')) { @result = &$value($root, @$args); ## @result } elsif ( ref $item eq 'ARRAY' ) { diff --git a/t/stash.t b/t/stash.t index 53ba4fa8..ef93f74d 100644 --- a/t/stash.t +++ b/t/stash.t @@ -402,3 +402,16 @@ PASS: stringified from GetNumbersome [% cmp_ol.hello %] -- expect -- Hello + +# Verify that hash vmethods (e.g. keys, size) work on non-root hashes +# and that 'import' works on root stash (operator precedence fix) + +-- test -- +[% myhash = { a => 1, b => 2 }; myhash.keys.sort.join(', ') %] +-- expect -- +a, b + +-- test -- +[% myhash = { x => 10 }; CALL myhash.import({ y => 20 }); myhash.keys.sort.join(', ') %] +-- expect -- +x, y