> > > - dot syntax, eg 'user.name' > > > >Allowing dots in variable names seems harmless enough. > <snip> > > > The thing is, 'user.name' isn't a variable name in the traditional > way. Rather, it's saying 'I want the attribute "name" for the variable > "user"', thus providing a more OO approach. > > I imagine that this would be implemented by passing an object that provides > accessors for the fields that would show up in the template. For the > example above: > > package My::UserVar; > use base 'HTML::Template::Var'; # For example > > sub new > { > my $class = shift; > my $in = shift || { }; > return unless ref($in) eq 'HASH'; > my $self = { map { $_ => $in->{$_} || '' } qw( name addr city state > postal )}; > bless $self, $class; > } > sub name { $_->{name} } > sub addr { $_->{addr} } > sub city { $_->{city} } > sub state { $_->{state} } > sub postal { $_->{postal} } > > > package main; > > # $tmpl defined elsewhere, holding an HTML::Template object > my $user = My::UserVar->new({ name => 'foo', addr => 'bar' }); > $tmpl->param( user => $user );
I hadn't considered doing it this way, though the idea of using a OO styled notation appeals to me. I was thinking along the lines of: In a template you may do something like: <TMPL_IF user> <TMPL_IF user.name> <TMPL_VAR user.name.first> <TMPL_VAR user.name.last> </TMPL_IF> <TMPL_IF user.address> <TMPL_VAR user.address.street> <TMPL_VAR user.address.town> </TMPL_IF> </TMPL_IF> Normally your code would look something like: if (length $user->name->first or $user->name->last ) { $tmpl->param ('user' => 1); $tmpl->param ('user.name' => 1); $tmpl->param ('user.name.first' => $user->name->first ); $tmpl->param ('user.name.last' => $user->name->last ); } if (length $user->address->street or $user->address->town) { $tmpl->param ('user' => 1); $tmpl->param ('user.address' => 1); $tmpl->param ('user.address.street' => $user->address->street); $tmpl->param ('user.address.town' => $user->address->town); } With the 'structure_vars' support you can do this: $tmpl->param( 'user.name.first' = $user->name->first ); $tmpl->param( 'user.name.last' = $user->name->last ); $tmpl->param( 'user.address.street' = $user->address->street ); $tmpl->param( 'user.address.town' = $user->address->town ); regards, Mathew ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click _______________________________________________ Html-template-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/html-template-users