Expose the stash , ideal for dumping via Template::Plugin::Dumper. Useful for debugging template toolkit. See pod for details

update:

get tarball at Template-Plugin-Stash-0.02.tar.gz.

=head1 NAME Template::Plugin::Stash - expose the stash, ideal for I<Dumper>ing... =head1 SYNOPSIS [% USE Stash %] [% USE Dumper Indent = 1%] <pre>[% Dumper.dump_html( Stash.stash() ) %]</pre> =head1 DESCRIPTION Instead of messing with C<< [% PERL %] >> blocks to get at the stash, simply C<< [% USE Stash %] >>. Output will look something like $VAR1 = bless( { 'global' => {}, 'var1' => 6666666, 'var2' => { 'e' => 'f', 'g' => 'h', 'a' => 'b', 'c' => 'd' }, }, 'Template::Stash::XS' ); which should be all you need. =head1 SEE ALSO L<Template::Plugin|Template::Plugin>, L<Template::Plugin::Dumper|Template::Plugin::Dumper>. =head1 LICENSE Copyright (c) 2003 by D.H. (PodMaster). All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. If you don't know what this means +, visit http://perl.org/ or http://cpan.org/. =cut package Template::Plugin::Stash; use strict; use base qw[ Template::Plugin ]; use vars '$VERSION'; $VERSION = 0.02; sub new { my( $class, $con ) = @_; return bless { _CONTEXT => $con }, $class; } sub stash { my $self = shift; my $stash = $self->{_CONTEXT}->stash()->clone(); delete $stash->{$_} for qw[ template dec inc component Stash ], grep { /^_/ } keys %$stash; for my $k( keys %$stash ){ delete $stash->{$k} if ref($stash->{$k}) =~ /^\QTemplate::Plu +gin/; } return $stash; } 1;
  • Comment on Template::Plugin::Stash - expose the stash, ideal for dumpering...
  • Download Code

Replies are listed 'Best First'.
Re: Template::Plugin::Stash - expose the stash, ideal for dumpering...
by theorbtwo (Prior) on Dec 23, 2003 at 19:27 UTC

    Because I'm confused: This deals with a Template Toolkit concept called the stash, and not the stash where perl holds my variables ... unlike a lot of recent snippets we've seen that deals explicitly with the later. Right?


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      Yes, this deals with the TT2 stash (it's the same concept as in perl). Sometimes you need to see all the variables available in a particular template. It basically answers this. Initially I solved this by embedding perl (which is bad) like so
      [% PERL %] use Data::Dumper; local $Data::Dumper::Indent = 1; print "THE STASH", Data::Dumper::Dumper($stash); [% END %]

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.