File Coverage

blib/lib/Form/Factory/Feature/Control/Required.pm
Criterion Covered Total %
statement 13 13 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Form::Factory::Feature::Control::Required;
2             $Form::Factory::Feature::Control::Required::VERSION = '0.022';
3 1     1   554 use Moose;
  1         2  
  1         7  
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   4992 use Carp ();
  1         2  
  1         94  
13              
14             # ABSTRACT: Makes sure a value is set on a control
15              
16              
17 7     7 1 22 sub check_control { }
18              
19              
20             sub check {
21 5     5 1 9 my $self = shift;
22 5         165 my $control = $self->control;
23              
24 5 100       19 if ($control->has_current_value) {
25 4         186 $self->result->is_valid(1);
26             }
27              
28             else {
29 1         6 $self->control_error('the %s is required');
30 1         29 $self->result->is_valid(0);
31             }
32             }
33              
34             __PACKAGE__->meta->make_immutable;
35              
36             __END__
37              
38             =pod
39              
40             =encoding UTF-8
41              
42             =head1 NAME
43              
44             Form::Factory::Feature::Control::Required - Makes sure a value is set on a control
45              
46             =head1 VERSION
47              
48             version 0.022
49              
50             =head1 SYNOPSIS
51              
52             has_control last_name => (
53             control => 'text',
54             features => {
55             required => 1,
56             },
57             );
58              
59             =head1 DESCRIPTION
60              
61             Reports a check error if the required value is not set. On scalar value controls, it checks that the value has a length greater than zero. On list value controls, it makes sure the list of selected items has more than zero elements.
62              
63             =head1 METHODS
64              
65             =head2 check_control
66              
67             No op.
68              
69             =head2 check
70              
71             Reports an error if a scalar value does not have a length greater than 0. Reports an error if a list value has 0 items in the list.
72              
73             =head1 AUTHOR
74              
75             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             This software is copyright (c) 2015 by Qubling Software LLC.
80              
81             This is free software; you can redistribute it and/or modify it under
82             the same terms as the Perl 5 programming language system itself.
83              
84             =cut