#!/usr/bin/perl { package Do::Stuff; use warnings; use strict; use P; sub setup{my $p=shift; my $c=ref $p||$p; bless $p={}, $c unless ref $p; $p; } #local *asub; *asub = sub { P "asub called with %d param%s%s.", 0+@_, -1+@_?"s":"", @_ ? P(" (%s)", \@_) : ""; 1}; local *bsub; sub do_internal_sub() { my $p=shift; *bsub = sub{ P "Called with %d param%s%s.", 0+@_, @_-1?"s":"", @_ ? P(" (%s)", \@_) : ""}; P "calling bsub: %s", &bsub("one",2,"III"); } sub stuff() { my $p=shift; P "In stuff"; eval {&asub("stuff")}; if ($@) { P "asub call gave: $@"; } eval {&bsub("more", "stuff")}; if ($@) { P "bsub call gave: $@"; } } 1} package main; use warnings; use strict; use P; my $p=Do::Stuff->setup; P "calling stuff..."; $p->stuff; P "calling internal_sub: %s", $p->do_internal_sub;