in reply to Re: •Re: Re: •Re: Re: Say no to ref $thing eq "Expected::Type"
in thread Putting file contents into a scalar

In your IO::File wrapper you should override isa. Why not? It completes the wrap properly. This is a good argument for isa.
But you can't. Sorry for not spelling it out earlier, but there's nothing I can do in my wrapper class to make:
UNIVERSAL::isa($object_of_my_class, "IO::File")
return true. Yes, I could make:
$object_of_my_class->isa("IO::File")
return true, but nobody does that any more because it breaks if the item in question is not a blessed reference. Everyone uses the subroutine form now.

So, we lose. We all lose. Some place, we've got to push it so it works. I'm saying to do that with either eval wrappers or capability testing with can, not isa.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Re: •Re: Re: •Re: Re: Say no to ref $thing eq "Expected::Type"
by dws (Chancellor) on Oct 30, 2002 at 07:39 UTC
    There's nothing I can do in my wrapper class to make: UNIVERSAL::isa($object_of_my_class, "IO::File") return true.
    Nothing? Nothing reliable, perhaps, but try
    *UNIVERSAL::old_isa = *UNIVERSAL::isa; *UNIVERSAL::isa = sub { my($self,$pkg) = @_; return 1 if ref($self) eq 'MyClass' and $pkg eq 'IO::Handle'; return UNIVERSAL::old_isa(@_); }; package MyClass; sub new { bless {} } my $object_of_myclass = new MyClass(); my $rc = UNIVERSAL::isa($object_of_myclass, 'IO::Handle'); print $rc ? "It worked\n" : "Oh nuts\n";
    And no, I'm not serious.

      And no, I'm not serious.
      Caught me a split second before I hit "reply"..

      Makeshifts last the longest.

Re: •Re: Re: •Re: Re: •Re: Re: Say no to ref $thing eq "Expected::Type"
by Anonymous Monk on Oct 30, 2002 at 08:45 UTC
    But you can. You can override the function UNIVERSAL::isa with a wrapper that adds any special case logic that you want before calling the built-in.

    Of course when you start doing that...

(Re:)+ Say no to ref $thing eq "Expected::Type"
by rir (Vicar) on Oct 30, 2002 at 19:15 UTC
    Just that many people use UNIVERSAL::can( $complete_unknown, $classname) is not a reason to stop providing proper interfaces to your objects. No one is going to use good interfaces if they don't exist.

    The two issues are completely unrelated. If you don't even know if you have an object, naturally you aren't prepared to use its interface.

    I hope the nobodies prevail.