Re: protecting access to object instance fields?
E R <[email protected]> Mon, 11 Feb 2013 11:39:43 -0600
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <CA+QY9tsrEGzYUeNqjpZggCZOq2rb=ko8Dc3L6s4whKz6AQDT_Q@mail.gmail.com> |
Ok - thanks. In my testing I didn't use '_' to prefix my fields. On Mon, Feb 11, 2013 at 11:35 AM, Stuart Johnston <[email protected]>wrote: > On 2/11/2013 10:54 AM, E R wrote: > >> When I have an object (e.g. blessed hash) in the stash, I'd like to >> prevent TT from accessing any of the hash fields directly. It can still >> access the method functions. >> >> A simple example - suppose the TT template looks like: >> >> [% obj.the_time %] >> [% obj._unix_time %] >> >> and in the stash 'obj' is a blessed hash: >> >> package foo; >> >> sub new { bless { _unix_time => time }, shift } >> sub the_time { ... } >> >> I'd like the first GET to succeed and the second one to either fail, >> raise and exception, return the empty string or something like that. >> >> Is this possible? >> > > This is already the default. Vars that start with '.' or '_' are > considered private, and ignored. If you want to die, rather than getting > undef, add STRICT => 1 to your Template->new. > > > > ______________________________**_________________ > templates mailing list > [email protected] > http://mail.template-toolkit.**org/mailman/listinfo/templates<http://mail.template-toolkit.org/mailman/listinfo/templates> > _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates