Wiki/Plugin/Block.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 14 / 14 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 100% 8 / 8 totaltotal 100% 83 / 83 CC 10 SCAR 13.9
CC
10
Cov
100%
trigger_check
8.0
get_child
2.0
push_children
2.0
CRAP 4.0
« Wiki/Plugin/Function/Pad.pm ↑ Summary Wiki/Plugin/Function/Color.pm »
1 package Text::Livedoor::Wiki::Plugin::Block;
2  
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use base qw(Class::Data::Inheritable);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 __PACKAGE__->mk_classdata('trigger');
8  
9 2 ▶sub check { die 'implement me'; }
Subroutine check: called CC=1 SCAR=0.0
Pod documented
10 1 ▶sub get { die 'implement me'; }
Subroutine get: called CC=1 SCAR=0.0
Pod documented
11 12 ▶sub mobile { shift->get(@_) }
Subroutine mobile: called CC=1 SCAR=0.0
Pod documented
12  
13 257 ▶sub trigger_check {
Subroutine trigger_check: called CC=8 SCAR=20.8
Pod documented
14 257 my $class = shift;
15 257 my $id = shift;
16 257 my $line = shift;
17 257 my $trigger = $Text::Livedoor::Wiki::scratchpad->{core}{block_trigger};
18  
19 257 my $skip = 0;
20 257 my $child_check = $class->get_child($id) ;
21
22 257 ▶ if( $child_check ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_check) 40 217 257
23 40 ▶ $skip = $trigger->{$child_check}{escape} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$trigger->{$child_check}{'escape'} ? : 27 13 40
24 }
25  
26 257 for my $key ( keys %$trigger ) {
27 487 ▶ last if $skip;
Branch: 1 branch
BranchTrueFalseTotal
if $skip 27 460 487
28 # append stocks
29 460 ▶ if ( $line =~ m/\G($trigger->{$key}{start})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\G($trigger->{$key}{"start"})/) 12 448 460
30 12 $class->push_children( $id, $key );
31 # warn 'size_up:' . $line . ':' .$id.':'. scalar @{$Text::Livedoor::Wiki::scratchpad->{block}{$id}{children}};
32 }
33 }
34  
35 257 ▶ if ( my $child = $class->get_child($id) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $child = $class->get_child($id)) 49 208 257
36 49 ▶ if ( $line =~ m/\G($trigger->{$child}{end})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\G($trigger->{$child}{'end'})/) { } 12 37 49
37 #warn 'killed:' . $id . ':' .$line ;
38 12 $class->kill_child( $id );
39 12 return 0;
40 }
41 else {
42 37 return 0;
43 }
44 }
45  
46  
47 208 1;
48 }
49  
50 12 ▶sub kill_child {
Subroutine kill_child: called CC=1 SCAR=0.0
Pod documented
51 12 my $class = shift;
52 12 my $id = shift;
53 12 pop @{$Text::Livedoor::Wiki::scratchpad->{block}{$id}{children}};
54 }
55  
56 602 ▶sub get_child {
Subroutine get_child: called CC=2 SCAR=6.9
Pod documented
57 602 my $class = shift;
58 602 my $id = shift;
59 602 ▶ return unless $Text::Livedoor::Wiki::scratchpad->{block}{$id}{children};
Branch: 1 branch
BranchTrueFalseTotal
unless $Text::Livedoor::Wiki::scratchpad->{"block"}{$id}{"children"} 487 115 602
60  
61 115 return $Text::Livedoor::Wiki::scratchpad->{block}{$id}{children}[-1];
62 }
63  
64 12 ▶sub push_children {
Subroutine push_children: called CC=2 SCAR=6.9
Pod documented
65 12 my $class = shift;
66 12 my $id = shift;
67 12 my $key = shift;
68 12 ▶ $Text::Livedoor::Wiki::scratchpad->{block}{$id}{children} ||= [];
Condition100%2/2
$Text::Livedoor::Wiki::scratchpad->{"block"}{$id}{"children"} ||= []
l!l
39
MC/DC100%1/1
$Text::Livedoor::Wiki::scratchpad->{"block"}{$id}{"children"} ||= []
$Text::Livedoor::Wiki::scratchpad->{"block"}{$id}{"children"}
Truth table100%2/2
A
A= $Text::Livedoor::Wiki::scratchpad->{"block"}{$id}{"children"}
Aresult
11
00
69 12 push @{ $Text::Livedoor::Wiki::scratchpad->{block}{$id}{children} }, $key;
70 }
71  
72 15 ▶sub opts {
Subroutine opts: called CC=1 SCAR=0.0
Pod documented
73 15 return $Text::Livedoor::Wiki::opts;
74 }
75 7 1;
76  
77 =head1 NAME
78  
79 Text::Livedoor::Wiki::Plugin::Block - Block Plugin Base Class
80  
81 =head1 DESCRIPTION
82  
83 you can use this class as base to create Base Plugin.
84  
85 =head1 SYNOPSIS
86  
87 package Text::Livedoor::Wiki::Plugin::Block::Pre;
88
89 use warnings;
90 use strict;
91 use base qw(Text::Livedoor::Wiki::Plugin::Block);
92
93 sub check {
94 my $self = shift;
95 my $line = shift;
96 my $args = shift;
97 my $on_next = $args->{on_next};
98
99 if( $line =~ /^\^/ ) {
100 $line =~ s/^\^// unless $on_next;;
101 return { line => $line . "\n" };
102 }
103 return;
104
105 }
106
107 sub get {
108 my $self = shift;
109 my $block = shift;
110 my $inline = shift;
111 my $items = shift;
112 my $html = '';
113 $html .= $inline->parse( $_->{line} ) . "\n" for @$items;
114 return "<pre>\n$html</pre>\n";
115
116 }
117 1;
118
119 =head1 FUNCTION
120  
121 =head2 trigger
122  
123 for $class->trigger_check. If your plugin has start tag and end tag then you should set it ,
124 otherwise the other plugin does not know your plugin so , they may be mess up your block.
125  
126 =over 4
127  
128 =item start
129  
130 regexp for start tag
131  
132 =item end
133  
134 regexp for end tag
135  
136 =item escape
137  
138 set 1 if your plugin escape Wiki parser in your block.
139  
140 =back
141  
142 =head2 check
143  
144 implement validation
145  
146 =head2 get
147  
148 implement Wiki to HTML.
149  
150 =head2 mobile
151  
152 if you did not use it , then $class->get() return.
153  
154 =head2 trigger_check
155  
156 use checking the other plugin status.
157  
158 =head2 kill_child
159  
160 kill child block
161  
162 =head2 get_child
163  
164 get child block
165  
166 =head2 push_children
167  
168 push new child
169  
170 =head2 opts
171  
172 get opts
173  
174 =head1 AUTHOR
175  
176 polocky
177  
178 =cut
« Wiki/Plugin/Function/Pad.pm ↑ Summary Wiki/Plugin/Function/Color.pm »