Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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 l.pl line 5 UNIVERSAL::AUTOLOAD() called at l.pl line 8
Could any one explaine me why can't Carp deal with UNIVERSAL::AUTOLOAD

"Keep pouring your ideas"

Comment on Carp can't deal with UNIVERSAL::AUTOLOAD
Download Code
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.

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

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-09-22 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls