in reply to (How) Do you document/test your private subroutines?
Because Perl doesn't have true method privacy, Perl developers can mean more than one thing when they talk about a "private" sub/method.
Sometimes they mean a sub which is not to be used at all outside the module it was defined in. In these cases, I'd suggest you should at least consider making it into a coderef instead of a named sub, so that it cannot be used elsewhere (PadWalker trickery notwithstanding).
my $run_end = sub { my $self = shift; ...; }; sub some_public_method { my $self = shift; ...; $self->$run_end(); }
Unless it's really obvious what it does, document its purpose in comments. The question of whether you should test it or not becomes moot — it cannot be used outside the module, so your test scripts can't directly touch it anyway. Any problems which affect the rest of the module should be exposed when you test the public API. Any problems which don't affect the rest of the module probably don't matter.
Other times, there are functions you have in one class/module that are not intended to be called by end users, but might be called by other classes/modules within your distribution, or overridden by subclasses within your distribution. This is racism. Don't do this. Well, okay, not racism, but that got your attention. It's still discriminating against other modules/classes because they weren't written by you. If it's a function/method which you have found useful/necessary, then other people might find it useful/necessary too, so make it part of your public API. Okay, so maybe it's pretty obscure and 99% of end users won't need it, and you don't want it cluttering up your documentation, but in that case, mention it in a separate "ADVANCED API" section of the documentation (perhaps even in a separate pod file) or document it fully in the comments, making it clear that it's a supported albeit obscure part of your API.
See also: the middle part of my presentation at the 2014 London Perl Workshop (and there's a cringy video of it on YouTube too).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: (How) Do you document/test your private subroutines?
by afoken (Chancellor) on Nov 08, 2018 at 21:37 UTC | |
by tobyink (Canon) on Nov 12, 2018 at 14:31 UTC | |
by LanX (Saint) on Nov 12, 2018 at 16:50 UTC | |
by choroba (Cardinal) on Nov 12, 2018 at 16:56 UTC | |
by tobyink (Canon) on Nov 13, 2018 at 19:02 UTC | |
by LanX (Saint) on Nov 12, 2018 at 17:41 UTC | |
by LanX (Saint) on Nov 12, 2018 at 17:00 UTC | |
Re^2: (How) Do you document/test your private subroutines?
by LanX (Saint) on Nov 09, 2018 at 00:47 UTC |