Figure out another way. Really. Like, it's ridiculous that ref is still being used in high-level code. And, I've got a really good reason.

I have the following situation:

So far, so good, right? The problem is in the <readmore>

HTML::Template uses ref all over the place. One thing is does is check to see if the value of a parameter is an arrayref. If it is, then it assumes that you're using it for a <TMPL_LOOP> and complains if it's being used for a <TMPL_VAR>. My self-formatting nubmers are meant for <TMPL_VAR> usage. So, we have a case of where I have to do this in my self-formatting number class. (I should move it to the base class, frankly.)

{ my %is_internal_type = map { $_ => 1 } qw( ARRAY HASH SCALAR GLOB CODE ); sub isa { my $self = shift; my ($type) = @_; return if $is_internal_type{$type}; return $self->SUPER::isa($type); } }

All because HTML::Template uses ref. And, it's not just HTML::Template. Most modules that have much dwimmery suffer from the same ... lack of discernment.

Figure out another way. Use class names and provide a factory, use different function name to provide different signatures, anything! Just don't use ref!

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.


In reply to Why ref() is bad. by dragonchild
in thread Is "ref $date eq 'ARRAY'" wrong? by bronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.