develooper Front page | perl.perl5.porters | Postings from August 2001

Re: 'can' with undefined subs

Thread Previous | Thread Next
From:
Tony Bowden
Date:
August 17, 2001 00:16
Subject:
Re: 'can' with undefined subs
Message ID:
20010817081640.A1868@blackstar.co.uk
On Fri, Aug 17, 2001 at 01:18:52AM +0100, Hugo van der Sanden wrote:
> A stub, which is a dummy coderef.
> :Is this behaviour 'correct'?
> It is deliberate, which is almost as good.

That's good enough :)

> :but it will equally trip the user up if there isn't an AUTOLOAD and the
> :method they thought they were safe in calling explodes.
> 
> I think that's really down to the user not to declare a sub without
> providing an implementation - "Undefined subroutine &Foo::bar called"
> is about as helpful as we can be at that point.

My main concern here is that UserA, who uses the module, may not be the
same as UserB, who wrote it.

So we end up with a scenario where UserA, thinking she's playing safe,
doesn't just call Foo->$method(@args), but ensures it's there first:
  if (my $ref = Foo->can($method)) {
    $ref->(@args)
  }
And the program still blows up. 

Probably not a big deal though ...

> :It also doesn't seem to be documented anywhere.
> Patches welcome, as always. You may well find that we are deficient
> on tests for this behaviour as well. :)

I'll try to find the best place to document it. Suggestions welcome.
Where should the test live?

Tony
-- 
--------------------------------------------------------------------------
 Tony Bowden | tony@tmtm.com | http://www.tmtm.com/
                          if more people were screaming then I could relax
--------------------------------------------------------------------------


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About