in reply to Re: Carp; errors ala DBI
in thread Carp; errors ala DBI
Yes, I am serious. Update: But use the relatively new NEXT and all the problems can go away.
AUTOLOAD is a powerful and facile tool: a beautiful thing.
I like it a lot. So there can be overriding motives to use
AUTOLOAD, but if possible it is to be avoided by module
publishers.
It is a name greedy pig.
The way Perl resolves a call is:
-
Seek routine in package.
-
If method: seek method in base classes.
-
Seek AUTOLOAD in package.
-
If method: seek AUTOLOAD in base classes.
The following code demonstrates the problem.
#!/usr/bin/perl -w use strict; package Mumma; use vars qw( $AUTOLOAD ); sub AUTOLOAD { print "$AUTOLOAD resolved to Mumma::AUTOLOAD\n"; } package Poppa; use vars qw( $AUTOLOAD ); sub AUTOLOAD { print "$AUTOLOAD resolved to Poppa::AUTOLOAD\n"; } # Baby doesn't know that Mumma & Poppa are secret AUTOLOADERs package Baby; use vars qw( @ISA $AUTOLOAD ); @ISA = qw( Poppa Mumma ); # Order is significant. sub new { bless {}, ref $_[0] || $_[0] } package main; use vars qw( $AUTOLOAD); # Baby is supposed to live in a caring universe. sub UNIVERSAL::AUTOLOAD { print "$AUTOLOAD resolved to UNIVERSAL::AUTOLOAD\n"; } my $c = Baby->new(); # first &AUTOLOAD found hides rest. $c->wants_mumma(); $c->wants_poppa(); $c->wants_universal_truth();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Carp; errors ala DBI
by adrianh (Chancellor) on Sep 21, 2002 at 13:36 UTC |
In Section
Seekers of Perl Wisdom