EchoAngel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have this language specific parser and there are many functions in this and when called , it will return a complex hash structure. I really want to update the functions to include a new hash branch with in the return output (for this new task). However, I am afraid which perl scripts this might affect. Is there another way then just copying this package? In the future, is there any way to prevent this?

Replies are listed 'Best First'.
Re: update package question
by moot (Chaplain) on Mar 04, 2005 at 14:58 UTC
    If the package models a class, can you not just sub-class it and override the functions for which you wish to modify behaviour?

    Existing scripts can continue to use the base class and new scripts can use the new (sub) class.

Re: update package question
by holli (Abbot) on Mar 04, 2005 at 15:04 UTC
    If it is an OO-module, then you can simply subclass it. Say your Parser is called Foo::Parser. Then you can create a class My::Foo::Parser and override all methods you like. Looks basically like this:
    package My::Foo::Parser; use base (Foo::Parser); sub new { my $class = shift; my $self = $class->SUPER::new (@_); #do your own constructor_code here return $self; } sub method { my $self = shift; my $complexHash = $self->SUPER::method(); #do your own stuff here return $complexHash; }
    See the various OO-Tutorials for more about subclassing.

    Hope that helps.


    holli, /regexed monk/
Re: update package question
by Taulmarill (Deacon) on Mar 04, 2005 at 15:03 UTC
    you could use the old package by a new one and use it as base class. old methods (aka subroutines) can be accessed by SUPER class or by the NEXT module (which is my favorite).