Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://305975]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2017-02-22 01:14 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (322 votes). Check out past polls.