On Fri, 2014-08-29 at 10:00 -0700, Karen Etheridge wrote:
> On Fri, Aug 29, 2014 at 09:34:41AM -0400, David Mertens wrote:
> > We can all agree that Perl likes to give lots of rope to its programmers.
> > Calling UNIVERSAL::isa prevents mocking, but it also prevents nefarious
> > classes from lying about what they do. Apparently, allowing mocking is *so*
> > much more useful than safe-guarding against lying that the porters decided
> > to (1) remove the documentation of this behavior (though anybody who
> > understands Perl's object system could figure it out)
> 
> Yes, a lot of things are tailored towards the newbie programmer, and
> rightly so, because it's an army of well-intentioned but ignorant newbies
> that can code us into a deep dark hole from which it takes a long time to
> get us out.
> 
> (And, as such, I tailor my answers on publicly archived and searchable
> mailing lists accordingly.)
> 
> I'm also saying all this just after fighting with fixing UNIVERSAL::isa's
> code (the CPAN module, not the built-in version) and shaking my head at all
> the wrongness that I found on the CPAN.
> 
> > and (2) remove it
> > from the Exporter list so that it is difficult to bring this function into
> > your current package.
> 
> I don't think that's the reason why it was removed.  There were technical
> issues involving interactions between UNIVERSAL and Export that were the
> primary motivators here, instead.  The p5p list contains all the gory
> details.
> 
> > If you think UNIVERSAL::isa is the
> > right way to go, then use it. But you really should know what you're
> > doing---and preventing---before using it this way. Chances are quite good
> > that the OP had code written by somebody who didn't understand what they
> > were doing.
> 
> Agreed on all counts.  And, FWIW, all the instances of 'UNIVERSAL::isa'
> that I found on my searches on grep.cpan.me were of the
> newbie-doing-it-wrong form, rather than the
> yes-I-really-want-the-true-answer-not-the-mocked-one-and-I-understand-the-difference
> form.
> 
> 


This thread has me curious.  

I wrote Sys::SigAction more than 10 years ago, and I have made minor
improvements and bug fixes over the years since.  I believe it is still
deemed useful... useful enough for the Debian packagers to ask me to
change the license to a pure perl license several years ago.


Sys::SigAction has one instance of a call to UNIVERSAL::isa (line 135 of
SigAction.pm) in a function context:

die '$action is not a POSIX::SigAction' if not UNIVERSAL::isa( $action 
,'POSIX::SigAction' );

This call is in set_sigaction() which is in a private function and it is
essentially just defensive programming. I don't think I have had a
problem with this since is was first released.   The reason
UNIVERSAL::isa is called as a function here is that that within the
scope of this function how might one know if the scaler $action is
blessed reference, just a reference, or something else. UNIVERSAL::isa()
answers all of these questions in one statement.  

If UNIVERSAL::isa() is now deemed "incorrect" in a context like this,
I'm curious, given the requirements this line of code meets, what those
on this list think this line of code should be converted to.  



Reply via email to