adding methods to existing packages

Michael Stillwell mjs at
Thu Jan 12 16:15:25 GMT 2006

On 13 Jan 2006, at 02:29, Michel Rodriguez wrote:

> I don't know of anything that would help you directly, but you  
> could adapt XML::DOM::BagOfTricks ( 
> DOM-BagOfTricks/) to XML::LibXML... and then release the result.

Is there any particular reason why XML::DOM::BagOfTricks does:

   addText($node, 'This is some text');

instead of adding the method to XML::DOM::Node itself, so that you  

   $node->addText('This is some text');


I quite frequently take advantage of the fact that Perl lets you add  
methods to pre-existing classes.  I didn't think this was  
particularly unsafe (particularly if you don't mess with the innards  
of the object itself), and it's certainly convenient--but is there  
some good reason to avoid this?


+61 4 1308 5680

More information about the mailing list