| 1 | package Text::Livedoor::Wiki::Block; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | 9 | my $class = shift; | |||||||||||||||||||||||||||
| 10 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 11 | 9 | $self = bless $self , $class; | |||||||||||||||||||||||||||
| 12 | 9 | Scalar::Util::weaken($self->{inline}); | |||||||||||||||||||||||||||
| 13 | 9 | $self->_load( $self->{block_plugins} ); | |||||||||||||||||||||||||||
| 14 | 9 | return $self; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | 234 | ▶ | sub blocks { shift->{blocks} } | ||||||||||||||||||||||||||
|
Subroutine
blocks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 92 | ▶ | sub trigger{ shift->{trigger} } | ||||||||||||||||||||||||||
|
Subroutine
trigger: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 83 | ▶ | sub inline { shift->{inline}->parse(@_); } | ||||||||||||||||||||||||||
|
Subroutine
inline: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 148 | ▶ | sub on_mobile{ shift->{on_mobile} } | ||||||||||||||||||||||||||
|
Subroutine
on_mobile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | #XXX only for footnote plugin for now | ||||||||||||||||||||||||||||
| 22 | 90 | ▶ | sub footer_section { | ||||||||||||||||||||||||||
|
Subroutine
footer_section: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 90 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 90 | my $res = ''; | |||||||||||||||||||||||||||
| 25 | 90 | my $footnotes = $Text::Livedoor::Wiki::scratchpad->{footnotes}; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 90 | ▶ | if( $footnotes ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 3 | $res =qq|<div class="footer-footnote">\n<hr />\n<ul class="list-1">\n|; | |||||||||||||||||||||||||||
| 29 | 3 | my $cnt = 1; | |||||||||||||||||||||||||||
| 30 | 3 | for ( @$footnotes ) { | |||||||||||||||||||||||||||
| 31 | 4 | $res .=qq|<li><a href="#footnote$cnt" name="footer-footnote$cnt">*$cnt </a> : $_</li>\n|; | |||||||||||||||||||||||||||
| 32 | 4 | $cnt++; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 3 | $res .="<ul>\n</div>\n"; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 90 | return $res; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 992 | ▶ | sub opts { $Text::Livedoor::Wiki::opts } | ||||||||||||||||||||||||||
|
Subroutine
opts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 178 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 178 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | 178 | my $text = shift; | |||||||||||||||||||||||||||
| 43 | 178 | my $nested = shift; | |||||||||||||||||||||||||||
| 44 | 178 | my $catalog_keeper = $self->opts->{catalog_keeper}; | |||||||||||||||||||||||||||
| 45 | 178 | my $id_keeper = $self->opts->{id_keeper}; | |||||||||||||||||||||||||||
| 46 | 178 | my $skip_catalog = $self->opts->{skip_catalog}; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 178 | my @lines = split("\n" ,$text , -1 ); | |||||||||||||||||||||||||||
| 49 | 178 | my $html = ''; | |||||||||||||||||||||||||||
| 50 | 178 | my @items = (); | |||||||||||||||||||||||||||
| 51 | 178 | my $last = scalar @lines; | |||||||||||||||||||||||||||
| 52 | 178 | my $cnt = 0; | |||||||||||||||||||||||||||
| 53 | 178 | my $on_processing = 0; | |||||||||||||||||||||||||||
| 54 | 178 | my $current_block ; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 178 | $Text::Livedoor::Wiki::scratchpad->{core}{block_uid}++; | |||||||||||||||||||||||||||
| 57 | LINE : | ||||||||||||||||||||||||||||
| 58 | 178 | for ( @lines ) { | |||||||||||||||||||||||||||
| 59 | 458 | ▶ | $Text::Livedoor::Wiki::scratchpad->{core}{current_pos}++ unless $nested; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | #warn $Text::Livedoor::Wiki::scratchpad->{core}{current_pos} . ':' . $_ unless $nested; | ||||||||||||||||||||||||||||
| 61 | 458 | $cnt++; | |||||||||||||||||||||||||||
| 62 | 458 | ▶ | my $blocks_cache = $on_processing ? [$current_block] : $self->blocks ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 458 | my $id = $self->opts->{name} . '_block_' . $Text::Livedoor::Wiki::scratchpad->{core}{block_uid} ; | |||||||||||||||||||||||||||
| 64 | 458 | for my $block ( @{$blocks_cache} ) { | |||||||||||||||||||||||||||
| 65 | 2391 | ▶ | if( my $res = $block->check($_ , { id => $id , on_next => 0 , inline => $self->{inline} } ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 373 | $current_block= $block; | |||||||||||||||||||||||||||
| 67 | 373 | $on_processing = 1; | |||||||||||||||||||||||||||
| 68 | 373 | push @items, $res; | |||||||||||||||||||||||||||
| 69 | 373 | ▶ | if( $last != $cnt ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 287 | ▶ | unless( my $next_res = $block->check($lines[$cnt] , { id => $id , on_next => 1 , inline => $self->{inline} } ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 62 | ▶ | $html =~ s/<br \/>\n$// unless $Text::Livedoor::Wiki::scratchpad->{skip_ajust_block_break}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 62 | $Text::Livedoor::Wiki::scratchpad->{skip_ajust_block_break} = 0; | |||||||||||||||||||||||||||
| 73 | 62 | ▶ | $html .= $self->on_mobile ? $block->mobile( $self, $self->{inline} , \@items) : $block->get( $self, $self->{inline} , \@items ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 62 | @items = (); | |||||||||||||||||||||||||||
| 75 | 62 | $Text::Livedoor::Wiki::scratchpad->{core}{block_uid}++; | |||||||||||||||||||||||||||
| 76 | 62 | $on_processing = 0; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | else { | ||||||||||||||||||||||||||||
| 80 | #$html =~ s/<br \/>\n$//; | ||||||||||||||||||||||||||||
| 81 | 86 | ▶ | $html =~ s/<br \/>\n$// unless $Text::Livedoor::Wiki::scratchpad->{skip_ajust_block_break}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 86 | ▶ | $html .= $self->on_mobile ? $block->mobile( $self, $self->{inline} , \@items) : $block->get( $self , $self->{inline} , \@items ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 86 | @items = (); | |||||||||||||||||||||||||||
| 84 | 86 | $Text::Livedoor::Wiki::scratchpad->{core}{block_uid}++; | |||||||||||||||||||||||||||
| 85 | 86 | $on_processing = 0; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 373 | next LINE; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 83 | my $text= $self->inline($_) ; | |||||||||||||||||||||||||||
| 92 | 83 | ▶ | if( length $text ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 69 | $html .= $text . qq|<br />\n|; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||
| 96 | 14 | $html .= qq|<br />\n|; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 176 | $on_processing = 0; # in case | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | #hoge<br /> <- remove this <br /> | ||||||||||||||||||||||||||||
| 102 | 176 | $html =~ s/<br \/>\n$//; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 176 | ▶ | if( $html && !($html =~ /\n$/) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$html and not $html =~ /\n$/
MC/DC100%2/2
$html and not $html =~ /\n$/
$html
not $html =~ /\n$/
Truth table100%3/3
A and not(B)
A= $htmlB= not $html =~ /\n$/
| |||||||||||||||||||||||||||||
| 105 | 44 | $html .= "\n"; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 176 | return $html; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 9 | ▶ | sub _load { | ||||||||||||||||||||||||||
|
Subroutine
_load: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 111 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | 9 | my $plugins = shift; | |||||||||||||||||||||||||||
| 113 | 9 | my $trigger = {}; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 9 | for (@$plugins ) { | |||||||||||||||||||||||||||
| 116 | 81 | $_->require; | |||||||||||||||||||||||||||
| 117 | 81 | ▶ | $trigger->{$_} = $_->trigger if $_->trigger; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 9 | $self->{blocks} = $plugins; | |||||||||||||||||||||||||||
| 120 | 9 | $self->{trigger} = $trigger; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 10 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head1 NAME | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Text::Livedoor::Wiki::Block - Block Parser | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | block parser. supporting block has block :-) | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =head1 METHOD | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head2 blocks | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 footer_section | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head2 inline | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =head2 new | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head2 on_mobile | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head2 opts | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head2 parse | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 trigger | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | polocky | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||