in reply to Indent, anonymous sub, or lexical sub for module private code?

Is an anonymous sub the right thing here?

A named subroutine will work (its what you want), just give it a prefix of "_", make it sub _private_by_convention { ... }

This signals to all who load your module not to rely on sub _private_by_convention because its not part of the public api

I thought this was mentioned in See perlstyle, perlstyle but its not, it is however mentioned in Perl::Critic::Policy::Subroutines::ProtectPrivateSubs and Perl::Critic::Policy::Subroutines::ProhibitUnusedPrivateSubroutines

Yes, too much indentation isn't exactly skimmable code :)

Also, "Code reuse question" has got two stopwords ("code" and "question"), all nodes of type perlquestion are questions about code :) see How do I compose an effective node title?

I don't have a much better

  • Comment on Re: Code reuse question (indent another level or non global subroutine or anonymous or sub _private_by_convention)
  • Download Code

Replies are listed 'Best First'.
Re^2: Code reuse question (indent another level or non global subroutine or anonymous or sub _private_by_convention)
by 1s44c (Scribe) on Jul 31, 2014 at 14:24 UTC

    I didn't know that underscores were the convention for module code that should not be used outside the module. Now I do. That seems like the best good solution to my problem given the module code is already indented annoyingly far.

    I'm glad I asked this, the answers here have been very helpful. I'll come up with more descriptive node names in future.