# common, clean, readable, OO-ish way
$foo->bar ( 'bash' );
# less common, probably less readable, way
Foo::bar ( $foo, 'bash' );
####
# from 5.6.1's Socket.pm on Linux 2.4
sub AUTOLOAD {
my($constname);
($constname = $AUTOLOAD) =~ s/.*:://;
my $val = constant($constname, @_ ? $_[0] : 0);
if ($! != 0) {
my ($pack,$file,$line) = caller;
croak "Your vendor has not defined Socket macro $constname, used";
}
eval "sub $AUTOLOAD () { $val }";
goto &$AUTOLOAD;
}
####
package MessageLibrary;
use ...
my $hash = { ... };
sub new {
my ( $class, %args ) = @_;
my $self = {}; bless ( $self, $class );
$self->_init();
return $self;
}
sub _init { ... }
sub AUTLOAD() { ... }
1;
#-----------------------------
package MessageLibrary::Error;
my $hash = { ... something different ... }
sub _init {
my ( $self, %args ) = @_;
... class-specific init code, if needed ...
$self->SUPER::_init ( %args );
}
1;