Params/Validate/Dependencies/Documenter.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 47 / 47 SCAR 13.9
CC
4
Cov
100%
_doc_element
3.0
_doc_me
2.0
BEGIN
1.0
CRAP 4.0
« Data/Domain/Dependencies.pm ↑ Summary
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.41';
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 77 ▶ my $sub = shift();
Subroutine _document: called CC=1 SCAR=0.0
16 77 local $Params::Validate::Dependencies::DOC = $sub;
17 77 $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 73 ▶ my $sub = shift;
Subroutine _doc_me: called CC=2 SCAR=6.9
24 73 my $list = {@_}->{list};
25 73 (my $name = $sub->name()) =~ s/_/ /g;
26  
27 my @list = (
28 149 (map { (my $t = $_) =~ s/'/\\'/g; "'$t'" } grep { !ref($_) } @{$list}), # scalars first, quoted
29 70 (grep { ref($_) } @{$list}) # then code-refs
30 );
31
32 return
33 $name.' ('.
34 (
35 $#list > 0
36 70 ▶ ? join(', ', map { _doc_element($_) } @list[0 .. $#list - 1]).
Branch: 1 branch
BranchTrueFalseTotal
$#list > 0 ? : 58 12 70
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 189 ▶ my $element = shift;
Subroutine _doc_element: called CC=3 SCAR=11.0
47 189 ▶ if(!ref($element)) { return $element }
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $element) { } 149 40 189
elsif (builtin::blessed($element)) { } 39 1 40
48 39 elsif(blessed($element)) { return $element->_document(); }
49 1 else { return '[coderef does not support autodoc]' }
50 }
51  
52 12 1;
« Data/Domain/Dependencies.pm ↑ Summary