Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by Damian (784) on 2005.10.29 5:24 (#44246)
    To be fair, Damian responded to my query, but he didn't answer my question. He gave more an example of how submethods are used, rather than why they are used.
    Subroutines are useful inside classes, for factoring class-specific implementation details out of the class's methods. The main reason they're useful is because they're not part of the object interface, and are not inherited. So they can be used purely as encapsulated implementation.

    But factoring method implementations out into a subroutines is also extremely annoying, because a subroutine doesn't provide the internal conveniences that a method does. In particular, it doesn't have an invocant and so you can't call $.attrs or &.methods. Instead you would have to pass the invocant to the subroutine call as an argument and then call accessors and methods explicitly through that argument.

    So we need a mechanism that is externally (i.e. from a class interface point-of-view) a subroutine, but internally has the features of a method (i.e. has an invocant). Since it's externally sub-like but internally method-like, we call this useful construct a submethod.