use strict; use warnings; {package This; sub new{ my ($class, %att )=@_; return bless {%att}, $class; } sub with_timeout{ my ($self, $timeout) = @_; $timeout or die "Timeout not specified"; return bless {%$self, TIMEOUT=>$timeout},__PACKAGE__; } sub do_work{ my ($self) = @_; for my $k(sort keys %$self){ print "$k \t=>" . ( $self->{$k}||"Undef*") . "\n"; } } 1; } my $t = This::->new (CANDY=>'Mint'); print "-- First call - no TIME--\n"; $t->do_work(); print "-- adding time--\n"; $t->with_timeout(10)->do_work(); print "-- this should not have it--\n"; $t->do_work();