in reply to AUTOLOAD and packages

you could either use Exporter module, or, even simpler, following approach:
package mypackage; sub my_lovely_autoload_for_main { # bla bla bla print STDERR "[@_]\n"; } *::main::AUTOLOAD = \&::mypackage::my_lovely_autoload_for_main; package main; fjkre('wdw');
Vadim

PS. Checking for existing main::AUTOLOAD and calling at appropriate time is left as exercise for reader :)

Replies are listed 'Best First'.
Re: Re: autoload and packages
by smackdab (Pilgrim) on May 11, 2002 at 20:15 UTC
    Thanks, I kinda get it...but if there is a main::AUTOLOAD, do I have to "rename" it? As it seems "*::main::AUTOLOAD = \&::mypackage::my_lovely_autoload_for_main;" will override it and then I can't call the original main::AUTOLOAD... Am I missing something?
      okay, you decided not to do exercise for a reader :)
      Let me give you my code for example for a reader:
      BEGIN{ if (exists $::{AUTOLOAD}) { print "exisa\n"; } else { print "no-exisa\n"; } } sub AUTOLOAD{} BEGIN{ if (exists $::{AUTOLOAD}) { print "exisa\n"; } else { print "no-exisa\n"; } }
      Sorry for not clearing it for cleverness, I'm drunk now :)
      but I checked it, it works!
        Thanks Svad ---remember, friends don't let friends code drunk :*)

        I'll post the entire module later, as I guess I can't explain what I am trying to do...unfortunately this is normal as I am learning perl by trial and error...

        I know that I can check to see if main::AUTOLOAD is defined and I guess I could die() if it is...I just was wondering if I could save the function pointer and insert mine in its place. Then I would call the original one and no one would be the wiser ;-)

        I want to create a module that you can just "use" and it would take care of "fixing" any AUTOLOAD requirements.

        Of course if I wanted to not have a dynamic function name none of this would be an issue...but what fun is that !