Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Carp can't deal with UNIVERSAL::AUTOLOAD

by jesuashok (Curate)
on Jun 07, 2006 at 16:43 UTC ( #554088=perlquestion: print w/replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

dear monks,

#!/usr/bin/perl -w use Carp; sub UNIVERSAL::AUTOLOAD { carp "foo"; } bar(); Error :- <code> foo at line 5 UNIVERSAL::AUTOLOAD() called at line 8
Could any one explaine me why can't Carp deal with UNIVERSAL::AUTOLOAD

"Keep pouring your ideas"

Replies are listed 'Best First'.
Re: Carp can't deal with UNIVERSAL::AUTOLOAD
by ikegami (Pope) on Jun 07, 2006 at 17:29 UTC

    Your problem has nothing to do with either UNIVERSAL or AUTOLOAD. You're seeing that behaviour because your AUTOLOAD was built in package main. Examine the following:

    sub Test1::print_context { print(__PACKAGE__, "\n"); } { package Test2; sub print_context { print(__PACKAGE__, "\n"); } } Test1::print_context(); # main Test2::print_context(); # Test2

    Fixed code:

    #!/usr/bin/perl -w { package UNIVERSAL; use Carp; sub AUTOLOAD { carp "foo"; } } bar();
Re: Carp can't deal with UNIVERSAL::AUTOLOAD
by derby (Abbot) on Jun 07, 2006 at 16:50 UTC

    Maybe because UNIVERSAL is the base class for all classes and bar is not a method but a subroutine. Maybe ... your code works fine for my version of perl (5.8.2) but I do get a deprecation warning -- Use of inherited AUTOLOAD for non-method main::bar() is deprecated.

Re: Carp can't deal with UNIVERSAL::AUTOLOAD
by perrin (Chancellor) on Jun 07, 2006 at 17:14 UTC
    UNIVERSAL::AUTOLOAD? You're really going to make life hard for yourself if you start messing with that. All kinds of strange things may happen.
Re: Carp can't deal with UNIVERSAL::AUTOLOAD
by diotalevi (Canon) on Jun 07, 2006 at 17:36 UTC

    Ok, so it doesn't examine $UNIVERSAL::AUTOLOAD. And? Patch Carp from bleadperl and send it in to p5p. Read perlhack for details.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://554088]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2016-10-21 13:13 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.