Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Accessing Template Toolkit Variables

by ktowle (Initiate)
on Oct 06, 2011 at 19:48 UTC ( #930051=note: print w/ replies, xml ) Need Help??


in reply to Re: Accessing Template Toolkit Variables
in thread Accessing Template Toolkit Variables

Extended the module to at least nominally handle dotted variables:

use strict; use warnings; package Template::Capturing::Stash; { use base 'Template::Stash'; our %remembering_hash; sub get { die if @_ != 2; my ( $self, $var_name ) = @_; my $var_value = $self->SUPER::get($var_name); if ( ref $var_name eq 'ARRAY' ) { $var_name = compound_var( @{$var_name} ); } #print "! Get of $var_name = $var_value\n"; $remembering_hash{$var_name} = $var_value; return $var_value; } sub set { die if @_ < 3 or @_ > 4; my ( $self, $var_name, $var_value, $default ) = @_; die "Not yet coded to handle default" if defined $default; my $return_value = $self->SUPER::set( $var_name, $var_value ); if ( ref $var_name eq 'ARRAY' ) { $var_name = compound_var( @{$var_name} ); } #print "! Set of $var_name = $var_value\n"; $remembering_hash{$var_name} = $var_value; return $return_value; } sub compound_var { my @var_name = @_; my @compound_var; foreach my $element ( @var_name ) { unless ( $element eq '0' ) { if ( ref $element eq 'ARRAY' ) { $element = compound_var( @{$element} ); } push @compound_var, $element; } } return join '.', @compound_var; } } 1;


Comment on Re^2: Accessing Template Toolkit Variables
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930051]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-09-17 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (100 votes), past polls