skerr1 has asked for the wisdom of the Perl Monks concerning the following question:

I get the following error:
Use of inherited AUTOLOAD for non-method common::process_error() is deprecated at mytool line 100.
In mytool I have:

use common;

In common.pm I have:

package common; use Exporter; use vars qw (@ISA @EXPORT); require SelfLoader; @ISA = qw(Exporter SelfLoader); @EXPORT = qw(process_error); __DATA__ sub process_error { #my code } 1;
Any ideas why I am getting this???

Replies are listed 'Best First'.
Re: deprecation problem
by japhy (Canon) on Feb 11, 2002 at 22:36 UTC
    The SelfLoader documentation suggests you use SelfLoader rather than require() it, because it does stuff in its import() method. Also, the docs state that there is no need to inherit from the module (so you needn't say @ISA = qw( SelfLoader ).

    The warning you get is because you added it to the inheritance tree, and Perl found SelfLoader::AUTOLOAD, and it's generally a bad idea to inherit an AUTOLOAD for functions rather than methods. It's all OO stuff. Here's code that works for me:

    package common; use SelfLoader; require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( process_error ); __DATA__ sub process_error { print "foo!\n"; }

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who could use a job
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      This was outstanding!!! Great work.
Re: deprecation problem
by skerr1 (Sexton) on Feb 11, 2002 at 22:28 UTC
    Also,
    I have a function in "mytool" called print_usage. In the Perl module "common.pm" the process_error function calls print_usage. When I try to do this I am getting the error:
    Undefined subroutine &common::print_usage called at common.pm line 100
    So common.pm does not know about print_usage from "mytool".
    All help is appreciated!
    -sk
      Does common.pm require() or use mytool.pm anywhere? And if so, does it import that function from it?

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who could use a job
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      When you are within the package called "common", all function calls are assumed to be calls to functions in that same package, unless you fully-qualify the fuction name itself. Assuming that "mytool" is a script, you were trying to call a routine that is in the main:: namespace from within the common:: namespace.

      --rjray

        After preceding the call to the print_usage function by "main::", that solved my problem. Thanks alot. I still have much to learn!