* Darren Chamberlain <d...@sevenroot.org> [2010-09-11 10:05]:
> Template Toolkit (and several other modules) use this idiom:
>
>   sub new {
>     my $class  = shift;
>
>     # allow hash ref as first argument, otherwise fold args into hash
>     my $config = defined $_[0] && UNIVERSAL::isa($_[0], 'HASH')  ? shift : { 
> @_ };
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     ..
>   }

That’s incredibly horrible. It should at least be using `reftype`
instead of abusing `UNIVERSAL::isa`. But in fact it should be
using just `ref`. You don’t want to reach inside an object just
because it happens to be hash-based. Miyagawa and I struggled
with this in writing Hash::MultiValue and eventually he settled
for this: <http://p3rl.org/Hash::MultiValue#NOTES_ON_ref>.
Perl( 5) just doesn’t really provide semantics for distinguishing
interface from implementation there.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to