Skip to content

Instantly share code, notes, and snippets.

@akimacho
Last active August 29, 2015 14:24
Show Gist options
  • Save akimacho/cc076786f24e0c5865b4 to your computer and use it in GitHub Desktop.
Save akimacho/cc076786f24e0c5865b4 to your computer and use it in GitHub Desktop.
standard function "caller"
use strict;
use warnings;
use utf8;
use Piyo;
use DDP {deparse => 1,};
warn "I'm " . __PACKAGE__ . "\n";
my @context = caller;
p @context;
my $p = Piyo->new;
__END__
I'm main
[]
I'm Piyo
I'm Hoge
[
[0] "Piyo",
[1] "Piyo.pm",
[2] 11
]
[
[0] "main",
[1] "caller.pl",
[2] 10
]
package Hoge;
use strict;
use warnings;
use utf8;
use DDP {deparse => 1,};
sub new {
my ($class, %args) = @_;
warn "I'm " . __PACKAGE__ . "\n";
my @context = caller;
p @context;
bless \%args, $class;
}
1;
package Piyo;
use strict;
use warnings;
use utf8;
use Hoge;
use DDP {deparse => 1,};
sub new {
my ($class, %args) = @_;
warn "I'm " . __PACKAGE__ . "\n";
$args{Hoge} = Hoge->new;
my @context = caller;
p @context;
bless \%args, $class;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment