Element/Form.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Element/Button.pm ↑ Summary Element/Input.pm »
1 package Data::HTML::Element::Form;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶use Data::HTML::Element::Utils qw(check_data check_data_type);
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Error::Pure qw(err);
8 use List::Util 1.33 qw(none);
9 use Mo qw(build is);
10 use Mo::utils::CSS 0.02 qw(check_css_class);
11 use Readonly;
12  
13 Readonly::Array our @METHODS => qw(get post);
14 Readonly::Array our @ENCTYPES => (
15 'application/x-www-form-urlencoded',
16 'multipart/form-data',
17 'text/plain',
18 );
19  
20 our $VERSION = 0.17;
21  
22 has action => (
23 is => 'ro',
24 );
25  
26 has css_class => (
27 is => 'ro',
28 );
29  
30 has data => (
31 default => [],
32 ro => 1,
33 );
34  
35 has data_type => (
36 ro => 1,
37 );
38  
39 has enctype => (
40 is => 'ro',
41 );
42  
43 has id => (
44 is => 'ro',
45 );
46  
47 has label => (
48 is => 'ro',
49 );
50  
51 has method => (
52 is => 'ro',
53 );
54  
55 sub BUILD {
56 my $self = shift;
57  
58 # Check CSS class.
59 check_css_class($self, 'css_class');
60  
61 # Check data type.
62 check_data_type($self);
63  
64 # Check data based on type.
65 check_data($self);
66  
67 # Check enctype.
68 if (defined $self->{'enctype'}) {
69 if (none { $self->{'enctype'} eq $_ } @ENCTYPES) {
70 err "Parameter 'enctype' has bad value.",
71 'Value', $self->{'enctype'},
72 ;
73 }
74 }
75  
76 # Check method.
77 if (! defined $self->{'method'}) {
78 $self->{'method'} = 'get';
79 }
80 if (none { $self->{'method'} eq $_ } @METHODS) {
81 err "Parameter 'method' has bad value.",
82 'Value', $self->{'method'};
83 }
84  
85 return;
86 }
87  
88 1;
89  
90 __END__
« Element/Button.pm ↑ Summary Element/Input.pm »