Skip to content

Instantly share code, notes, and snippets.

@niratama
Created February 19, 2015 06:40
Show Gist options
  • Save niratama/1b4dc2ee4cd7375ac58e to your computer and use it in GitHub Desktop.
Save niratama/1b4dc2ee4cd7375ac58e to your computer and use it in GitHub Desktop.
呼び出し元のサブルーチンを呼び出す
#!/usr/bin/env perl
use strict;
use warnings;
use MySub;
sub callback {
print "in main::callback($_[0])\n";
return "main::callback($_[0])";
}
MySub::test_sub('from main');
package MySub;
use strict;
use warnings;
use MySub2;
sub callback {
print "in MySub::callback($_[0])\n";
}
sub test_sub {
print "in MySub::test_sub($_[0])\n";
MySub2::test_sub('from MySub');
{
no strict 'refs';
&{(caller)[0].'::callback'}('from MySub')."\n";
}
}
1;
package MySub2;
use strict;
use warnings;
use Data::Dumper;
use MySub2;
sub test_sub {
print "in MySub2::test_sub($_[0])\n";
{
no strict 'refs';
&{(caller)[0].'::callback'}('from MySub2')."\n";
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment