Objects are not different than primitive Perl datastructures. I guess I was a little loose with my usage of the word "object" in that quote, but I simply meant "a thing" and not specifically a blessed reference. HTML::Template currently will take any hashref, blessed or unblessed. But the point is that H::T doesn't hinge on any internal hash magic -- all it needs from the "things" you pass is the interface of a hashref. A blessed arrayref can have this interface, but the way HTML::Template checks its input makes it very hard to successfully get this to work.

The documentation for HTML::Template says to pass it in hashrefs, etc -- "plain old reference" datastructures. But blessed objects can be used seamlessly as "plain old reference" datastructures, either by being the correct type of blessed reference, or by overloading the appropriate dereferencing operators. I'm just suggesting a more complete way of checking for the type of a datastructure that includes these possibilities.

It's like writing a sub that requires a scalar, so you have some code to verify the input is a scalar. But the verification code fails for a tied scalar. That would be ridiculous. We have tied objects so we can use the "plain old variable" interface seamlessly. We also have the ability to overload dereferencing operators -- for what other reason than to use the "plain old reference" interface?

blokhead


In reply to Re: Re: "Is it a hashref" vs "Can I use it like a hashref?" by blokhead
in thread "Is it a hashref" vs "Can I use it like a hashref?" by blokhead

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.