lib/HTML/FormFu/Element/SimpleTable.pm

filter: Statementstmt 100% 76 / 76 Branchbran 75.0% 15 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 50.0% 2 / 4 totaltotal 93.9% 109 / 116 CC 16 SCAR 15.7
CC
16
Cov
95%
render_data_non_recursive
8.0
rows
6.2
headers
4.0
CRAP 4.8
« lib/HTML/FormFu/Role/Element/Coercible.pm ↑ Summary lib/HTML/FormFu/Role/Filter/Compound.pm »
1 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Element::SimpleTable;
4 10 $HTML::FormFu::Element::SimpleTable::VERSION = '2.09';
5 # ABSTRACT: simple table element
6  
7 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 extends 'HTML::FormFu::Element::Block';
10  
11 10 ▶use HTML::FormFu::Util qw( append_xml_attribute );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 has odd_class => ( is => 'rw', traits => ['Chained'] );
16 10 has even_class => ( is => 'rw', traits => ['Chained'] );
17  
18 7 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
19 7 my $self = shift;
20  
21 7 $self->tag('table');
22  
23 7 return;
24 10 };
25  
26 4 ▶sub headers {
Subroutine headers: called CC=4 SCAR=13.9
Pod documented
27 4 my ( $self, $headers ) = @_;
28  
29 4 ▶ croak "headers must be passed as an array-ref"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($headers) ne "ARRAY" 0 4 4
30 if reftype($headers) ne 'ARRAY';
31  
32 # save any elements already added
33 4 my @original_rows = @{ $self->_elements };
34 4 $self->_elements( [] );
35  
36 4 my $header_row = $self->element('Block');
37 4 $header_row->tag('tr');
38  
39 4 for my $text (@$headers) {
40 7 my $th = $header_row->element('Block');
41 7 $th->tag('th');
42 7 $th->content($text);
43 }
44  
45 4 ▶ if (@original_rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@original_rows) 3 1 4
46 3 push @{ $self->_elements }, @original_rows;
47 }
48  
49 4 return $self;
50 }
51  
52 6 ▶sub rows {
Subroutine rows: called CC=6 SCAR=18.2
Pod documented
53 6 my ( $self, $rows ) = @_;
54  
55 6 ▶ croak "too many arguments" if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 6 6
56  
57 6 ▶ croak "rows must be passed as an array-ref"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($rows) ne "ARRAY" 0 6 6
58 if reftype($rows) ne 'ARRAY';
59  
60 6 for my $cells (@$rows) {
61 10 ▶ croak "each row must be an array-ref"
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($cells) ne "ARRAY" 0 10 10
62 if reftype($cells) ne 'ARRAY';
63  
64 10 my $row = $self->element('Block');
65 10 $row->tag('tr');
66  
67 10 for my $cell (@$cells) {
68 15 my $td = $row->element('Block');
69 15 $td->tag('td');
70 15 $td->element($cell);
71 }
72 }
73  
74 6 return $self;
75 }
76  
77 4 ▶sub render_data {
Subroutine render_data: called CC=1 SCAR=0.0
Pod undocumented
78 4 return shift->render_data_non_recursive(@_);
79 }
80  
81 10 ▶sub render_data_non_recursive { # though it is really recursive
Subroutine render_data_non_recursive: called CC=8 SCAR=20.8
Pod undocumented
82 10 my ( $self, $args ) = @_;
83  
84 10 my $odd = $self->odd_class;
85 10 my $even = $self->even_class;
86 10 my $i = 1;
87  
88 10 for my $row ( @{ $self->get_elements } ) {
89 19 my $first_cell = $row->get_element;
90  
91 19 ▶ if ( $i == 1 && $first_cell->tag eq 'th' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1 and $first_cell->tag eq "th") 5 14 19
Condition100%3/3
$i == 1 and $first_cell->tag eq "th"
!ll&&!rl&&r
595
MC/DC100%2/2
$i == 1 and $first_cell->tag eq "th"
$i == 1 $first_cell->tag eq "th"
Truth table100%3/3
A and B
A= $i == 1B= $first_cell->tag eq "th"
ABresult
0X0
100
111
92  
93 # skip the header row
94 5 next;
95 }
96  
97 14 ▶ if ( $i % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 2) { } 10 4 14
98 10 ▶ if ( defined $odd ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $odd) 2 8 10
99 2 $row->attributes( { class => $odd } );
100 }
101 }
102 else {
103 4 ▶ if ( defined $even ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $even) 1 3 4
104 1 $row->attributes( { class => $even } );
105 }
106 }
107 14 $i++;
108 }
109  
110 my $render = $self->SUPER::render_data_non_recursive(
111 10 ▶ { elements => [ map { $_->render_data } @{ $self->_elements } ],
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 10 10
112 $args ? %$args : (),
113 } );
114  
115 10 append_xml_attribute( $render->{attributes}, 'class', lc $self->type );
116  
117 10 return $render;
118 }
119  
120 10 __PACKAGE__->meta->make_immutable;
121  
122 10 1;
123  
124 __END__
« lib/HTML/FormFu/Role/Element/Coercible.pm ↑ Summary lib/HTML/FormFu/Role/Filter/Compound.pm »