Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Pre/post subroutine assertions and documentation module?

by suaveant (Parson)
on Jan 12, 2012 at 16:40 UTC ( #947580=perlquestion: print w/ replies, xml ) Need Help??
suaveant has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a module to assign pre and post assertions to subroutines in development and pre-production but be able to be skipped on production, and also to double as documentation (or at least facilitate documentation) of inputs and outputs.

I've found Sub::Assert which looks promising except for the documenting part (which maybe I could work in somehow) and Sub::Spec which looks interesting but not at all what I want.

Anyone know of anything useful?

                - Ant
                - Some of my best work - (1 2 3)

Comment on Pre/post subroutine assertions and documentation module?
Replies are listed 'Best First'.
Re: Pre/post subroutine assertions and documentation module?
by educated_foo (Vicar) on Jan 12, 2012 at 17:29 UTC
    Smart::Comments may help -- what do you mean by "documentation"? POD? Comments? Code examples?
      I want something that verifies incoming parameters (usually a hash ref, so sub-keys) are correct, and also is designed in such a way that a short blurb can be added for viewing/extracting that describes the inputs.

      It seems an obvious conjoining, if you are verifying inputs why not also document them, or vice versa. I may end up using something like Smart::Comments/Getopt::Euclid as a starting point for something of my own.

                      - Ant
                      - Some of my best work - (1 2 3)

        These subs... are they intended to be called as functions, or as methods? If the latter, then something like Method::Signatures, or MooseX::Declare might be an idea.

Re: Pre/post subroutine assertions and documentation module?
by TJPride (Pilgrim) on Jan 12, 2012 at 17:59 UTC
    Couldn't you just put in extra lines of code with a test flag?
    sub myFunc { my ($x, $y) = @_; ### Assertion if ($::test) { ### Do something } ### Rest of sub }

    Might help if you could give an example of what a simple sub might do with and without an assertion.

      If you do this, you want to make $::test a constant, so it can be optimized away when you're done testing, e.g.
      use constant TEST => $ENV{TEST}; if (TEST) { ... }
      I can think of a number of ways I could do it in a custom manner, I'm just making sure I'm not reinventing anything.

                      - Ant
                      - Some of my best work - (1 2 3)

Re: Pre/post subroutine assertions and documentation module?
by Khen1950fx (Canon) on Jan 12, 2012 at 19:15 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://947580]
Approved by jfroebe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2015-07-30 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls