in reply to Why ref() is bad.
in thread Is "ref $date eq 'ARRAY'" wrong?
All because HTML::Template uses ref.
Actually, no, that's not why. If it was just using ref() it wouldn't see that your object was an arrayref, it would see it as an object of some class. It uses isa(). This is exactly the advice the OP was getting: that he should use UNIVERSAL::isa(). I think that's generally poor advice and HTML::Template is one good example of one place just using ref() would have been an excellent idea.
Here is the relevant crufty code from HTML::Template:
if (defined($value_type) and length($value_type) and ($value_type +eq 'ARRAY' or ((ref($value) !~ /^(CODE)|(HASH)|(SCALAR)$/) and $value->isa('ARRA +Y')))) { (ref($param_map->{$param}) eq 'HTML::Template::LOOP') or croak("HTML::Template::param() : attempt to set parameter '$pa +ram' with an array ref - parameter is not a TMPL_LOOP!");
I think you are really misplacing blame. You are using HTML::Template so, you've contracted to abide by its API. You can't expect HTML::Template to handle everyones quirky data, afterall. And I think that's the fundamental misconception here. It isn't the module author's responsibility to code for every contingency. It's his responsibility to develop an API that makes sense and stick to it. Keeping it simple is a sound approach!
Your simple fix is to call
In other words, stringify your object yourself. You're the one who knows it should be stringified. HTML::Template doesn't.$template->param( PARAM => "$object");
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why ref() is bad. (It isn't bad, your assumptions are.)
by dragonchild (Archbishop) on Dec 20, 2003 at 16:39 UTC | |
by sauoq (Abbot) on Dec 20, 2003 at 21:15 UTC |