Factory/Interface/HTML/Widget/Element.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 100% 6 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 8 totaltotal 83.5% 61 / 73 CC 5 SCAR 4.7
CC
5
Cov
96%
render_content
2.0
__ANON__
2.0
render_control
2.0
CRAP 1.6
« Factory/Feature/Functional.pm ↑ Summary Factory/Stasher/Memory.pm »
1 package Form::Factory::Interface::HTML::Widget::Element;
2 1 $Form::Factory::Interface::HTML::Widget::Element::VERSION = '0.022';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 with qw( Form::Factory::Interface::HTML::Widget );
6  
7 # ABSTRACT: HTML interface widget helper
8  
9  
10 1 has tag_name => (
11 is => 'ro',
12 isa => 'Str',
13 required => 1,
14 );
15  
16 1 has id => (
17 is => 'ro',
18 isa => 'Str',
19 predicate => 'has_id',
20 );
21  
22 has classes => (
23 is => 'ro',
24 isa => 'ArrayRef[Str]',
25 required => 1,
26 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 1 );
28  
29 has attributes => (
30 is => 'ro',
31 isa => 'HashRef[Str]',
32 required => 1,
33 534 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 1 );
35  
36 1 has content => (
37 is => 'ro',
38 isa => 'Str',
39 predicate => '_has_content',
40 );
41  
42 1 ▶sub has_content {
Subroutine has_content: called CC=1 SCAR=0.0
Pod undocumented
43 1 my $self = shift;
44 1 return $self->_has_content;
45 }
46  
47 6 ▶sub render_control {
Subroutine render_control: called CC=2 SCAR=6.9
Pod undocumented
48 6 my ($self, %options) = @_;
49  
50 6 my $html = '<' . $self->tag_name;
51 6 $html .= $self->render_id(%options);
52 6 $html .= $self->render_class(%options);
53 6 $html .= $self->render_attributes(%options);
54  
55 6 ▶ if ($self->has_content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_content) { } 5 1 6
56 5 $html .= '>';
57 5 $html .= $self->render_content(%options);
58 5 $html .= '</' . $self->tag_name . '>';
59 }
60  
61 else {
62 1 $html .= '/>';
63 }
64  
65 6 return $html;
66 }
67  
68 5 ▶sub render_content {
Subroutine render_content: called CC=2 SCAR=7.1
Pod undocumented
69 5 my $self = shift;
70 5 my $content = $self->content;
71 5 ▶ return $self->content || '';
Condition50%1/2
$self->content || ''
l!l
50
MC/DC0%0/1
$self->content || ''
$self->content
Truth table50%1/2
A
A= $self->content
Aresult
11
00
72 }
73  
74 6 ▶sub render_id {
Subroutine render_id: called CC=2 SCAR=6.9
Pod undocumented
75 6 my $self = shift;
76 6 ▶ return '' unless $self->has_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_id 5 1 6
77 1 return ' id="' . $self->id . '"';
78 }
79  
80 6 ▶sub render_class {
Subroutine render_class: called CC=1 SCAR=0.0
Pod undocumented
81 6 my $self = shift;
82  
83 6 my @classes = ('form', @{ $self->classes });
84 6 return ' class="' . join(' ', @classes) . '"';
85 }
86  
87 6 ▶sub render_attributes {
Subroutine render_attributes: called CC=2 SCAR=6.9
Pod undocumented
88 6 my $self = shift;
89 6 my @attributes;
90  
91 my %attributes = (
92 6 %{ $self->attributes },
93 6 %{ $self->more_attributes },
94 );
95  
96 6 ▶ while (my ($name, $value) = each %attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attributes) 3 6 9
97 3 push @attributes, $name . '="' . $value . '"';
98 }
99  
100 6 return join ' ', @attributes;
101 }
102  
103 5 ▶sub more_attributes { {} }
Subroutine more_attributes: called CC=1 SCAR=0.0
Pod undocumented
104  
105 130 ▶sub consume_control { }
Subroutine consume_control: called CC=1 SCAR=0.0
Pod undocumented
106  
107  
108 1 __PACKAGE__->meta->make_immutable;
109  
110 __END__
« Factory/Feature/Functional.pm ↑ Summary Factory/Stasher/Memory.pm »