Articulate/Validation.pm

filter: Statementstmt 88.0% 22 / 25 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 82.8% 29 / 35 SCAR 11.2
CC
3
Cov
81%
validate
3.6
__ANON__
2.0
BEGIN
1.0
CRAP 3.1
« Articulate/Request.pm ↑ Summary Articulate/Role/Flow.pm »
1 package Articulate::Validation;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 with 'Articulate::Role::Component';
8 4 ▶use Articulate::Syntax qw(instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Articulate::Validation - ensure content is valid before accepting it.
13  
14 =head1 DESCRIPTION
15  
16 use Articulate::Validation;
17 $validation->validate($meta, $content) or throw_error;
18  
19 Validators should return a true argument if either a) The item is valid, or b) The validator has no opinion on the item.
20  
21 =head1 METHODS
22  
23 =head3 validate
24  
25 Iterates through the validators. Returns false if any has a false result. Returns true otherwise.
26  
27 =cut
28  
29 =head1 ATTTRIBUTES
30  
31 =head3 validators
32  
33 An arrayref of the classes which provide a validate function, in the order in which they will be asked to validate items.
34  
35 =cut
36  
37 has validators =>
38 is => 'rw',
39 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 3 ▶ coerce => sub { instantiate_array @_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
41  
42 sub validate {
43 2 ▶ my $self = shift;
Subroutine validate: called CC=3 SCAR=12.7
Pod documented
44 2 my $meta = shift;
45 2 my $content = shift;
46 2 foreach my $validator (@{ $self->validators }) {
47 0 my $result = $validator->validate($meta, $content);
48 0 ▶ return $result unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
49 }
50 2 return 1;
51 }
52  
53 4 1;
« Articulate/Request.pm ↑ Summary Articulate/Role/Flow.pm »