Created
December 17, 2019 08:12
-
-
Save nipotan/bebc00afc353b3ab8e76f963b56cf0ac to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env perl | |
package InsideOut; | |
use strict; | |
use warnings; | |
our %obj; | |
sub new { | |
my $class = shift; | |
my $self = bless +{}, $class; | |
return $self; | |
} | |
sub foo { | |
my $self = shift; | |
if (defined $_[0]) { | |
$obj{$self + 0}{foo} = $_[0]; | |
} | |
return $obj{$self + 0}{foo}; | |
} | |
sub bar { | |
my $self = shift; | |
if (defined $_[0]) { | |
$obj{$self + 0}{bar} = $_[0]; | |
} | |
return $obj{$self + 0}{bar}; | |
} | |
sub DESTROY { | |
my $self = shift; | |
delete $obj{$self + 0}; | |
} | |
package main; | |
use Data::Dumper; | |
my $o = InsideOut->new; | |
$o->foo('UNKO'); | |
$o->bar('TIMPO'); | |
warn $o->foo; | |
warn $o->bar; | |
warn Dumper $o; | |
warn Dumper \%InsideOut::obj; | |
__END__ | |
UNKO at ./inside-out.pl line 44. | |
TIMPO at ./inside-out.pl line 45. | |
$VAR1 = bless( {}, 'InsideOut' ); | |
$VAR1 = { | |
'140539299111016' => { | |
'bar' => 'TIMPO', | |
'foo' => 'UNKO' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment