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