in reply to Re^3: Overridding subroutines called in private subroutines
in thread Overridding subroutines called in private subroutines
It's really just a nit, but you're leaking an alias to @Foo::Bar::ISA. I also use BEGIN {} instead of {} inlined modules. I'd write your program as:
#!/usr/bin/perl use strict; use warnings; BEGIN { package Foo; sub method { routine(); } sub routine { return __PACKAGE__; } } BEGIN { package Foo::Bar; our @ISA = qw( Foo ); sub routine { return __PACKAGE__; } sub method { no warnings 'redefine'; # Temporarily override routine() in the parent class. local *Foo::routine = \&routine; # Delegate to parent method. my $self = shift; $self->SUPER::method(@_); } } print "Foo: ", Foo->method, "\n"; print "Foo::Bar: ", Foo::Bar->method, "\n"; print "Foo: ", Foo->method, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Overridding subroutines called in private subroutines
by TGI (Parson) on Oct 07, 2008 at 18:42 UTC | |
by ikegami (Patriarch) on Oct 08, 2008 at 01:11 UTC |