> -----Original Message----- > From: Aristotle Pagaltzis [mailto:pagalt...@gmx.de] > Sent: Sunday, September 12, 2010 11:10 PM > To: module-authors@perl.org > Subject: Re: my $self = shift > > * 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
Well, evil or not, I wrote something that eases this kind of job: http://search.cpan.org/~burak/Scalar-Util-Reftype/lib/Scalar/Util/Reftype.pm > 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/>