Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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?
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.

      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)

      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) { ... }
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 musing on the Monastery: (3)
As of 2014-09-20 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls