Thread view

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: [ctrese@...]
|> -----Original Message-----
|> From: html-template-users-admin@...
|> [mailto:html-template-users-admin@...] On
|> Behalf Of Cory Trese
|> Sent: Thursday, March 03, 2005 11:32 AM
|> To: html-template-users@...
|> 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@...
|> 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.
**********************************************************************

Community

Help

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

CountryState

JavaScript is required for this form.

I agree to receive quotes, newsletters and other information from sourceforge.net and its partners regarding IT services and products. I understand that I can withdraw my consent at any time. Please refer to our Privacy Policy or Contact Us for more details