Re: [Templates] Accessing hash elements in a tied hash-object

[prev] [thread] [next] [Date index for 2005/04/13]

From: Andy Wardley
Subject: Re: [Templates] Accessing hash elements in a tied hash-object
Date: 07:37 on 13 Apr 2005
Trond Michelsen wrote:
> Is it possible to access hash elements of an object which is also a
> tied hash?

Yes you can using the regular Perl Stash, but not using the XS Stash which
doesn't supports tied objects (something which is very non-trivial in XS
code).

> FETCH() and STORE() are just wrappers around functions called
> swig_${key}_get and swig_${key}_set(), so I don't _have_ to access the
> object as a hash. It'd just be nice to be able to reduce the general
> uglyness the swig_*_[gs]et methods causes.

TT3 provides a way around this with the TT_get($key) and TT_set($key, $value) 
methods.  You can provide these for your objects to handle the mapping to
internal methods.  e.g.

  sub TT_get {
    my ($self, $key) = @_;
    my $method = "swig_${key}_get";
    $self->$method();
  }

Not much help to you at the moment, but it is on the list of "things broken
in TT2 and fixed in TT3".

A


_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

Re: [Templates] Accessing hash elements in a tied hash-object
Andy Wardley 07:37 on 13 Apr 2005

Generated at 09:31 on 27 Apr 2005 by mariachi v0.52