Re: [Templates] hash.keys not working on blessed hash?

[prev] [thread] [next] [Date index for 2004/12/15]

From: Simon Wistow
Subject: Re: [Templates] hash.keys not working on blessed hash?
Date: 17:41 on 15 Dec 2004
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
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] hash.keys not working on blessed hash?
Thomas, Mark - BLS CTR 13:57 on 15 Dec 2004

RE: [Templates] hash.keys not working on blessed hash?
Thomas, Mark - BLS CTR 17:06 on 15 Dec 2004

Re: [Templates] hash.keys not working on blessed hash?
Simon Wistow 17:41 on 15 Dec 2004

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52