Thanks, that's a good idea. However I can't use it in my case, as there are too many methods in Log.pm to override - they all use couple of instance variables, which should have new values. Ideally this would work for me:
package Redirector;
my $new_obj;
# Redirect all methods calls of object A to object B.
sub redirect
{
my $new_obj = shift;
my @methods = @_ || 'all';
<instrument the methods so that Redirector::foo is called
instead of old_obj::foo>
}
sub print
{
my $real_obj = shift;
# Conveniently switch the object.
$new_obj->print(@_);
}
The issue with the above is keeping track of $new_obj.
This needs to be a package variable, and the class itself
has to be a singleton - unless a hash with package names
as keys. Any ideas ?
For now, deepcopying looks the simplest solution to me,
as the data to be traversed is small in size. But I think
your idea can be generalized to a Redirector CPAN module !
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.