package MyPackage; use strict; use Class::Flyweight; my $flyweight = Class::Flyweight->new(); sub new { return $flyweight->instantiate(bless {}, shift); } sub get_name { my $self = $flyweight->access(shift); return $self->{name}; } #### package MyPackage; use strict; my %instance; sub new { my $class = shift; my $obj = {}; my $name = "$obj"; $instance{$name} = $obj; return bless $name, class; } sub get_name { my $self = $instance{shift(@_)}; return $self->{name}; }