File Coverage

blib/lib/Form/Factory/Feature/Control/MatchCode.pm
Criterion Covered Total %
statement 12 14 85.7
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 20 24 83.3


line stmt bran cond sub pod time code
1             package Form::Factory::Feature::Control::MatchCode;
2             $Form::Factory::Feature::Control::MatchCode::VERSION = '0.022';
3 1     1   505 use Moose;
  1         2  
  1         6  
4              
5             with qw(
6             Form::Factory::Feature
7             Form::Factory::Feature::Role::Check
8             Form::Factory::Feature::Role::Control
9             Form::Factory::Feature::Role::CustomControlMessage
10             );
11              
12 1     1   4818 use Carp ();
  1         2  
  1         126  
13              
14             # ABSTRACT: Greps the control value for correctness
15              
16              
17             has code => (
18             is => 'ro',
19             isa => 'CodeRef',
20             required => 1,
21             );
22              
23              
24 5     5 1 9 sub check_control { }
25              
26              
27             sub check {
28 1     1 1 2 my $self = shift;
29 1         35 my $control = $self->control;
30 1         3 my $value = $control->current_value;
31              
32 1 50       30 unless ($self->code->($value)) {
33 0         0 $self->control_error('the %s is not correct');
34 0         0 $self->result->is_valid(0);
35             }
36              
37 1 50       40 $self->result->is_valid(1) unless $self->result->is_validated;
38             }
39              
40             __PACKAGE__->meta->make_immutable;
41              
42             __END__
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             Form::Factory::Feature::Control::MatchCode - Greps the control value for correctness
51              
52             =head1 VERSION
53              
54             version 0.022
55              
56             =head1 SYNOPSIS
57              
58             has_control even_value => (
59             control => 'text',
60             features => {
61             match_code => {
62             message => 'the value in %s is not even',
63             code => sub { shift % 2 == 0 },
64             },
65             },
66             );
67              
68             =head1 DESCRIPTION
69              
70             Runs the control value against a code reference during the check. If that code reference returns a false value, an error is generated.
71              
72             =head1 ATTRIBUTES
73              
74             =head2 code
75              
76             This is the code reference. It should expect a single argument to be passed, which is the value to check.
77              
78             =head1 METHODS
79              
80             =head2 check_control
81              
82             No op.
83              
84             =head2 check
85              
86             Does the work of running the given subroutine over the control value and reports an error if the code reference runs and returns a false value.
87              
88             =head1 AUTHOR
89              
90             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
91              
92             =head1 COPYRIGHT AND LICENSE
93              
94             This software is copyright (c) 2015 by Qubling Software LLC.
95              
96             This is free software; you can redistribute it and/or modify it under
97             the same terms as the Perl 5 programming language system itself.
98              
99             =cut