Wiki/Plugin/Block/Toggle.pm

filter: Statementstmt 100% 83 / 83 Branchbran 100% 24 / 24 Conditioncond 84.0% 21 / 25 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 94.7% 145 / 153 CC 24 SCAR 22.4
CC
24
Cov
97%
check
14.0
get
7.0
mobile
5.0
CRAP 9.4
« Wiki/Plugin/Block/CopyAndPaste.pm ↑ Summary Wiki/Block.pm »
1 package Text::Livedoor::Wiki::Plugin::Block::Toggle;
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 5 __PACKAGE__->trigger({ start=> '^\[(\+|-)\]' , end => '^\[END\]$' });
8  
9 245 ▶sub check {
Subroutine check: called CC=14 SCAR=26.4
Pod documented
10 245 my $class = shift;
11 245 my $line = shift;
12 245 my $args = shift;
13 245 my $on_next = $args->{on_next};
14 245 my $id = $args->{id};
15 245 my $inline = $args->{inline};
16 245 my $scratchpad = $Text::Livedoor::Wiki::scratchpad;
17 245 my $row;
18 my $option_str;
19 245 my $processing = $scratchpad->{block}{$id}{processing};
20
21
22 # rule
23 # 1. [+]~ or [-]~
24 # 2. not starting.
25 # 3. this line
26 # 4. no child found
27 245 ▶ if ((my ( $mark ) = $line =~ /^\[(\+|-)\]/) && !$processing && !$on_next && !$class->get_child($id) ){
Branch: 4 branches
BranchTrueFalseTotal
if (my($mark) = $line =~ /^\[(\+|-)\]/ and not $processing and not $on_next and not $class->get_child($id)) { } 22 223 245
elsif (not $on_next and $class->trigger_check($id, $line) and $line =~ /^\[END\]$/ and $processing) { } 13 210 223
elsif ($on_next and not $processing) { } 2 208 210
elsif ($processing) { } 123 85 208
Condition77%7/9
my($mark) = $line =~ /^\[(\+|-)\]/ and not $processing and not $on_next and not $class->get_child($id)
!ll&&!rl&&r
223022
my($mark) = $line =~ /^\[(\+|-)\]/ and not $processing and not $on_next
!ll&&!rl&&r
223022
my($mark) = $line =~ /^\[(\+|-)\]/ and not $processing
!ll&&!rl&&r
2032022
MC/DC50%2/4
my($mark) = $line =~ /^\[(\+|-)\]/ and not $processing and not $on_next and not $class->get_child($id)
my($mark) = $line =~ /^\[(\+|-)\]/ not $processing not $on_next not $class->get_child($id)
Truth table60%3/5
A and not(B) and not(C) and not(D)
A= my($mark) = $line =~ /^\[(\+|-)\]/B= not $processingC= not $on_nextD= not $class->get_child($id)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
28 #XXX
29 22 $Text::Livedoor::Wiki::scratchpad->{skip_ajust_block_break} = '1';
30
31 22 $scratchpad->{block}{$id}{processing} = 1 ;
32 22 ▶ my $toggle = $mark eq '+' ? 'close' : 'open';
Branch: 1 branch
BranchTrueFalseTotal
$mark eq '+' ? : 18 4 22
33
34 22 my ( $dummy , $title ) = $line =~ /^\[(\+|-)\](.+)/;
35 22 ▶ $title = '' unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 6 16 22
36 22 return { id => $id , title => $title , toggle => $toggle };
37 }
38 # end box
39 ▶ elsif( !$on_next && $class->trigger_check($id,$line) && $line =~ /^\[END\]$/ && $processing ) {
Condition88%8/9
not $on_next and $class->trigger_check($id, $line) and $line =~ /^\[END\]$/ and $processing
!ll&&!rl&&r
210013
not $on_next and $class->trigger_check($id, $line) and $line =~ /^\[END\]$/
!ll&&!rl&&r
10110913
not $on_next and $class->trigger_check($id, $line)
!ll&&!rl&&r
7031122
MC/DC75%3/4
not $on_next and $class->trigger_check($id, $line) and $line =~ /^\[END\]$/ and $processing
not $on_next $class->trigger_check($id, $line) $line =~ /^\[END\]$/ $processing
Truth table80%4/5
not(A) and B and C and D
A= not $on_nextB= $class->trigger_check($id, $line)C= $line =~ /^\[END\]$/D= $processing
ABCDresult
0XXX0
10XX0
110X0
11100
11111
40 13 $scratchpad->{block}{$id}{processing} = 0;
41 13 return { line => "\n" };
42 }
43 # finnalize
44 ▶ elsif( $on_next && !$processing ) {
Condition100%3/3
$on_next and not $processing
!ll&&!rl&&r
140682
MC/DC100%2/2
$on_next and not $processing
$on_next not $processing
Truth table100%3/3
A and not(B)
A= $on_nextB= not $processing
ABresult
0X0
100
111
45 2 return;
46 }
47 # processing
48 elsif( $processing ) {
49 123 return { line => $line };
50 }
51 85 return;
52  
53 }
54  
55 15 ▶sub get {
Subroutine get: called CC=7 SCAR=19.5
Pod documented
56 15 my $class = shift;
57 15 my $block = shift;
58 15 my $inline = shift;
59 15 my $items = shift;
60 15 my $meta = shift @{$items};
61 15 my $box = $meta->{box};
62 15 my $class_name = $meta->{class_name};
63 15 my $id = $meta->{id};
64 15 my $title = $meta->{title};
65 15 $title = $inline->parse($title);
66  
67 # END LINE
68 15 ▶ if ( scalar @$items ) { # in case there is no line in $items
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$items) 12 3 15
69 12 ▶ pop @$items if $items->[-1]{line} eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $items->[-1]{"line"} eq "\n" 10 2 12
70 }
71  
72 15 my $html = '';
73 15 $html .= $_->{line} . "\n" for @$items;
74 15 $html =~ s/\n$//;
75 15 ▶ my $save_skip_catalog = $Text::Livedoor::Wiki::opts->{skip_catalog} || 0 ;
Condition100%2/2
$Text::Livedoor::Wiki::opts->{'skip_catalog'} || 0
l!l
213
MC/DC100%1/1
$Text::Livedoor::Wiki::opts->{'skip_catalog'} || 0
$Text::Livedoor::Wiki::opts->{'skip_catalog'}
Truth table100%2/2
A
A= $Text::Livedoor::Wiki::opts->{'skip_catalog'}
Aresult
11
00
76 15 $Text::Livedoor::Wiki::opts->{skip_catalog} = 1;
77 15 $html = $block->parse( $html , 1) ;
78 15 $Text::Livedoor::Wiki::opts->{skip_catalog} = $save_skip_catalog ;
79  
80 15 my $spacer_image = $class->opts->{storage} . '/images/common/spacer.gif';
81  
82  
83 #return qq|<toggle-$id>\n$html</toggle-$id>\n|;
84 15 my $id_inside = "$id-inside";
85 15 my $id_label = "$id-label";
86 15 ▶ my $label_class = $meta->{toggle} eq 'open' ? 'toggle-link-close': 'toggle-link-open';
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'toggle'} eq 'open' ? : 4 11 15
87 15 my $js = qq|if( document.getElementById('$id_inside').style.display =='none' ) { document.getElementById('$id_inside').style.display ='block' ; document.getElementById('$id_label').className = 'toggle-link-close'; } else { document.getElementById('$id_inside').style.display ='none';document.getElementById('$id_label').className = 'toggle-link-open'; } ;|;
88 15 my $button = qq|<div class="toggle-title"><a id="$id-label" onClick="$js" class="$label_class"><img src="$spacer_image" width="17" height="17" alt="" /></a><p>$title</p></div>\n|;
89  
90 15 ▶ if( $meta->{toggle} eq 'open' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{'toggle'} eq 'open') { } 4 11 15
91 4 $html= qq|$button<div id="$id_inside" class="toggle-display">\n$html</div>\n|;
92 }
93 else {
94 11 $html= qq|$button<div style="display:none" id="$id_inside" class="toggle-display">\n$html</div>\n|;
95 }
96  
97 15 return qq|<div id="$id">\n$html</div>\n|;
98 }
99  
100 7 ▶sub mobile {
Subroutine mobile: called CC=5 SCAR=16.1
Pod documented
101 7 my $class = shift;
102 7 my $block = shift;
103 7 my $inline = shift;
104 7 my $items = shift;
105 7 my $meta = shift @{$items};
106 7 my $box = $meta->{box};
107 7 my $class_name = $meta->{class_name};
108 7 my $id = $meta->{id};
109 7 my $title = $meta->{title};
110 7 $title = $inline->parse($title);
111  
112 # END LINE
113 7 ▶ if ( scalar @$items ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$items) 5 2 7
114 5 ▶ pop @$items if $items->[-1]{line} eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $items->[-1]{"line"} eq "\n" 3 2 5
115 }
116  
117 7 my $html = '';
118 7 $html .= $_->{line} . "\n" for @$items;
119 7 $html =~ s/\n$//;
120 7 ▶ my $save_skip_catalog = $Text::Livedoor::Wiki::opts->{skip_catalog} || 0 ;
Condition50%1/2
$Text::Livedoor::Wiki::opts->{'skip_catalog'} || 0
l!l
07
MC/DC0%0/1
$Text::Livedoor::Wiki::opts->{'skip_catalog'} || 0
$Text::Livedoor::Wiki::opts->{'skip_catalog'}
Truth table50%1/2
A
A= $Text::Livedoor::Wiki::opts->{'skip_catalog'}
Aresult
11
00
121 7 $Text::Livedoor::Wiki::opts->{skip_catalog} = 1;
122 7 $html = $block->parse( $html , 1) ;
123 7 $Text::Livedoor::Wiki::opts->{skip_catalog} = $save_skip_catalog ;
124  
125 7 return qq|<div id="$id">\n$title<br />\n$html</div>\n|;
126 }
127  
128 5 1;
129  
130 =head1 NAME
131  
132 Text::Livedoor::Wiki::Plugin::Block::Toggle - Toggle Block Plugin
133  
134 =head1 DESCRIPTION
135  
136 you can open and close block with this.
137  
138 =head1 SYNOPSIS
139  
140 [+]''you can open me!''
141 - item
142 - item
143 [END]
144 [-]''you can close me!''
145 * title
146 hoge hoge
147 hoge hoge
148 [END]
149  
150 =head1 FUNCTION
151  
152 =head2 check
153  
154 =head2 get
155  
156 =head2 mobile
157  
158 =head1 AUTHOR
159  
160 polocky
161  
162 =cut
« Wiki/Plugin/Block/CopyAndPaste.pm ↑ Summary Wiki/Block.pm »