Skip to content

Instantly share code, notes, and snippets.

@foursixnine
Last active December 13, 2016 11:34
Show Gist options
  • Save foursixnine/0ea0bf80765370702b2e44ffdbe79c8e to your computer and use it in GitHub Desktop.
Save foursixnine/0ea0bf80765370702b2e44ffdbe79c8e to your computer and use it in GitHub Desktop.
Module export test
package PackageTesting::A;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT = qw(a b);
sub whowasi { ( caller(2) )[3] }
sub a {
my ($called_from) = whowasi();
my $var = shift;
print "Calling PackageTesting::A::a with $var called from: $called_from\n";
b("Within PackageTesting::A::a");
}
sub b {
my ($called_from) = whowasi();
my $var = shift;
print "Calling PackageTesting::A::b with $var called from: $called_from\n";
}
1;
package PackageTesting::B;
use strict;
use warnings;
use Exporter qw(import);
our @EXPORT = qw(main b);
sub whowasi { ( caller(2) )[3] }
sub main {
my ($called_from) = whowasi();
my $var = shift;
print "Calling PackageTesting::B::Main with $var called from: $called_from\n";
}
sub b {
my ($called_from) = whowasi();
my $var = shift;
print "Calling PackageTesting::B::b with $var called from: $called_from\n";
}
1;
Calling PackageTesting::A::a with : A should be from PackageTesting::A called from: main::test_sub
Calling PackageTesting::A::b with Within PackageTesting::A::a called from: PackageTesting::A::a
Calling PackageTesting::B::Main with : Main should be from PackageTesting::B called from: main::test_sub
Calling PackageTesting::B::b with : B should be from PackageTesting::B called from: main::test_sub
use PackageTesting::A;
use PackageTesting::B;
sub test_sub{
a(": A should be from PackageTesting::A");
main(": Main should be from PackageTesting::B");
b(": B should be from PackageTesting::B");
}
test_sub();
@okurz
Copy link

okurz commented Dec 13, 2016

now try to call B::b from A::b and call A::a from B::main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment