Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Background: I have a requirement, that goes like this:
Log object provides the methods filehandle() and filename() to set the above values (and ofcourse, a $log->print()). I have a large codebase, that I'm modifying to enable parallel processing of various parts, with minimum changes to the codebase. So the call:$VAR1 = bless({'options' => {'filehandle' => bless( \*Symbol::GEN2, 'FileHandle' ), 'filename' => 'a.log'},}, 'Log' );
becomes:$self->do_task()
The problem is, $self has references to the log object at various places. I want all the output of the spawned process to go to a new file. So I do something like this:Process::spawn(\&do_task, $self);
But alas !, $self also has various other references to log, embedded deep inside, like:$new_log = new Log(filename => 'new.log'); $cur_log = $self->{log}; $self->{log} = $new_log; Process::spawn(\&do_task, $self); # This runs in background. $self->{log} = $cur_log; # Restore.
...etc. Since these log objects are created in the parent, at various points in the code, they all refer to the parent filehandle. I cannot change the parent code; So I need to do some gimmick to find out all these references to Log and replace them with $new_log.$self->{system}->{log}, $self->{filecache}->{system}->{log}
Anybody can provide a more enlightened solution ? Any hints to how I can develop Devel::ObjSearch ? (I plan to steal code from Data::Dumper, or implement a hook in dumper, if possible).@ref = Devel::ObjSearch($self, sub { return UNIVERSAL::isa($_[0], 'Log'); }); foreach (@ref) { $_->filename('new.log'); $_->filehandle($new_log); } .. spawn() ..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching for an object reference
by Mostly Harmless (Initiate) on Jul 05, 2005 at 05:52 UTC | |
|
Re: searching for an object reference
by simonm (Vicar) on Jul 05, 2005 at 18:10 UTC | |
by Mostly Harmless (Initiate) on Jul 06, 2005 at 08:08 UTC | |
by simonm (Vicar) on Jul 08, 2005 at 23:52 UTC | |
by simonm (Vicar) on Jul 09, 2005 at 00:24 UTC | |
by pemungkah (Priest) on Jul 06, 2005 at 01:20 UTC | |
by Mostly Harmless (Initiate) on Jul 06, 2005 at 07:38 UTC |