Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: autoload and packages

by svad (Pilgrim)
on May 12, 2002 at 00:12 UTC ( [id://165962]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: autoload and packages
in thread AUTOLOAD and packages

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!

Replies are listed 'Best First'.
Re: Re: Re: Re: autoload and packages
by smackdab (Pilgrim) on May 12, 2002 at 01:22 UTC
    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 !

      if we'll see into perlref.pod and search for substring {CODE} and read around a bit, then we'll calmly understand that we're able to do following trick:
      use strict; package main; sub AUTOLOAD { return 'old-main-autoload'; } package mypackage; # let's capture that ::AUTOLOAD my $aasub = *{$::{AUTOLOAD}}{CODE}; # now let's, as we decided earlier, have it overloaded *::AUTOLOAD = sub { # here how we overload it: print "do first\n"; #call old one and print that returned value inside '[]' print '[', $aasub->(), "]\n"; print "do last\n"; }; package main; # again flurfish_sub();
      in my case output is
      do first [old-main-autoload] do last
      But my personal advice - you're moving to C-like area or even assembler code catching area when you will really soon will complicate logic.
      I think when you will see that code in your program then it is a good signal to redesign your code.
      :)

      Best wishes,
      Vadim.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://165962]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found