sub mock { my $self = shift; # ref count of the object +1 # code here } # $self goes out of scope, ref count of the object -1