in reply to Re^2: replace object methods at runtime
in thread replace object methods at runtime

Sure ,

Thank you for indulging me. I've seen this kind of facility requested (or described in other languages), but I've never really seen a non-hypothetical use-case for it. And I'm always more interested in real use cases than hypothetical ones.

That said, without fully understanding the architecture you are describing, it sounds like a complex way of coding a simple boolean condition? Essentially:

sub method { my( $self, @args ) = @_; ... if( $self->_pipeExistsAndIsGood ) { ## communicate with pipe } else { ## $self->_forkAndStorePipe(); } }

I can see that 'dynamic method rewriting' is a way to avoid a boolean test, which might provide a small efficiency gain, but trading that for the complexity and 'action at a distance' involved runtime determination of the code behind a method, along with parent & child time forked instances, just seems like a recipe for complex and difficult to trace bugs and failures.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: replace object methods at runtime
by karavelov (Monk) on Jun 25, 2008 at 17:53 UTC

    Yes, the "boolean test" method is more simple and maintainable. As a performance it is equal or better to the approach with wrappers/AUTOLOAD because you always must check some condition in the wrapper.

    I see that if we have symtables per instance this will hurt the performance of all objects and the gain in flexibility is minimal. The suggested re-blessing method seems more general and could do the same without penalty for other objects.

    Thanks
    luben