| 1 | package Text::Livedoor::Wiki; | ||||||||||||
| 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 Scalar::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 10 | ▶ | use Text::Livedoor::Wiki::Block; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 10 | ▶ | use Text::Livedoor::Wiki::CatalogKeeper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 10 | ▶ | use Text::Livedoor::Wiki::Function; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 10 | ▶ | use Text::Livedoor::Wiki::IDKeeper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 10 | ▶ | use Text::Livedoor::Wiki::Inline; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 10 | ▶ | use Text::Livedoor::Wiki::Plugin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 10 | our $VERSION ='0.02'; | |||||||||||
| 14 | |||||||||||||
| 15 | # Everybody can not be happy but I am happy. | ||||||||||||
| 16 | 9 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||
| 17 | 9 | my $class = shift; | |||||||||||
| 18 | 9 | ▶ | my $self = shift || {}; | ||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 19 | # * god bless you | ||||||||||||
| 20 | 9 | $self = bless $self, $class; | |||||||||||
| 21 | |||||||||||||
| 22 | # * initialize args | ||||||||||||
| 23 | 9 | ▶ | my $block_plugins = $self->{block_plugins} ? $self->{block_plugins} : Text::Livedoor::Wiki::Plugin->block_plugins; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 9 | ▶ | my $inline_plugins = $self->{inline_plugins} ? $self->{inline_plugins} : Text::Livedoor::Wiki::Plugin->inline_plugins; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | 9 | ▶ | my $function_plugins= $self->{function_plugins} ? $self->{function_plugins} : Text::Livedoor::Wiki::Plugin->function_plugins; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 9 | ▶ | my $on_mobile = $self->{on_mobile} || 0; | ||||||||||
|
Condition100%2/2
$self->{'on_mobile'} || 0
MC/DC100%1/1
$self->{'on_mobile'} || 0
$self->{'on_mobile'}
Truth table100%2/2
A
A= $self->{'on_mobile'}
| |||||||||||||
| 27 | |||||||||||||
| 28 | # * creating parser objects | ||||||||||||
| 29 | 9 | my $function = Text::Livedoor::Wiki::Function->new( { plugins => $function_plugins , on_mobile => $on_mobile } ); | |||||||||||
| 30 | |||||||||||||
| 31 | $self->{inline} | ||||||||||||
| 32 | 9 | = Text::Livedoor::Wiki::Inline->new({ | |||||||||||
| 33 | plugins => $inline_plugins, | ||||||||||||
| 34 | function => $function, | ||||||||||||
| 35 | on_mobile => $on_mobile | ||||||||||||
| 36 | }); | ||||||||||||
| 37 | |||||||||||||
| 38 | # nobody likes memory leak. | ||||||||||||
| 39 | 9 | Scalar::Util::weaken($self->{inline}); | |||||||||||
| 40 | |||||||||||||
| 41 | $self->{block} | ||||||||||||
| 42 | = Text::Livedoor::Wiki::Block->new({ | ||||||||||||
| 43 | block_plugins => $block_plugins , | ||||||||||||
| 44 | inline => $self->{inline} , | ||||||||||||
| 45 | 9 | on_mobile => $on_mobile | |||||||||||
| 46 | }); | ||||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | # default options | ||||||||||||
| 50 | 9 | ▶ | $self->{opts} ||= {}; | ||||||||||
|
Condition100%2/2
$self->{"opts"} ||= {}
MC/DC100%1/1
$self->{"opts"} ||= {}
$self->{"opts"}
Truth table100%2/2
A
A= $self->{"opts"}
| |||||||||||||
| 51 | 9 | return $self; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 87 | ▶ | sub opts { $Text::Livedoor::Wiki::opts } | ||||||||||
|
Subroutine
opts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 55 | |||||||||||||
| 56 | 92 | ▶ | sub parse { | ||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 57 | 92 | my $self = shift; | |||||||||||
| 58 | 92 | my $text = shift; | |||||||||||
| 59 | 92 | ▶ | my $opts = shift || {}; | ||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 60 | 92 | %$opts = ( %{$self->{opts}}, %$opts ); | |||||||||||
| 61 | |||||||||||||
| 62 | 92 | my $want_pos = delete $opts->{want_pos} ; | |||||||||||
| 63 | # * creating scrathpad and options which scorpe is only for this parse() , so that this module can be as a Singleton. | ||||||||||||
| 64 | 92 | ▶ | $opts->{name} = $opts->{name} || 'content'; | ||||||||||
|
Condition100%2/2
$opts->{'name'} || 'content'
MC/DC100%1/1
$opts->{'name'} || 'content'
$opts->{'name'}
Truth table100%2/2
A
A= $opts->{'name'}
| |||||||||||||
| 65 | 92 | my $id_keeper = Text::Livedoor::Wiki::IDKeeper->new({ name => $opts->{name} } ); | |||||||||||
| 66 | 92 | my $catalog_keeper = Text::Livedoor::Wiki::CatalogKeeper->new(); | |||||||||||
| 67 | 92 | local $Text::Livedoor::Wiki::scratchpad = {}; | |||||||||||
| 68 | 92 | local $Text::Livedoor::Wiki::opts = { id_keeper => $id_keeper , catalog_keeper => $catalog_keeper , %$opts }; | |||||||||||
| 69 | 92 | $Text::Livedoor::Wiki::scratchpad->{core}{block_uid} = 0; | |||||||||||
| 70 | 92 | $Text::Livedoor::Wiki::scratchpad->{core}{inline_uid} = 0; | |||||||||||
| 71 | 92 | $Text::Livedoor::Wiki::scratchpad->{core}{block_trigger} = $self->{block}->trigger ; | |||||||||||
| 72 | 92 | $Text::Livedoor::Wiki::scratchpad->{core}{current_pos} = 0; | |||||||||||
| 73 | |||||||||||||
| 74 | 92 | $self->_init_text( \$text ); | |||||||||||
| 75 | 92 | my $html = $self->{block}->parse( $text ); | |||||||||||
| 76 | 90 | $html .= $self->{block}->footer_section(); | |||||||||||
| 77 | |||||||||||||
| 78 | 90 | ▶ | if( $want_pos ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | 3 | return $Text::Livedoor::Wiki::scratchpad->{core}{h3pos}; | |||||||||||
| 80 | } | ||||||||||||
| 81 | else { | ||||||||||||
| 82 | 87 | return $self->_build( $html ); | |||||||||||
| 83 | } | ||||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 92 | ▶ | sub _init_text() { | ||||||||||
|
Subroutine
_init_text: called CC=1 SCAR=0.0
| |||||||||||||
| 87 | 92 | my $self = shift; | |||||||||||
| 88 | 92 | my $text = shift; | |||||||||||
| 89 | 92 | $$text =~ s/\r//g; | |||||||||||
| 90 | 92 | $$text =~ s/\n$//; | |||||||||||
| 91 | } | ||||||||||||
| 92 | 87 | ▶ | sub _build { | ||||||||||
|
Subroutine
_build: called CC=2 SCAR=6.9
| |||||||||||||
| 93 | 87 | my $self = shift; | |||||||||||
| 94 | 87 | my $sections = shift; | |||||||||||
| 95 | 87 | my $opts = $self->opts; | |||||||||||
| 96 | |||||||||||||
| 97 | 87 | $sections =~ s/<br \/>\n$/\n/; | |||||||||||
| 98 | # TODO customize class name | ||||||||||||
| 99 | # * build sections | ||||||||||||
| 100 | 87 | my $html = qq|<div class="user-area">\n|; | |||||||||||
| 101 | 87 | $html .= $sections; | |||||||||||
| 102 | 87 | $html .= qq|</div>\n|; | |||||||||||
| 103 | |||||||||||||
| 104 | # * build contents | ||||||||||||
| 105 | 87 | ▶ | if( !$self->{on_mobile} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 76 | my $catalog_keeper = $opts->{catalog_keeper}; | |||||||||||
| 107 | 76 | my $contents = $catalog_keeper->contents(); | |||||||||||
| 108 | 76 | $html =~ s/\n#contents/\n$contents\n/g; | |||||||||||
| 109 | } | ||||||||||||
| 110 | else { | ||||||||||||
| 111 | 11 | $html =~ s/\n#contents<br \/>\n/\n/g; | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 87 | return $html; | |||||||||||
| 115 | |||||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | |||||||||||||
| 119 | 10 | 1; | |||||||||||
| 120 | |||||||||||||
| 121 | =head1 NAME | ||||||||||||
| 122 | |||||||||||||
| 123 | Text::Livedoor::Wiki - Perl extension for formatting text with livedoor Wiki Style. | ||||||||||||
| 124 | |||||||||||||
| 125 | =head1 SYNOPSIS | ||||||||||||
| 126 | |||||||||||||
| 127 | use Text::Livedoor::Wiki; | ||||||||||||
| 128 | my $parser = Text::Livedoor::Wiki->new( { opts => { storage => 'http://static.wiki.livedoor.jp/formatter-storage' } } ); | ||||||||||||
| 129 | |||||||||||||
| 130 | my $data = "* ''polocky''"; | ||||||||||||
| 131 | $html = $parser->parse( $data ); | ||||||||||||
| 132 | |||||||||||||
| 133 | =head1 DESCRIPTION | ||||||||||||
| 134 | |||||||||||||
| 135 | This is livedoor Wiki Style Parser. you can download CSS and images from http://static.wiki.livedoor.jp/download/livedoor-wiki.0.02.tar.gz | ||||||||||||
| 136 | |||||||||||||
| 137 | =head1 METHOD | ||||||||||||
| 138 | |||||||||||||
| 139 | =head2 new | ||||||||||||
| 140 | |||||||||||||
| 141 | constructor. you can set arguments as hash ref. | ||||||||||||
| 142 | |||||||||||||
| 143 | =over 4 | ||||||||||||
| 144 | |||||||||||||
| 145 | =item block_plugins | ||||||||||||
| 146 | |||||||||||||
| 147 | set list of block plugins you want to load. default is Text::Livedoor::Wiki::Plugin->block_plugins | ||||||||||||
| 148 | |||||||||||||
| 149 | =item inline_plugins | ||||||||||||
| 150 | |||||||||||||
| 151 | set list of inline plugins you want to load. default is Text::Livedoor::Wiki::Plugin->inline_plugins | ||||||||||||
| 152 | |||||||||||||
| 153 | =item function_plugins | ||||||||||||
| 154 | |||||||||||||
| 155 | set list of function plugins you want to load. default is Text::Livedoor::Wiki::Plugin->function_plugins | ||||||||||||
| 156 | |||||||||||||
| 157 | =item on_mobile | ||||||||||||
| 158 | |||||||||||||
| 159 | set 1 for mobile mode. | ||||||||||||
| 160 | |||||||||||||
| 161 | =back | ||||||||||||
| 162 | |||||||||||||
| 163 | =head2 parse | ||||||||||||
| 164 | |||||||||||||
| 165 | parse Wiki to HTML. | ||||||||||||
| 166 | |||||||||||||
| 167 | $parser->parse( $wiki, { your_options => 'hoge' } ); | ||||||||||||
| 168 | |||||||||||||
| 169 | =head2 opts | ||||||||||||
| 170 | |||||||||||||
| 171 | get options | ||||||||||||
| 172 | |||||||||||||
| 173 | =head1 AUTHOR | ||||||||||||
| 174 | |||||||||||||
| 175 | Polocky | ||||||||||||
| 176 | |||||||||||||
| 177 | =head1 SEE ALSO | ||||||||||||
| 178 | |||||||||||||
| 179 | http://wiki.livedoor.com (Japanese) | ||||||||||||
| 180 | http://wiki.livedoor.jp/wiki_text/ (Japanese) | ||||||||||||
| 181 | |||||||||||||
| 182 | =cut | ||||||||||||