TableContent/Template.pm

filter: Statementstmt 99.3% 141 / 142 Branchbran 85.7% 12 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 97.7% 44 / 45 Podpod n/a totaltotal 98.0% 202 / 206 SCAR 23.0
CC
10
Cov
98%
_filter_attributes
5.0
import
4.0
__ANON__
3.0
CRAP 10.0
« TableContent/Parser.pm ↑ Summary TableContent/Table/Row.pm »
1 package HTML::TableContent::Template;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooX::ReturnModifiers;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use HTML::TableContent::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use HTML::TableContent::Table::Caption;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use HTML::TableContent::Table::Header;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.18';
12  
13 2 my %TABLE = (
14 caption => 'HTML::TableContent::Table::Caption',
15 header => 'HTML::TableContent::Table::Header',
16 row => 'HTML::TableContent::Table::Row',
17 cell => 'HTML::TableContent::Table::Row::Cell',
18 );
19  
20 sub import {
21 45 ▶ my ( $self, @import ) = @_;
Subroutine import: called CC=4 SCAR=13.9
22
23 45 my $target = caller;
24
25 45 my %modifiers = return_modifiers($target);
26  
27 45 my @target_isa;
28  
29 45 ▶ return if $target->can('_table');
Branch: 1 branch
BranchTrueFalseTotal
if $target->can("_table") 0 45 45
30  
31 2 ▶ { no strict 'refs'; @target_isa = @{"${target}::ISA"} };
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 45 ▶ if (@target_isa) {
Branch: 1 branch
BranchTrueFalseTotal
if (@target_isa) 45 0 45
34 45 ▶ eval '{
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _cell_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
Subroutine _row_spec: called CC=1 SCAR=0.0
35 package ' . $target . ';
36  
37 sub _caption_spec {
38 my ($class, @meta) = @_;
39 return $class->maybe::next::method(@meta);
40 }
41  
42 sub _header_spec {
43 my ($class, @meta) = @_;
44 return $class->maybe::next::method(@meta);
45 }
46
47 sub _row_spec {
48 my ($class, @meta) = @_;
49 return $class->maybe::next::method(@meta);
50 }
51
52 sub _cell_spec {
53 my ($class, @meta) = @_;
54 return $class->maybe::next::method(@meta);
55 }
56
57 1;
58 }';
59 }
60  
61 45 ▶ $modifiers{has}->( 'package' => ( is => 'ro', lazy => 1, default => sub { return $target; } ) );
Subroutine __ANON__: called CC=1 SCAR=0.0
62  
63 my $apply_modifiers = sub {
64 46 ▶ $modifiers{with}->('HTML::TableContent::Template::Base');
Subroutine __ANON__: called CC=1 SCAR=0.0
65 45 };
66  
67 45 for my $element (keys %TABLE) {
68 180 my @element = ();
69 my $option = sub {
70 218 ▶ my ( $name, %attributes ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
71
72 218 my $element_data = { };
73 218 my %filtered_attributes = _filter_attributes($name, $element, %attributes);
74  
75 218 ▶ if ( $element =~ m{caption|header}ixms ){
Branch: 1 branch
BranchTrueFalseTotal
if ($element =~ /caption|header/imsx) 180 37 217
76 181 $modifiers{has}->( $name => %filtered_attributes );
77 }
78  
79 218 delete $filtered_attributes{default};
80  
81 218 $element_data->{$name} = \%filtered_attributes;
82
83 218 my $spec = sprintf('_%s_spec', $element);
84 218 ▶ if ( $element =~ m{row|cell}ixms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element =~ /row|cell/imsx) { } 37 180 217
85 $modifiers{around}->(
86 $spec => sub {
87 36 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=1 SCAR=0.0
88 36 return $self->$orig(@_), %$element_data;
89 }
90 38 );
91 } else {
92 180 push @element, $element_data;
93 $modifiers{around}->(
94 $spec => sub {
95 180 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=1 SCAR=0.0
96 180 return $self->$orig(@_), \@element;
97 }
98 180 );
99 }
100 217 return;
101 180 };
102  
103 2 ▶ { no strict 'refs'; *{"${target}::$element"} = $option; }
Subroutine BEGIN: called CC=1 SCAR=0.0
104 }
105  
106 45 $apply_modifiers->();
107  
108 45 return;
109 }
110  
111 sub _filter_attributes {
112 217 ▶ my ($name, $element, %attributes) = @_;
Subroutine _filter_attributes: called CC=5 SCAR=16.1
113  
114 217 $attributes{template_attr} = $name;
115  
116 217 ▶ if ( ! exists $attributes{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attributes{"text"}) 160 57 217
117 160 $attributes{text} = $name;
118 }
119  
120 217 ▶ if ( $element eq 'cell' && exists $attributes{alternate_classes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element eq "cell" and exists $attributes{"alternate_classes"}) 3 214 217
Condition100%3/3
$element eq "cell" and exists $attributes{"alternate_classes"}
!ll&&!rl&&r
20593
MC/DC100%2/2
$element eq "cell" and exists $attributes{"alternate_classes"}
$element eq "cell" exists $attributes{"alternate_classes"}
Truth table100%3/3
A and B
A= $element eq "cell"B= exists $attributes{"alternate_classes"}
ABresult
0X0
100
111
121 3 my @classes = @{ $attributes{alternate_classes} };
122 3 $attributes{oac} = \@classes;
123 }
124  
125 217 my %tattr = %attributes;
126 217 $attributes{is} = 'ro';
127 217 $attributes{lazy} = 1;
128 217 ▶ if ( $element =~ m{row|cell}ixms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element =~ /row|cell/imsx) { } 37 180 217
129 37 ▶ $attributes{default} = sub { return \%tattr; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
130 } else {
131 180 my $class = $TABLE{$element};
132 180 ▶ $attributes{default} = sub { my %aah = %tattr; return $class->new(\%aah); };
Subroutine __ANON__: called CC=1 SCAR=0.0
133 }
134  
135 217 return %attributes;
136 }
137  
138 2 1;
139  
140 __END__
« TableContent/Parser.pm ↑ Summary TableContent/Table/Row.pm »