Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRACE_VARS using hash extraction #53

Open
sten22 opened this issue Oct 6, 2015 · 6 comments
Open

TRACE_VARS using hash extraction #53

sten22 opened this issue Oct 6, 2015 · 6 comments
Labels

Comments

@sten22
Copy link

sten22 commented Oct 6, 2015

Simple test case:

use Template::Parser;
use Test::More;

my $template = Template::Parser
    ->new(TRACE_VARS => 1)
    ->parse('[% FOREACH [ A ] %][% B.C %][% END %]');

is_deeply $template->{VARIABLES}, {A => {B => { C => {} } } };

done_testing;

Output:

not ok 1
#   Failed test at t/auto/template/trace-vars.t line 8.
#     Structures begin differing at:
#          $got->{A}{B} = Does not exist
#     $expected->{A}{B} = HASH(0x7fdd1501b730)
1..1
# Looks like you failed 1 test of 1.
@toddr toddr added the Bug label Oct 5, 2018
@toddr
Copy link
Collaborator

toddr commented Oct 9, 2018

Looks like it stores as:

#   'VARIABLES' => {
#     'A' => {},
#     'B' => {
#       'C' => {}
#     }
#   }

@toddr
Copy link
Collaborator

toddr commented Oct 9, 2018

I don't necessarily see why you were expecting {A => {B => { C => {} } } }

@a-parser
Copy link

a-parser commented Oct 9, 2018

Just because [ A ] will expand keys in FOREACH scope and B.C will be accessible

@toddr toddr added the Soon label Oct 9, 2018
@toddr
Copy link
Collaborator

toddr commented Oct 9, 2018

foreach is a loop. So you're iterating once with A as the $_; but then in the loop you're not doing $_.B.C You're doing B.C I don't see how A is implied. If it were implied, how would you display B.C if you wanted to?

@toddr toddr added Query and removed Soon Bug labels Oct 9, 2018
@toddr toddr changed the title Bug in TRACE_VARS using hash extraction TRACE_VARS using hash extraction Oct 9, 2018
@toddr toddr closed this as completed Oct 11, 2018
@a-parser
Copy link

I can't found this in docs right now, but it's works for long time:

perl -e 'use Template; Template->new()->process(\"[% FOREACH [A]; B.C; END %]\n", {A => {B => {C => 42}}});'
42

And it is present in tests:
https://github.com/abw/Template2/blob/master/t/foreach.t#L370

@toddr toddr reopened this Oct 11, 2018
@toddr toddr added the Bug label Oct 11, 2018
@toddr
Copy link
Collaborator

toddr commented Oct 11, 2018

@a-parser I'm surprised it does that but it looks like this works now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants