|XP is just a number|
forks.pm finally supports : shared attribute, correctly?by liz (Monsignor)
|on Sep 27, 2003 at 07:18 UTC||Need Help??|
liz has asked for the
wisdom of the Perl Monks concerning the following question:
The forks module (drop-in replacement for Perl ithreads for unthreaded Perl 5.6 and higher) only missed one feature until this morning: the ": shared" attribute.
Some background: the forks::shared module already had a "_share" subroutine that only needs a reference to the variable (either a scalar, array or hash) to be shared. This subroutine basically does a tie on the variable.
So the attribute handler only needed to get the reference and act on that. No further attribute data needs to be kept.
Yesterday, I finally grokked attributes.pm, particularly this bit:
and created the following code:
Now, what I'm wondering about is whether I should capture the code reference of the "old" handler, and pass on the remaining attributes to it. Or whether that this is somehow handled automatically.
If it is not needed, I'd like to remove it of course. But if it is needed and people use other attribute handlers, than that may cause the other attribute handlers not to be called and thus break other modules.
If this is a piece of solid code, I was thinking of using this approach for other attributes and/or generalizing this into a module.
Finally, yes I know about Attribute::Handlers, but since I'm only interested in tieing the reference, it seems like overkill to me. Especially looking at the compactness of the code I've created now.