Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Why does this work? AUTOLOAD sans sub declaration

by converter (Priest)
on Nov 10, 2003 at 21:06 UTC ( #305975=note: print w/ replies, xml ) Need Help??

in reply to Why does this work? AUTOLOAD sans sub declaration

Since the perlsub POD mentions the AUTOLOAD subroutine in the same sentence as "BEGIN", "CHECK", "INIT", "END", "CLONE" and "DESTROY", I assume it shares some of the same characteristics as the others, the important one in this case being that the sub keyword is implied. When fed your code, B::Deparse prints the following. Notice how the sub keyword is inserted for the BEGIN subs, as well as the AUTOLOAD sub:

package Foo; use warnings; use strict 'refs'; our $AUTOLOAD; sub main::BEGIN { package main; no strict 'refs'; require strict; do { 'strict'->import }; } sub main::BEGIN { package main; require warnings; do { 'warnings'->import }; } sub new { return bless({}, shift @_); } sub do_something { print 'did something'; } sub AUTOLOAD { print "message from Foo: undefined method ($AUTOLOAD) called"; } package main; my $instance = 'Foo'->new; $instance->do_something; $instance->do_notimplemented;

Comment on Re: Why does this work? AUTOLOAD sans sub declaration
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://305975]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2015-11-29 07:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (748 votes), past polls