in reply to AUTOLOAD inheritance

Dynaloader uses AUTOLOAD. Since you have said that MyModule is a Dynaloader, it means that if you call a function in the MyModule class, and it can't be found, Perl is going to search the Dynaloader package as well. Now, Perl also has the rule that if a function isn't found in a package, Perl will search for an AUTOLOAD function instead. These behaviours are not mutally excluded. Basically what happens if you call a function my_func in the package MyModule is:
  1. Search for the function my_func in MyModule. If found, call it. Else:
  2. Search for the function my_func in any of the packages inherited by MyModule. This is done in a depth-first order. If a function is found, call it. Else:
  3. Search for the function my_func in the UNIVERSAL package. If found, call it. Else:
  4. Search for the function AUTOLOAD in MyModule. If found, call it. Else:
  5. Search for the function AUTOLOAD in any of the packages inherited by MyModule. This is done in a depth-first order. If an AUTOLOAD function is found, call it. Else:
  6. Search for the function AUTOLOAD in the UNIVERSAL package. If found, call it. Else:
  7. Produce a fatal (but trappable) error about a function not found.
It's case 5 that's trapping this warning.

Abigail

Replies are listed 'Best First'.
Re: Re: AUTOLOAD inheritance
by ysth (Canon) on Feb 12, 2004 at 21:29 UTC
    That describes a method call (whether class or instance), but not a non-method function call. For these, steps 2 and 3 are skipped. That steps 5 and 6 happen for non-method calls is a historical oddity, and is deprecated (hence the warning).

    Update: the perldiag entry for the warning tells how to eliminate it if your code was intentionally relying on the deprecated behaviour: *AUTOLOAD = \&BaseClass::AUTOLOAD; (in this case, BaseClass would be DynaLoader.)   I would guess that more commonly, the warning is an indication of another problem, perhaps a missing use statement or misspelled function name.

      Well, it might be helpful to tell the poster how to eliminate the warning.... Since the module in question is a Exporter and DynaLoader, and only the latter has an autoload method, adding the following to the module should work (untested in this form, slightly modified from working code in a different context):
      sub AUTOLOAD { my $name = our $AUTOLOAD; $name =~ s/.*:://; # lose package name my $target = "DynaLoader::$name"; goto &$target; }
      This will get called in Abigail-II's step 4, preventing the warning from step 5.