Element/Utils.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Element/Textarea.pm ↑ Summary Element.pm »
1 package Data::HTML::Element::Utils;
2  
3 64 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 64 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 64 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use List::Util 1.33 qw(none);
9 use Mo::utils 0.06 qw(check_array);
10 use Readonly;
11  
12 Readonly::Array our @DATA_TYPES => qw(cb plain tags);
13 Readonly::Array our @EXPORT_OK => qw(check_data check_data_type);
14  
15 our $VERSION = 0.17;
16  
17 sub check_data {
18 my $self = shift;
19  
20 # Check data based on type.
21 check_array($self, 'data');
22 foreach my $data_item (@{$self->{'data'}}) {
23 # Plain mode
24 if ($self->{'data_type'} eq 'plain') {
25 if (ref $data_item ne '') {
26 err "Parameter 'data' in 'plain' mode must contain ".
27 'reference to array with scalars.';
28 }
29  
30 # Tags mode.
31 } elsif ($self->{'data_type'} eq 'tags') {
32 if (ref $data_item ne 'ARRAY') {
33 err "Parameter 'data' in 'tags' mode must contain ".
34 "reference to array with references ".
35 'to array with Tags structure.';
36 }
37  
38 # Callback.
39 } else {
40 if (ref $data_item ne 'CODE') {
41 err "Parameter 'data' in 'cb' mode must contain ".
42 "reference to code with callback.";
43 }
44 }
45 }
46  
47 return;
48 }
49  
50 sub check_data_type {
51 my $self = shift;
52  
53 # Check data type.
54 if (! defined $self->{'data_type'}) {
55 $self->{'data_type'} = 'plain';
56 }
57 if (none { $self->{'data_type'} eq $_ } @DATA_TYPES) {
58 err "Parameter 'data_type' has bad value.",
59 'Value', $self->{'data_type'},
60 ;
61 }
62  
63 return;
64 }
65  
66  
67 1;
68  
69 __END__
« Element/Textarea.pm ↑ Summary Element.pm »