| 1 | package Data::TreeValidator::Branch; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 5 | $Data::TreeValidator::Branch::VERSION = '0.04'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | # ABSTRACT: A branch of tree validation | ||||||||||||||||||||
| 6 | 5 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 5 | ▶ | use Data::TreeValidator::Types qw( HashTree Node ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 5 | ▶ | use MooseX::Types::Moose qw( CodeRef Maybe Str ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 5 | ▶ | use MooseX::Types::Structured qw( Map ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 5 | ▶ | use aliased 'Data::TreeValidator::Result::Branch' => 'Result',; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 5 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 5 | with 'Data::TreeValidator::Node'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | has 'children' => ( | ||||||||||||||||||||
| 19 | isa => Map[ Str, Node ], | ||||||||||||||||||||
| 20 | 4 | ▶ | default => sub { {} }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 5 | traits => [ 'Hash' ], | |||||||||||||||||||
| 22 | handles => { | ||||||||||||||||||||
| 23 | children => 'values', | ||||||||||||||||||||
| 24 | child_names => 'keys', | ||||||||||||||||||||
| 25 | add_child => 'set', | ||||||||||||||||||||
| 26 | child => 'get', | ||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | has 'cross_validator' => ( | ||||||||||||||||||||
| 31 | isa => CodeRef, | ||||||||||||||||||||
| 32 | traits => [ 'Code' ], | ||||||||||||||||||||
| 33 | 15 | ▶ | default => sub { sub {} }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 5 | handles => { | |||||||||||||||||||
| 35 | cross_validate => 'execute', | ||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 12 | ▶ | sub process { | ||||||||||||||||||
|
Subroutine
process: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 40 | 12 | my $self = shift; | |||||||||||||||||||
| 41 | 12 | my ($tree) = pos_validated_list([ shift ], | |||||||||||||||||||
| 42 | { isa => Maybe[HashTree], coerce => 1 } | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | 12 | my %args = @_; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | my $result = Result->new( | ||||||||||||||||||||
| 47 | input => $tree, | ||||||||||||||||||||
| 48 | results => { | ||||||||||||||||||||
| 49 | map { | ||||||||||||||||||||
| 50 | 12 | ▶ | my $process = $tree->{$_} || $args{initialize}->{$_}; | ||||||||||||||||||
|
Condition100%3/3
$tree->{$_} || $args{'initialize'}{$_}
MC/DC100%2/2
$tree->{$_} || $args{'initialize'}{$_}
$tree->{$_}
$args{'initialize'}{$_}
Truth table100%3/3
A || B
A= $tree->{$_}B= $args{'initialize'}{$_}
| |||||||||||||||||||||
| 51 | 27 | $_ => $self->child($_)->process($process) | |||||||||||||||||||
| 52 | } $self->child_names | ||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | # XXX Try::Tiny doesn't work here -- why? | ||||||||||||||||||||
| 57 | 12 | eval { | |||||||||||||||||||
| 58 | 12 | $self->cross_validate($result->clean); | |||||||||||||||||||
| 59 | }; | ||||||||||||||||||||
| 60 | 12 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 1 | $result->add_error($@); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 12 | return $result; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 5 | 1; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||