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 Tags::HTML::Element::Utils;
2  
3 6 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=2.6
8  
9 Readonly::Array our @EXPORT_OK => qw(tags_boolean tags_data tags_label tags_value);
10  
11 our $VERSION = 0.15;
12  
13 sub tags_boolean {
14 my ($self, $element, $method) = @_;
15  
16 if ($element->$method) {
17 return (['a', $method, $method]);
18 }
19  
20 return ();
21 }
22  
23 sub tags_data {
24 my ($self, $object) = @_;
25  
26 # Plain content.
27 if ($object->data_type eq 'plain') {
28 $self->{'tags'}->put(
29 map { (['d', $_]) } @{$object->data},
30 );
31  
32 # Tags content.
33 } elsif ($object->data_type eq 'tags') {
34 $self->{'tags'}->put(@{$object->data});
35  
36 # Callback.
37 } else {
38 foreach my $cb (@{$object->data}) {
39 $cb->($self);
40 }
41 }
42  
43 return;
44 }
45  
46 sub tags_label {
47 my ($self, $object) = @_;
48  
49 # CSS for required span.
50 my $css_required = '';
51 if (defined $object->css_class) {
52 $css_required .= $object->css_class.'-';
53 }
54 $css_required .= 'required';
55  
56 $self->{'tags'}->put(
57 defined $object->label ? (
58 ['b', 'label'],
59 $object->id ? (
60 ['a', 'for', $object->id],
61 ) : (),
62 ['d', $object->label],
63 $object->required ? (
64 ['b', 'span'],
65 ['a', 'class', $css_required],
66 ['d', '*'],
67 ['e', 'span'],
68 ) : (),
69 ['e', 'label'],
70 ) : (),
71 );
72  
73 return;
74 }
75  
76 sub tags_value {
77 my ($self, $element, $method, $method_rewrite) = @_;
78  
79 if (defined $element->$method) {
80 return ([
81 'a',
82 defined $method_rewrite ? $method_rewrite : $method,
83 $element->$method,
84 ]);
85 }
86  
87 return ();
88 }
89  
90 1;
91  
92 __END__
« Element/Textarea.pm ↑ Summary Element.pm »