package Storage; sub new { return (bless { 'key 1' => 'default 1', 'key 2' => 'default 2', }, shift); } package InvoiceCalculator; sub new { my $O = bless {}, shift; $O->{'data'} = shift; return ($O); } sub calculate { my $O = shift; for my $k (sort keys %{ $O->{'data'} }) { printf ("%s -> %s\n", $k, $O->{'data'}->{ $k }); } return; } package Client; sub new { my $O = bless {}, shift; $O->{'data'} = new Storage (); return ($O); } sub getCalculator { my $O = shift; return (new InvoiceCalculator ($O->{'data'})); } package main; my $client = new Client; my $calc = $client->getCalculator(); $calc->calculate();