in reply to Re^3: Overriding 'static' methods of a perl package
in thread Overriding 'static' methods of a perl package

Ok.

The line 'use parent -norequire => "Parent"' generates a compilation error.

I guess I'm still dragging too much Java baggage along with me. In my 'real life' implementation of this idea, the 'Parent' package contains an elaborate routine that calls a number of supporting subroutines to control its operation. The idea was to override the supporting subroutines to create new behaviors.

I was trying to avoid making it truly OO as there was only one use of the class after it was created.

  • Comment on Re^4: Overriding 'static' methods of a perl package

Replies are listed 'Best First'.
Re^5: Overriding 'static' methods of a perl package
by Corion (Patriarch) on Sep 16, 2008 at 15:37 UTC

    As you keep the exact text of "compilation error" to yourself, I won't be able to help you with that. The most likely reason is that parent.pm is not installed on your machine. You could try the substitute base.pm that is distributed with older versions of Perl.

    I can only iterate it again. If you want to use features such as "inheritance", you'll have to use the object syntax everywhere.

    Of course, for customizing the behaviour of the One Big Subroutine, it's likely easier to pass it a callback and in its absence to use a default routine:

    package Parent; sub name { return 'Parent' }; sub identify { my (%options) = @_; $options{ get_name } ||= \&name; print "Hello " . $options{ get_name }->() . "\n"; }; package Child; sub identify { Parent::identify( get_name => sub { 'Child' }); }; 1;
      DOH! (mental head slap)

      I didn't even think of that. I was so fixated on making 'inheritance' work the way I wanted to, I missed the big picture.

      The 'compliation error' was the fact that parent.pm was not installed on the system. Do you consider 5.8.5 'old'?

      Thanks for all your help and the excellent suggestion.

        Do you consider 5.8.5 'old'?

        For something released four years ago that's probably an acceptable declaration.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.