package Class_Inside_Out; use Scalar::Util qw(refaddr); my %name; my %colour; my %age; sub new { my $key = bless \(my $dummy) => shift; $$key = refaddr ( $key ); my %args = @_; $name {$$key} = $args {name} || "abigail"; $colour {$$key} = $args {colour} || "pink"; $age {$$key} = $args {age} || 100; $key; } sub name { my $key = shift; $name {$$key} = shift if @_; $name {$$key}; } sub colour { my $key = shift; $colour {$$key} = shift if @_; $colour {$$key}; } sub age { my $key = shift; $age {$$key} = shift if @_; $age {$$key}; } sub format { my $key = shift; join " " => $name {$$key}, $colour {$$key}, $age {$$key}; } #### Rate closure inside_out traditional closure 177/s -- -43% -45% inside_out 313/s 76% -- -3% traditional 321/s 81% 3% --