{ package Foo; sub foo; sub bar { __PACKAGE__ }; # Handles &foo, and fallback for everything. AUTOLOAD { __PACKAGE__ } ## or, if it should can() everything: #use Class::AUTOCAN sub { # return sub { __PACKAGE__ }; #}; } { package Foo::Bar; our @ISA = Foo::; sub bar; # Lazily overload bar. # Handle &bar and provide fallback for &foo and &BAR. # &foo should not be called here since &foo is declared # and should be handled by Foo::AUTOLOAD. If &foo should # be handled here then a stub should have been declared # here. use Class::AUTOCAN sub { my $self = shift; my ($method) = @_; return sub { __PACKAGE__ } if $method eq 'foo'; # Beware: stub. return sub { __PACKAGE__ } if $method eq 'bar'; return sub { __PACKAGE__ } if $method eq 'BAR'; return; # Let Foo worry about other methods. }; } my $o = Foo::Bar::; for my $method (qw/ foo bar BAR abc /) { my $code = $o->can($method); printf "%s => %-8s (can: %-8s)\n", $method, $o->$method, ($code ? $o->$code : ''), ; } __END__ foo => Foo (can: Foo ) bar => Foo::Bar (can: Foo::Bar) BAR => Foo::Bar (can: Foo::Bar) abc => Foo (can: )