On 4/7/06, David Wright <[EMAIL PROTECTED]> wrote:
>
> On Fri, 7 Apr 2006, demerphq wrote:
>
> > On 4/7/06, Adam Kennedy <[EMAIL PROTECTED]> wrote:
> >> Just because I (repeatedly) attack chromatic over UNIVERSAL::isa/can
> >> nobody should be under the impression that using the functions directly
> >> is in any way a good thing.
> >>
> >> The only cases for which it's genuinely useful is asking "ignoring what
> >> you say you are in OO terms, what are you actually implemented as
> >> underneath".
>
> > The only advantage I can think of using the function form of isa/can
> > is that you dont have to do a ref test first. Or if you want to find
> > out if a module is lying to you about what it isa/can do. But its not
> > actually that useful to find out how the module is implemented
> > underneath, nor is that useful for finding out how an object can be
> > used/dereferenced.
>
> Your $thingy could be a hashref, in which case $thingy->isa will die.

Yes, thats what I meant, I should have said blessed() not ref().

> I've been using it a lot recently to catch exceptions. What's so wrong
> with the below, almost identical to the example in perldoc -f die? I'd
> rather not die again immediately by assuming [EMAIL PROTECTED]>isa will work.
>
> eval {
>          # do some stuff
> };
>
> if ( $@ ) {
>          if( UNIVERSAL::isa($@, 'My::Exception') ) {
>             # known exception, handle appropriately
>          }
>          else {
>             die "Ooops-a-daisy: $@";
>          }
> }

Well, the problem with that is as chromatic says: What happens if $@
is an object that is pretending to be a My::Exception (ie, interface
compatible but not isa)? I think he would say it should be rewritten
as

if (blessed($@) and [EMAIL PROTECTED]>isa('My::Exception')) {
   ...
}

But the problem with that is blessed() wasnt even core until 5.8.x,
and isn't a true keyword but an exported sub. So you are putting a
dependency on a module that wont always be around.

IMO if the only kind of exception classes involved are your own then
there is no point.

cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

Reply via email to