in reply to Is there a way to dynamically copy subroutine from one module to another?
use strict; package TestA; sub new { bless {}, shift; } sub doit { my $self = shift; warn 'A::doit'; } package TestB; use base 'TestA'; sub doit { my $self = shift; warn 'B::doit'; $self->SUPER::doit(); } package TestC; use base 'TestB'; package TestD; sub new { bless {}, shift; } sub doit { my $self = shift; warn 'D::doit'; } package main; my $c = TestC->new; *TestC::doit = sub { my $self = shift; local *TestA::doit = \&TestD::doit; $self->TestB::doit(); }; $c->doit();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is there a way to dynamically copy subroutine from one module to another?
by OlegG (Monk) on Feb 13, 2011 at 10:30 UTC |