Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: Let a module call a sub of the caller

by moritz (Cardinal)
on Sep 07, 2012 at 10:02 UTC ( #992270=note: print w/replies, xml ) Need Help??

in reply to Re^2: Let a module call a sub of the caller
in thread Let a module call a sub of the caller

I am not that familiar with the processing phases BEGIN,INIT,END, that's why I asked. Is there a way to call the method at the END of execution of the caller?

END time is the same for all, so yes, that works:

# file package CallMe; use 5.010; use strict; use warnings; my @to_call; sub import { my ($self, @routines) = @_; my $call_package = (caller(1))[0]; push @to_call, $call_package. "::$_" for @routines; } END { no strict 'refs'; $_->() for @to_call; } 1;

And then in your script:

use 5.010; use lib '.'; use CallMe 'foo'; sub foo { say 42 } say 'in mainline';


in mainline 42

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992270]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-03-24 18:11 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (299 votes). Check out past polls.