On Wed, Dec 15, 2004 at 12:06:51PM -0500, Thomas, Mark - BLS CTR said:
> I was hoping to find a way that didn't require modifying classes. I have a
> template which can be pointed at any TT source to find out what variables
> are available (like a fancy Dumper output). However it descends into a hash
> only if hash.keys exists.
install a method in UNIVERSAL?
% cat dumper.pl
#!/usr/local/bin/perl -w
use strict;
use Template;
my $t = Template->new();
my $o = bless { foo => 'bar', quux => 'quirka'}, "SomeClass";
my %opts = ( object => $o );
$t->process('dumper.tt', \%opts);
package UNIVERSAL;
sub keys {
my $self = shift;
return unless ref $self;
return keys %{$self};
}
% cat dumper.tt
[%- FOREACH key = object.keys -%]
[% key %]
[% END -%]
% ./dumper.pl
quux
foo
%
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates