Re: [htmltmpl] Sub-Classing HTML::Template v2.7
Brought to you by:
samtregar
From: Sam T. <sa...@tr...> - 2005-03-03 19:30:40
|
On Thu, 3 Mar 2005, Cory Trese wrote: > My major questions are: > > 1. How does a sub-class of HTML::Template construct itself? Should I > over-ride 'new( )' or use something like 'make_new( )' to wrap 'new( )' > or 'SUPER::new( )'. package HTML::Template::Awesomer; use base 'HTML::Template'; sub new { my $pkg = shift; my $self = $pkg->SUPER::new(@_); return $self; } Of course you can insert your own code before and after the call to SUPER::new() depending what you're trying to do. > 2. What packages should my 'param( )' method be overridden in? More > than HTML::Template? In your sub-class of course. Something like: sub param { my $self = shift; $self->SUPER::param(@_); } Of course you'll want to add code to implement your extension. You should never have this line in a sub-class: > package HTML::Template; That's going to actually overwrite (not override) a subroutine in the HTML::Template namespace. Have you read Damian Conway's Object Oriented Perl book? I highly recommend it for anyone serious about doing OO in Perl. -sam |