Articulate/Validation.pm

filter: Statementstmt 95.8% 23 / 24 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 94.1% 32 / 34 CC 3 SCAR 5.8
CC
3
Cov
96%
validate
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.8
« Articulate/Authorisation/OwnerOverride.pm ↑ Summary Articulate/Construction.pm »
1 package Articulate::Validation;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 with 'Articulate::Role::Component';
8 6 ▶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($item) 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 7 ▶ coerce => sub { instantiate_array @_ }
Subroutine __ANON__: called CC=1 SCAR=0.0
41 6 );
42  
43 5 ▶sub validate {
Subroutine validate: called CC=3 SCAR=11.0
Pod documented
44 5 my $self = shift;
45 5 my $item = shift;
46 5 foreach my $validator ( @{ $self->validators } ) {
47 2 my $result = $validator->validate($item);
48 2 ▶ return $result unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 1 1 2
49 }
50 4 return 1;
51 }
52  
53 6 1;
« Articulate/Authorisation/OwnerOverride.pm ↑ Summary Articulate/Construction.pm »