Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Let a module call a sub of the caller

by clueless newbie (Friar)
on Sep 07, 2012 at 12:00 UTC ( #992295=note: print w/ replies, xml ) Need Help??


in reply to Let a module call a sub of the caller

Does this do what you want?

#!/usr/bin/perl use strict; use warnings; use v5.10; sub YadaYada { say "YadaYada"; }; use Xyzzy (\&YadaYada); say "Executing ".__PACKAGE__; INIT { say __PACKAGE__."::INIT"; }; END { say __PACKAGE__."::END"; };
package Xyzzy; use Data::Dumper; use strict; use warnings; use v5.10; my $external; sub import { shift; $external=$_[0]; }; say "Executing ".__PACKAGE__; INIT { say __PACKAGE__."::INIT"; $external->(); }; END { say __PACKAGE__."::END"; }; 1;

yields

Executing Xyzzy Xyzzy::INIT YadaYada main::INIT Executing main main::END Xyzzy::END


Comment on Re: Let a module call a sub of the caller
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-07-12 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (239 votes), past polls