Skip to content

Instantly share code, notes, and snippets.

@fukata
Last active December 18, 2015 15:49
Show Gist options
  • Save fukata/5806698 to your computer and use it in GitHub Desktop.
Save fukata/5806698 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
package Base;
sub new {
my ($class) = @_;
bless {}, $class;
}
sub pkg {
my ($self) = @_;
ref $self;
}
sub print_pkg {
my ($self) = @_;
print "ref=" . $self->pkg . ", __PACKAGE__=" . __PACKAGE__ . "\n";
}
package Hoge;
use base qw(Base);
package Hoge::Foo;
use base qw(Hoge);
package main;
Base->new->print_pkg;
Hoge->new->print_pkg;
Hoge::Foo->new->print_pkg;
=head description
$ perl package.pl
ref=Base, __PACKAGE__=Base
ref=Hoge, __PACKAGE__=Base
ref=Hoge::Foo, __PACKAGE__=Base
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment