develooper Front page | perl.perl5.porters | Postings from November 2003

Re: [5.8.12] Proposal for changing UNIVERSAL semantics

Thread Previous | Thread Next
Michael Jacob
November 4, 2003 02:59
Re: [5.8.12] Proposal for changing UNIVERSAL semantics
Message ID:
On 2003-11-04 10:49:14 Dave Mitchell <> was overheard saying:
> On Mon, Nov 03, 2003 at 12:37:49PM -0800, Michael Jacob wrote:
>> I think, this change should not break any well written module. Testing
>> for any method that's in UNIVERSAL is just useless, we already know
>> before the test that it must be there. Any module that want's to know if
>> there is some additional method in UNIVERSAL:: can just test against
>> UNIVERSAL->can() directly.
>But C<can> doesn't just test for existance, it returns a code ref of the
>method if found. Thus C<$code = $obj->can('can')> is perfectly
>reasonable, and should return a ref to UNIVERSAL::can if there aren't
>any others in the inheritance chain.

Show me one CPAN module that calls can() on anything (other than UNIVERSAL) to get a coderef for can(), isa() or VERSION(). I will personally contact the author to change his code to use \&UNIVERSAL::isa etc before Perl 5.12.0 ;)

This is why I proposed this to be a two step change with a depricated warning in 5.10 first.

At the moment, we need to write:

  my $a = $obj->can($method);
  $a = undef if $a eq UNIVERSAL->can($method);
  if ($a) {

or fail miserably when is loaded or UNIVERSAL:: is modified. (Remember, you cannot use UNIVERSAL and DBI in the same program now!) In future, one who rally want's to catch _soft_referenced_method_calls_ to can(), is() and VERSION() must write:

  if (my $a = $obj->can($method) || UNIVERSAL->can($method)) {

Tell me what more more often will be written as "$obj->can($method)" by accident?

Gratuitous Advertisements:

This email was brought to you by You've Got Post!


Publish your company's press releases for just $5.99 per month (unlimited access), visit

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About