TreeValidator/Sugar.pm

filter: Statementstmt 100% 39 / 39 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 98.2% 56 / 57 CC 2 SCAR 1.4
CC
2
Cov
98%
leaf
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« TreeValidator/RepeatingBranch.pm ↑ Summary TreeValidator/Types.pm »
1 package Data::TreeValidator::Sugar;
2 {
3 3 $Data::TreeValidator::Sugar::VERSION = '0.04';
4 }
5 # ABSTRACT: Syntatic sugar for easily creating tree validators
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use aliased 'Data::TreeValidator::Branch';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use aliased 'Data::TreeValidator::Leaf';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use aliased 'Data::TreeValidator::RepeatingBranch';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use Data::TreeValidator::Constraints 'type';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
16 exports => [ qw( branch leaf repeating ) ],
17 3 };
18  
19 3 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use MooseX::Types::Moose qw( CodeRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 ▶sub _branch {
Subroutine _branch: called CC=1 SCAR=0.0
23 6 my ($class, $code) = @_;
24 6 my %children = $code->();
25 6 return $class->new( children => \%children );
26 }
27  
28 5 ▶sub branch (&;) {
Subroutine branch: called CC=1 SCAR=0.0
Pod documented
29 5 my ($code) = pos_validated_list(\@_,
30 { isa => CodeRef }
31 );
32 5 return _branch(Branch, $code);
33 }
34  
35 11 ▶sub leaf {
Subroutine leaf: called CC=2 SCAR=7.2
Pod documented
36 11 ▶ my @args = @_ == 1 ? (constraints => [ type($_[0]) ] )
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 11 11
37 : @_;
38 11 return Leaf->new(@args);
39 }
40  
41 1 ▶sub repeating (&;) {
Subroutine repeating: called CC=1 SCAR=0.0
Pod documented
42 1 my ($code) = pos_validated_list(\@_,
43 { isa => CodeRef }
44 );
45 1 return _branch(RepeatingBranch, $code);
46 }
47  
48 3 1;
49  
50  
51 __END__
« TreeValidator/RepeatingBranch.pm ↑ Summary TreeValidator/Types.pm »