Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created May 13, 2014 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/5e61b92f56c4d2c1bc4c to your computer and use it in GitHub Desktop.
Save hitode909/5e61b92f56c4d2c1bc4c to your computer and use it in GitHub Desktop.
メソッドが呼ばれたときに同名のフィールドがあったらもしかしてって言いながら死ぬやつ
package Mosikasite {
sub new {
my ($class) = @_;
bless {}, $class;
}
sub AUTOLOAD {
my ($self) = @_;
my $method = (split '::', $AUTOLOAD)[-1];
if (@_ == 1 && exists $self->{$method}) {
die "もしかして:->{$method}";
} else {
die;
}
}
};
my $m = Mosikasite->new;
$m->{hoge} = 1;
$m->hoge;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment