| 1 | package Params::Validate::Dependencies::Documenter; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 12 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 12 | ▶ | use vars qw($VERSION); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 12 | $VERSION = '1.01'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 12 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | # sets a magic flag in P::V::D that the code-refs use to tell | ||||||||||||||
| 12 | # whether they should document themselves or validate, then | ||||||||||||||
| 13 | # calls the code-ref | ||||||||||||||
| 14 | sub _document { | ||||||||||||||
| 15 | 74 | ▶ | my $sub = shift(); | ||||||||||||
|
Subroutine
_document: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 74 | local $Params::Validate::Dependencies::DOC = $sub; | |||||||||||||
| 17 | 74 | $sub->({}); | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | # gets passed the list of options for this validator, and spits | ||||||||||||||
| 21 | # out doco, recursing as necessary | ||||||||||||||
| 22 | sub _doc_me { | ||||||||||||||
| 23 | 71 | ▶ | my $sub = shift; | ||||||||||||
|
Subroutine
_doc_me: called CC=2 SCAR=6.9
| |||||||||||||||
| 24 | 71 | my $list = {@_}->{list}; | |||||||||||||
| 25 | 71 | (my $name = $sub->name()) =~ s/_/ /g; | |||||||||||||
| 26 | |||||||||||||||
| 27 | my @list = ( | ||||||||||||||
| 28 | 142 | (map { (my $t = $_) =~ s/'/\\'/g; "'$t'" } grep { !ref($_) } @{$list}), # scalars first, quoted | |||||||||||||
| 29 | 68 | (grep { ref($_) } @{$list}) # then code-refs | |||||||||||||
| 30 | ); | ||||||||||||||
| 31 | |||||||||||||||
| 32 | return | ||||||||||||||
| 33 | $name.' ('. | ||||||||||||||
| 34 | ( | ||||||||||||||
| 35 | $#list > 0 | ||||||||||||||
| 36 | 68 | ▶ | ? join(', ', map { _doc_element($_) } @list[0 .. $#list - 1]). | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | " ".$sub->join_with().' '._doc_element($list[-1]) | ||||||||||||||
| 38 | : _doc_element($list[0]) | ||||||||||||||
| 39 | ). | ||||||||||||||
| 40 | ')'; | ||||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | # passed an option, returning it if it's scalar, otherwise | ||||||||||||||
| 44 | # calling its ->_document() method | ||||||||||||||
| 45 | sub _doc_element { | ||||||||||||||
| 46 | 181 | ▶ | my $element = shift; | ||||||||||||
|
Subroutine
_doc_element: called CC=3 SCAR=11.0
| |||||||||||||||
| 47 | 181 | ▶ | if(!ref($element)) { return $element } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 48 | 38 | elsif(blessed($element)) { return $element->_document(); } | |||||||||||||
| 49 | 1 | else { return '[coderef does not support autodoc]' } | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 12 | 1; | |||||||||||||