File Coverage

blib/lib/Test/Proto/Repeatable.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 15 16 93.7


line stmt bran cond sub pod time code
1             package Test::Proto::Repeatable;
2 5     5   1561 use strict;
  5         11  
  5         164  
3 5     5   26 use warnings;
  5         10  
  5         120  
4 5     5   24 use Moo;
  5         9  
  5         36  
5              
6             has 'contents',
7             is => 'rw',
8             default => sub { Test::Proto::Series->new(@_) };
9              
10             has 'min',
11             is => 'rw',
12             default => sub { 0 };
13              
14             has 'max',
15             is => 'rw',
16             default => sub { undef };
17              
18             around 'min', 'max', 'contents' => \&Test::Proto::Common::chainable;
19              
20             sub BUILDARGS {
21 13     13 0 3745 my $class = shift;
22 13         304 return { contents => Test::Proto::Series->new(@_) };
23             }
24              
25             =head1 NAME
26              
27             Test::Proto::Repeatable - represent a repeatable element or series in array validation
28              
29             =head1 SYNOPSIS
30              
31             pArray->contains_only(pRepeatable('a', 'b'));
32             # will validate ['a', 'b'] and ['a', 'b', 'a', 'b'] as true
33              
34             Used in array validation to represent a sequence qhich must be present in its entirety. Can contain, or be contained by, a L or a L.
35              
36             =head1 METHODS
37              
38             =head3 new
39              
40             Each argument is another element in the series. NB: A series is automatically created to hold all the contents.
41              
42             =head3 contents
43              
44             die unless exists $alternation->contents->[0];
45              
46             A chainable getter/setter method for the contents of the series.
47              
48             =head3 min
49              
50             my $pRepeatable = pRepeatable('foo')->min(2);
51             my $min = $pRepeatable->min;
52              
53             Sets and/or returns the minimum number of occurrences required.
54              
55             =head3 max
56              
57             my $pRepeatable = pRepeatable('foo')->max(2);
58             my $max = $pRepeatable->max;
59              
60             Sets and/or returns the maximum number of occurrences permitted.
61              
62             =cut
63              
64             1;