moderated >> AUTOLOAD pretending to be Perl

by Mark Jason Dominus » Thu, 31 Aug 2006 02:39:47 GMT


Suppose I have an AUTOLOAD, and the AUTOLOAD has determined that it
doesn't want to emulate the function or method that was just called.
How can I have the AUTOLOAD issue exactly the same error message that
would have been issued, had Perl not found the AUTOLOAD instead?



moderated >> AUTOLOAD pretending to be Perl

by Yitzchak Scott-Thoennes » Thu, 31 Aug 2006 07:32:30 GMT


> Suppose I have an AUTOLOAD, and the AUTOLOAD has determined that it

There are just a couple different errors, aren't there? Would
Devel::Caller::called_as_method and Carp::croak be good enough?

Yitzchak Scott-Thoennes
Sr. Software Engineer II
W H I T E P A G E S .C O M | I N C
XXXX@XXXXX.COM

moderated >> AUTOLOAD pretending to be Perl

by Mark Jason Dominus » Thu, 31 Aug 2006 16:55:40 GMT


Yitzchak Scott-Thoennes:

Yes, that's exactly the essence of the problem.


Maybe that's just what I was looking for. Thanks.

moderated >> AUTOLOAD pretending to be Perl

by Gaal Yahas » Thu, 31 Aug 2006 18:30:58 GMT


There may not even be an error: if this is a method, don't you need
something like NEXT.pm to dispatch to the following module in the
inheritance tree?

--
Gaal Yahas < XXXX@XXXXX.COM >
http://gaal.livejournal.com/

moderated >> AUTOLOAD pretending to be Perl

by Mark Jason Dominus » Thu, 31 Aug 2006 21:12:58 GMT

Gaal Yahas:


In general, yes, but in this case there is no inheritance at all.

Similar Threads

1. *{$AUTOLOAD} vs *$AUTOLOAD



I frequently see statements like

  *{$AUTOLOAD} = \&foobar;  # under no strict 'refs'

but I don't understand the need for curly brackets in the LHS
expression.  Why not simply

  *$AUTOLOAD = \&foobar;

?

TIA!

jill


-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.

2. catch all method... e.g perl's autoload

3. Python's __getattr__, Perl's autoload, Ruby's method_missing, and Smalltalk's #doesNotUnderstand

4. Python's __getattr__, Perl's autoload, Ruby's method_missing, and Smalltalk's #doesNotUnderstand

5. SUPER::AUTOLOAD(@_) -- will this work? With $AUTOLOAD?

On Dec 19, 4:01 pm, Dodger < XXXX@XXXXX.COM > wrote a question and
then shortly thereafter answered it himself.

It appears to work. I made a small test script like so:



use strict;
my $bar = new Bar;
$bar->{thing} = 1;
print "\$bar->thing = ", $bar->thing, "\n";

print "Trying Bar AUTOLOAD specifically\n";
$bar->do_bar_AUTOLOAD(1, 2, 3);
print "\n";

print "Trying inherited AUTOLOAD\n";
$bar->do_foo_AUTOLOAD(4, 5, 6);
print "\n";

package Foo;
use strict;

our $AUTOLOAD;

sub new {
    my $pkg = shift;
    my $class = ref $pkg || $pkg;
    my $obj = {};
    bless $obj, $class;
    return $obj
}

sub AUTOLOAD {
    my $obj = shift;
    my $method = $AUTOLOAD;
    $method =~ s/^.*://;
    print "AUTOLOAD of Foo\n";
    print "method: $method\n";
    print "args: ", join('. ', @_), "\n";
}

package Bar;
use strict;
use vars('@ISA');
BEGIN {
    push @ISA,('Foo');
}

our $AUTOLOAD;


sub AUTOLOAD {
    my $obj = shift;
    my $method = $AUTOLOAD;
    $method =~ s/.*://;
print "method: $method\n";

    if ($method eq 'do_bar_AUTOLOAD') {
        print "AUTOLOAD of Bar\n";
        print "method: $method\n";
        print "args: ", join('. ', @_), "\n";
    }
    elsif (exists $obj->{$method}) {
        return "(Bar sez) $obj->{$method}";
    }
    else {
        $obj->SUPER::AUTOLOAD(@_);
    }
}

and my results came back as:

method: thing
$bar->thing = (Bar sez) 1
Trying Bar AUTOLOAD specifically
method: do_bar_AUTOLOAD
AUTOLOAD of Bar
method: do_bar_AUTOLOAD
args: 1. 2. 3

Trying inherited AUTOLOAD
method: do_foo_AUTOLOAD
AUTOLOAD of Foo
method:
args: 4. 5. 6

method: DESTROY
AUTOLOAD of Foo
method:
args:


So it appears that this trick will not work unless I specifically
assign to Foo::AUTOLOAD before calling it...

I tried it two ways:
    else {
        $SUPER::AUTOLOAD = $AUTOLOAD;
        $obj->SUPER::AUTOLOAD(@_);
    }
does NOT work, which seems odd...

because

    else {
        $Foo::AUTOLOAD = $AUTOLOAD;
        $obj->SUPER::AUTOLOAD(@_);
    }

DOES work...

So, I know how to do it now, but... I'm still unclear on one part...

Can anyone explain why I can't set the $AUTOLOAD in Foo with
$SUPER::AUTOLOAD instead of $Foo::AUTOLOAD if I can successfully call
SUPER::AUTOLOAD() instead of having to specify Foo::AUTOLOAD() ?

6. I am looking for PERL coder from Romania, Bulgaria, Russia or India - Perl

7. I am looking for a free perl compiler.

Hi, guys,

I am looking for a free perl compiler.

I tried PDK-Pro-6.0 from ActiveState.
It works pretty well.
But it's not free.

Where can I get a free perl compiler, as powerful as PDK-Pro-6.0 from
ActiveState?
Thanks in advance.

Best wishes,
Xun

-- 
Best wishes,
Xun

8. CPAN thinks I am using an older Perl version - Perl