Then write a module that provides routines (not methods) that satisfy your exacting standards or stop whining.
Most of the time when I come across these cases, I find several choices of what to do and none of them are perfect and it isn't easy to figure out if I'm overlooking some bizarre code (such as chromatic's "well-used code on the CPAN" that breaks in the face of the techniques that most people end up using).
I often punt and use UNIVERSAL::isa( $var, "TYPE" ) and assume that people who do really strange stuff can always just push @ISA, "TYPE" if they need to.
I can't afford to spend the amount of effort that you would require to support a slightly old version of Perl just to try (and probably fail) to figure out how to get my code to work with that last 1% of weird cases.
For years I've felt that Perl needed better ways to determine "is this a hash reference" and what we got was more ways to do it and other changes that made none of the ways perfect still. So now we've got lots of not perfect ways and lots of confusion.
In one case (Data::Diver), I wanted to be extra precise so I resorted to something like eval { my $x= $ref->[0]; 1 } but that can't be used to test for CODE refs (and one can still write objects that don't tollerate such very well, but I really consider such objects broken at this point).
So I test for CODE refs by using isa() as a function. And I'm sure I'll do that many more times until someone comes up with the obviously better solution. And the following isn't obviouisly better to me:
( eval { $ref->can("isa") } || \&UNIVERSAL::isa )->( $ref, "TYPE" )
because it is dang ugly and I'm not going to type that over and over (and I'm not sure that it is a 100% solution and it took me several tries to even come up with that).
I've seen people fighting about "isa" and "UNIVERSAL" and "AUTOLOAD" and I've mostly come away with the impression that AUTOLOAD is broken in design and should have instead been designed to return a code ref and there is no perfect solution to this design oversight and there are several conflicting camps about the "right" way to deal with it and I haven't seen a clear winner so I don't write code that assumes any one of those camps.
So provide the obviously better solution.
|