http://qs321.pair.com?node_id=136161

rfb has asked for the wisdom of the Perl Monks concerning the following question: (object-oriented programming)

Would it be possible to override a method this way?
sub GD::Graph::axestype::create_x_label {
or \&GD::Graph::axestype::create_x_label = sub { I know these doesnt work because I've tried, is there another way like this?

-ryan

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: overriding a methods.
by merlyn (Sage) on Jan 04, 2002 at 18:28 UTC
    The first one works fine, provided you understand that you're compiling code which has to be compiled after the original method is compiled. So, it's fine after a use that pulls in the other module. You'll probably get a "redefining ___" warning though. The typeglob assignment has also worked for me in the past.
Re: overriding a methods.
by belg4mit (Prior) on Jan 04, 2002 at 04:54 UTC
    You could typeglob...

    *GD::Graph::axestype::create_x_label = sub {...}