Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-04-17 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (439 votes), past polls