There are some places in H::T where this is done... and I agree with you -> its wrong if you need to subclass H::T... However, you should be able to simply change it to:
$self->_new_from_loop(...) Perl will automatically dereference $self so as to determine the correct package name - in fact ref($self) may return a string which is not appropriate, in certain scenarios (eg: it may return HTML::Template when it should return, say, MyHtmlTemplate). Then _new_from_loop should implement: sub _new_from_loop { my $proto = shift; my $class = ref($proto) || $proto; ... } at this point $class will contain the correct package name. The same point could be said about H::T::E::output(), since it does this: sub output { .... HTML::Template::output(...) ... } which again is incorrect if H::T::E is to be subclass'able. FWIW, the version of H::T that I have modified (available at: http://members.optusnet.com.au/~mathew ) also makes this mistake in some of the code that I have extended... ie we are all fallable... regards, Mathew ----- Original Message ----- From: "Cory Trese" <[EMAIL PROTECTED]> To: "Cory Trese" <[EMAIL PROTECTED]>; <html-template-users@lists.sourceforge.net> Sent: Saturday, March 05, 2005 4:59 AM Subject: RE: [htmltmpl] Sub-Classing HTML::Template v2.7 > Hello, > > I have found the root of my problem! All the code below was centered > around trying, and failing, to fully replace all instances of the > HTML::Template 'param( )' method within our code-base. I thought that > by building a sub-class and overriding param, I would be able to > accomplish this. However, I was unable to override all calls to 'param( > )' -- some within HTML::Template remained using the SUPER::param( ). > > I attempted to overwrite the package method, as seen below. This, > however, doesn't actually work. So again, no dice. Until I found the > following code in HTML::Template around Line #2112: > > $loop->[HTML::Template::LOOP::TEMPLATE_HASH]{$starts_at} > > = HTML::Template->_new_from_loop( > > This does not seem friendly to sub-classes ... I didn't see any > references to this type of issue in Damian Conway's Object Oriented Perl > book, but I found a solution that works great for my sub-classes. > > $loop->[HTML::Template::LOOP::TEMPLATE_HASH]{$starts_at} > > = ref( $self )->_new_from_loop( > > This way, the "_new_from_loop" call always occurs against the correct > class -- HTML::Template or otherwise. I have no production code to test > compatibility with HTML::Template::Expr so I cannot state if this type > of change will work for everyone trying to sub-class HTML::Template. > > However, I do know that making this change caused my sub-classes to > completely work and I am very happy about that. > > Sincerely, > Cory Trese > Lead Web Application Developer > > O'NEIL & ASSOCIATES, INC. > 495 Byers Rd. > Miamisburg, Ohio 45342-3662 > Phone: (937) 865-0846 ext. 3038 > Fax: (937) 865-5858 > E-mail: [EMAIL PROTECTED] > > > |> -----Original Message----- > |> From: [EMAIL PROTECTED] > |> [mailto:[EMAIL PROTECTED] On > |> Behalf Of Cory Trese > |> Sent: Thursday, March 03, 2005 11:32 AM > |> To: html-template-users@lists.sourceforge.net > |> Subject: [htmltmpl] Sub-Classing HTML::Template v2.7 > |> > |> Hello, > |> > |> From some previous traffic on this list, Sam Tregar said: > |> > |> |> Ultimately HTML::Template v2 doesn't offer much in terms > |> of official > |> |> support for sub-classes and extensions. That's a > |> deficiency I intend > |> |> to address in the perpetually-delayed v3. > |> > |> I am trying to create a sub-class of HTML::Template that > |> over-rides the 'param( )' method. The code below "works" -- > |> mostly -- but I have a feeling that I'm doing this all > |> wrong. Does anyone have some advice or a link on > |> HTML::Template v2 sub-classing? I looked at > |> "HTML::Template::Expr" -- my code below is based, roughly, > |> on this module. > |> > |> 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( )'. > |> > |> 2. What packages should my 'param( )' method be overridden > |> in? More than HTML::Template? > |> > |> The thing that doesn't work right: > |> > |> 1. calls to 'param( )' seem to loose my 'i18n_strings' > |> object -- it isn't ALWAYS present in 'options' when I call > |> 'param( )', just most of the time. > |> > |> I _think_ that this is somehow related to some of the > |> 'param( )' methods I'm using being in the class 'make_new( > |> )' returns, and others, constructed somewhere else, but > |> still using my 'param( )' method. I know that's confusing I > |> haven't slept much in the past few days, sorry. > |> > |> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > |> package Service::Template; > |> > |> use strict; > |> use vars qw($VERSION); > |> > |> $VERSION = '0.01'; > |> > |> use HTML::Template; > |> > |> use base 'HTML::Template'; > |> > |> sub make_new { > |> my $pkg = shift; > |> my $self; > |> > |> # check hashworthyness > |> croak("Service::Template->new() called with odd number of > |> option parameters - should be of the form option => value") > |> if (@_ % 2); > |> my %options = @_; > |> > |> > |> # create an HTML::Template object, catch the results to keep error > |> # message line-numbers helpful. > |> eval { > |> $self = $pkg->new(%options ); > |> }; > |> croak("Service::Template->new() : Error creating > |> HTML::Template object > |> : $@") if $@; > |> > |> $self->{options}->{i18n_strings} = $options{'i18n_strings'}; > |> > |> > |> return $self; > |> } > |> > |> 1; > |> > |> package HTML::Template; > |> > |> sub param { > |> ... > |> } > |> > |> 1; > |> > |> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > |> > |> ************************************************************* > |> ********* > |> Confidentiality Notice > |> The information contained in this e-mail is confidential and > |> intended for use only by the person(s) or organization > |> listed in the address. If you have received this > |> communication in error, please contact the sender at O'Neil > |> & Associates, Inc., immediately. Any copying, dissemination, > |> or distribution of this communication, other than by the > |> intended recipient, is strictly prohibited. > |> ************************************************************* > |> ********* > |> > |> > |> > |> ------------------------------------------------------- > |> SF email is sponsored by - The IT Product Guide Read honest > |> & candid reviews on hundreds of IT Products from real users. > |> Discover which products truly live up to the hype. Start reading now. > |> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > |> _______________________________________________ > |> Html-template-users mailing list > |> Html-template-users@lists.sourceforge.net > |> https://lists.sourceforge.net/lists/listinfo/html-template-users > |> > > ********************************************************************** > Confidentiality Notice > The information contained in this e-mail is confidential and intended for > use only by the person(s) or organization listed in the address. If you have > received this communication in error, please contact the sender at O'Neil & > Associates, Inc., immediately. Any copying, dissemination, or distribution > of this communication, other than by the intended recipient, is strictly > prohibited. > ********************************************************************** > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Html-template-users mailing list > Html-template-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/html-template-users > ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ Html-template-users mailing list Html-template-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/html-template-users