Created
March 22, 2013 10:24
-
-
Save Shinpeim/5220327 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| package Dynamic { | |
| sub new { | |
| bless {}, shift; | |
| } | |
| sub dump { | |
| my ($self) = @_; | |
| for my $key (keys %{$self}) { | |
| print "$key : @{[$self->{$key}]}\n"; | |
| } | |
| } | |
| sub AUTOLOAD { | |
| my ($self, $value) = @_; | |
| my $key = our $AUTOLOAD; | |
| $self->{$key} = $value if defined $value; | |
| return $self->{$key}; | |
| } | |
| } | |
| my $dynamic = Dynamic->new; | |
| $dynamic->nyan("mew"); | |
| $dynamic->wan("bow"); | |
| $dynamic->dump; | |
| # 出力結果 | |
| # Dynamic::wan : bow | |
| # Dynamic::nyan : mew |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment