Wiki/Plugin/Block/Table.pm

filter: Statementstmt 100% 136 / 136 Branchbran 100% 48 / 48 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 100% 202 / 202 CC 34 SCAR 20.4
CC
34
Cov
100%
row
11.0
get
9.0
trs
7.0
CRAP 7.7
« Wiki/Block.pm ↑ Summary Wiki/Plugin/Block/H4.pm »
1 package Text::Livedoor::Wiki::Plugin::Block::Table;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use base qw(Text::Livedoor::Wiki::Plugin::Block);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 178 ▶sub check {
Subroutine check: called CC=5 SCAR=16.1
Pod documented
9 178 my $self = shift;
10 178 my $line = shift;
11 178 my $args = shift;
12 178 my $id = $args->{id};
13 178 my $on_next = $args->{on_next};
14  
15 178 my $row = '';
16 178 ▶ if ( ($row) = $line =~ /^\|(.*)(\||\|\s)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($row) = $line =~ /^\|(.*)(\||\|\s)$/) { } 58 120 178
elsif (($row) = $line =~ /^,(.*)(,|,\s)$/) { } 7 113 120
17 58 ▶ unless ($on_next) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($on_next) 41 17 58
18 41 $row =~ s/\|$/\| /;
19 41 $row =~ s/\|\|/\| \|/;
20 41 $row =~ s/\|\|/\| \|/;
21 }
22 58 my @rows = split( /\|/, $row , -1);
23 58 return { id => $id , rows => \@rows };
24  
25 }
26 elsif ( ($row) = $line =~ /^,(.*)(,|,\s)$/ ) {
27 7 ▶ unless ($on_next) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($on_next) 5 2 7
28 5 $row =~ s/,$/, /;
29 5 $row =~ s/,,/, ,/;
30 5 $row =~ s/,,/, ,/;
31 }
32 7 my @rows = split( ',', $row , -1);
33 7 return { id => $id , rows => \@rows };
34 }
35  
36 113 return;
37  
38 }
39  
40 #{{{ get
41 25 ▶sub get {
Subroutine get: called CC=9 SCAR=22.0
Pod documented
42 25 my $self = shift;
43 25 my $block = shift;
44 25 my $inline = shift;
45 25 my $items = shift;
46 25 my $id = $items->[0]{id};
47 25 my $rows = $self->trs($items);
48 25 my $data = '';
49 25 for my $row ( @$rows ) {
50 42 $data .= "<tr>\n";
51 42 for my $col (@$row) {
52 100 $data .= qq|<$col->{tag}|;
53 100 for ( qw/colspan rowspan/ ) {
54 200 ▶ $data .= qq| $_="$col->{$_}"| if $col->{$_} && $col->{$_} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $col->{$_} and $col->{$_} > 1 13 187 200
Condition100%3/3
$col->{$_} and $col->{$_} > 1
!ll&&!rl&&r
929513
MC/DC100%2/2
$col->{$_} and $col->{$_} > 1
$col->{$_} $col->{$_} > 1
Truth table100%3/3
A and B
A= $col->{$_}B= $col->{$_} > 1
ABresult
0X0
100
111
55 }
56  
57 100 my $style = '';
58 100 for my $option ( @{$col->{options}} ) {
59 17 $style .= qq|$option->{key}:$option->{value};|;
60 }
61  
62 100 my $text = $inline->parse($col->{inline});
63 100 ▶ $data .= qq| style="$style"| if $style;
Branch: 1 branch
BranchTrueFalseTotal
if $style 10 90 100
64 100 $data .= q|>|;
65 100 ▶ $data .= $text ne '' ? $text : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$text ne '' ? : 82 18 100
66 100 $data .= qq|</$col->{tag}>\n|;
67  
68 }
69 42 $data .= "</tr>\n";
70 }
71  
72 25 return qq|<table id="$id">\n$data</table>\n|;
73 }
74 25 ▶sub trs {
Subroutine trs: called CC=7 SCAR=19.5
Pod documented
75 25 my $self = shift;
76 25 my $items = shift;
77 25 my @rows = ();
78 25 my $rowspan = {};
79  
80 25 for ( reverse @$items ) {
81 42 my $remove_cell = {};
82 42 my $colspan_total = 0;
83 42 my $row = $self->row($_->{rows});
84 42 ▶ for ( my $j = 0; $j < scalar @$row ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @$row) 109 42 151
85 109 $colspan_total += $row->[$j]->{colspan} - 1;
86 109 ▶ if( $row->[$j]{inline} =~ /^\^$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->[$j]{'inline'} =~ /^\^$/) { } 9 100 109
87 9 $rowspan->{$j + $colspan_total }{cnt}++;
88 9 $remove_cell->{$j} = 1;
89 }
90 else {
91 100 ▶ if ( $rowspan->{$j + $colspan_total }{cnt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rowspan{$j + $colspan_total}{"cnt"}) 8 92 100
92 8 $row->[$j]->{rowspan} = $rowspan->{$j + $colspan_total }{cnt} + 1;
93 8 $rowspan->{$j + $colspan_total}{cnt} = 0;
94 }
95 }
96 }
97 42 my @new_row = ();
98 42 ▶ for ( my $j = 0 ; $j < scalar @{$row} ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @{$row;}) 109 42 151
99 109 ▶ push @new_row , $row->[$j] unless $remove_cell->{$j};
Branch: 1 branch
BranchTrueFalseTotal
unless $remove_cell->{$j} 100 9 109
100 }
101 42 push @rows , \@new_row;
102 }
103  
104 25 @rows = reverse @rows;
105 25 return \@rows;
106 }
107 42 ▶sub row {
Subroutine row: called CC=11 SCAR=24.0
Pod documented
108 42 my $self = shift;
109 42 my $cells = shift;
110 42 my $on_force_th = 0;
111 42 my @row = ();
112 42 my $colspan=1;
113 42 for my $cell ( @$cells ) {
114 115 my @options = ();
115 115 my $tag = 'td';
116 115 $cell =~ s/^\s+//;
117 115 $cell =~ s/\s+$//;
118  
119 115 ▶ if( $cell =~ /^>$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cell =~ /^>$/) 6 109 115
120 6 $colspan++;
121 6 next;
122 }
123 # th
124 109 ▶ if( $cell =~ /^\!/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cell =~ /^\!/) { } 2 107 109
elsif ($cell =~ /^~/) { } 3 104 107
125 2 $tag = 'th';
126 2 $cell =~ s/^\!//;
127 }
128 # force th
129 elsif( $cell =~ /^~/ ) {
130 3 $on_force_th = 1;
131 3 $cell =~ s/^~//;
132 }
133  
134 109 ▶ if( $on_force_th ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($on_force_th) 7 102 109
135 7 $tag = 'th';
136 }
137  
138 109 my $data = {};
139 109 while(1){
140 126 ▶ if ( my( $style , $value , $left ) = $cell =~ /^(BGCOLOR|COLOR|SIZE|LEFT|CENTER|RIGHT)\s*(?:\(([A-Za-z0-9\-\#]*)\))?\s*:\s*(.*)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $cell =~ /^(BGCOLOR|COLOR|SIZE|LEFT|CENTER|RIGHT)\s*(?:\(([A-Za-z0-9\-\#]*)\))?\s*:\s*(.*)/i) { } 17 109 126
141 17 $cell = $left;
142 17 $style = lc $style;
143 17 ▶ if( $style eq 'bgcolor' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($style eq 'bgcolor') { } 5 12 17
elsif ($style =~ /left|center|right/) { } 4 8 12
elsif ($style eq 'size') { } 3 5 8
144 5 $style = 'background-color';
145 }
146 elsif( $style =~ /left|center|right/ ) {
147 4 $value = $style;
148 4 $style = 'text-align';
149 }
150 elsif( $style eq 'size' ) {
151 3 $style = 'font-size';
152 3 $value .= 'px';
153 }
154 17 push @options , { key => $style , value => $value } ;
155 }
156 else {
157 109 last;
158 }
159 }
160 109 %$data = ( %$data , ( inline => $cell , options => \@options , tag => $tag , colspan => $colspan ) );
161 109 push @row , $data;
162  
163 109 ▶ if( $colspan > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($colspan > 1) 5 104 109
164 5 $colspan = 1;
165 }
166 }
167  
168 42 return \@row;
169 }
170 #}}}
171  
172 2 ▶sub mobile {
Subroutine mobile: called CC=6 SCAR=17.9
Pod documented
173 2 my $self = shift;
174 2 my $block = shift;
175 2 my $inline = shift;
176 2 my $items = shift;
177  
178 2 my $data = '';
179  
180 2 for my $item ( @$items ) {
181 4 my $rows = $item->{rows};
182 4 for my $cell ( @$rows ) {
183 18 $cell =~ s/^\s+//;
184 18 $cell =~ s/\s+$//;
185 18 ▶ next if $cell =~ /^>$/ ;
Branch: 1 branch
BranchTrueFalseTotal
if $cell =~ /^>$/ 2 16 18
186 16 ▶ next if $cell =~ /^\^/;
Branch: 1 branch
BranchTrueFalseTotal
if $cell =~ /^\^/ 2 14 16
187  
188 14 $cell =~ s/^\!//;
189 14 $cell =~ s/^~//;
190 14 while(1){
191 16 ▶ if ( my( $style , $value , $left ) = $cell =~ /^(BGCOLOR|COLOR|SIZE|LEFT|CENTER|RIGHT)\s*(?:\(([A-Za-z0-9\-\#]*)\))?\s*:\s*(.*)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $cell =~ /^(BGCOLOR|COLOR|SIZE|LEFT|CENTER|RIGHT)\s*(?:\(([A-Za-z0-9\-\#]*)\))?\s*:\s*(.*)/i) { } 2 14 16
192 2 $cell = $left;
193 }
194 else {
195 14 last;
196 }
197 }
198
199 14 $data .= $inline->parse($cell) . ' ';
200 }
201 4 $data .= "<br />\n";
202 }
203  
204  
205 2 return $data;
206 }
207  
208 5 1;
209  
210 =head1 NAME
211  
212 Text::Livedoor::Wiki::Plugin::Block::Table - Table Block Plugin
213  
214 =head1 DESCRIPTION
215  
216 create table.
217  
218 =head1 SYNOPSIS
219  
220 |hoge|hoge|
221 |!hoge|hoge|
222 |~hoge|hoge|
223 |>|hoge|
224  
225 ,hoge,hoge,
226 ,^,hoge,
227  
228 =head1 FUNCTION
229  
230 =head2 check
231  
232 =head2 get
233  
234 =head2 mobile
235  
236 =head2 row
237  
238 =head2 trs
239  
240 =head1 AUTHOR
241  
242 polocky
243  
244 =cut
« Wiki/Block.pm ↑ Summary Wiki/Plugin/Block/H4.pm »