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

Re: [5.8.12] Proposal for changing UNIVERSAL semantics

Thread Previous | Thread Next
Michael G Schwern
November 4, 2003 04:09
Re: [5.8.12] Proposal for changing UNIVERSAL semantics
Message ID:
On Tue, Nov 04, 2003 at 02:51:10AM -0800, Michael Jacob wrote:
> 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 ;)

Wrong solution.

	my $code_ref = $class->can('can');

That is perfectly valid code.  Has been for years.  Don't change it.
Even if you changed every module on CPAN and somehow got around the
halting problem of:

	my $code_ref = $class->can($method);

there's still all that code out there that's not on CPAN that we can't

Backwards compatibility does not just mean your car goes in reverse.

> 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.

We do?  I've been using can() for all sorts of horrid things for years and
never had to do *that*.  Why would I want to deliberately ignore methods
inherited from UNIVERSAL?

Are you saying we can't rely on not being modified... when,
at run time?  Sometime in the future?  I don't understand.

Your code examples seem to imply that anything inherited from UNIVERSAL
is inherited by mistake and must be covered up.  That runs directly against
the current uses of UNIVERSAL:: on CPAN.  UNIVERSAL::monkier, 
UNIVERSAL::require and UNIVERSAL::exports.  They all quite deliberately
put perfectly normal public methods into UNIVERSAL.

> (Remember, you cannot use UNIVERSAL and DBI in the same program now!) 

As noted in my eariler post it seems DBI has some bizarre XS
hackery changing now the method dispatcher and can() work that 
Attribute::Handlers is tickling.  There's where the problem likely lies.  
I'm sure Tim will track it down and fix it.

Also, UNIVERSAL and DBI appear to work just fine together.  I just ran
DBI's test suite with PERL5OPT='-MUNIVERSAL' set both using the current
version of UNIVERSAL and the one from bleadperl.  No problems.

I think the problem is only triggered by Attribute::Handlers which, as
has been noted, is putting *way* too much stuff into UNIVERSAL and is
slated to be fixed.

> In future, one who rally want's to catch _soft_referenced_method_calls_ to can(), is() and VERSION() must write:

What's a soft_referenced_method_call?

>   if (my $a = $obj->can($method) || UNIVERSAL->can($method)) {
> Tell me what more more often will be written as "$obj->can($method)" by accident?

Michael G Schwern
<mendel>	 ScHWeRnsChweRN    sChWErN   SchweRN  SCHWErNSChwERnsCHwERN    
  sChWErn  ScHWeRn	schweRn 	  sCHWErN	    schWeRn    scHWeRN 
   SchWeRN	scHWErn SchwErn       scHWErn	    ScHweRN	  sChwern      
scHWerN        scHWeRn		 scHWerN	ScHwerN       SChWeRN scHWeRn  
	SchwERNschwERn	      SCHwern  sCHWErN	 SCHWErN	   sChWeRn 

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