| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 117 | 160 | $attributes{text} = $name; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 217 | ▶ | if ( $element eq 'cell' && exists $attributes{alternate_classes} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$element eq "cell" and exists $attributes{"alternate_classes"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||