line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Livedoor::Wiki::Inline; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
62565
|
use warnings; |
|
12
|
|
|
|
|
22
|
|
|
12
|
|
|
|
|
323
|
|
4
|
12
|
|
|
12
|
|
60
|
use strict; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
346
|
|
5
|
12
|
|
|
12
|
|
1871
|
use UNIVERSAL::require; |
|
12
|
|
|
|
|
3410
|
|
|
12
|
|
|
|
|
84
|
|
6
|
12
|
|
|
12
|
|
1422
|
use Text::Livedoor::Wiki::Utils; |
|
12
|
|
|
|
|
24
|
|
|
12
|
|
|
|
|
86
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
16
|
|
|
16
|
1
|
128
|
my $class = shift; |
10
|
16
|
|
|
|
|
35
|
my $self = shift; |
11
|
16
|
|
|
|
|
217
|
$self = bless $self, $class; |
12
|
16
|
|
|
|
|
294
|
my $plugins = delete $self->{plugins}; |
13
|
16
|
|
|
|
|
245
|
$self->_load( $plugins ); |
14
|
15
|
|
|
|
|
82
|
$self->function->setup( $self ); |
15
|
15
|
|
|
|
|
92
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
444
|
|
|
444
|
1
|
2170
|
sub function { shift->{function} } |
19
|
|
|
|
|
|
|
sub _build_catchall { |
20
|
493
|
|
|
493
|
|
619
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
5938
|
|
|
|
|
20865
|
my $regex |
23
|
493
|
|
|
|
|
638
|
= join( '|', map { '(' . $_->{regex} . ')' } @{ $self->{elements} } ); |
|
493
|
|
|
|
|
1783
|
|
24
|
493
|
|
|
|
|
3986
|
return q{((?:.|^|$)+?(?=} . $regex . q{|$))}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _no_match { |
28
|
432
|
|
|
432
|
|
897
|
my ( $self, $char ) = @_; |
29
|
432
|
|
|
|
|
2297
|
return Text::Livedoor::Wiki::Utils::escape($char); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub parse { |
33
|
538
|
|
|
538
|
1
|
295136
|
my $self = shift; |
34
|
538
|
|
|
|
|
877
|
my $line = shift; |
35
|
538
|
100
|
|
|
|
1826
|
return '' unless defined $line; |
36
|
|
|
|
|
|
|
|
37
|
535
|
|
|
|
|
1655
|
chomp($line); |
38
|
|
|
|
|
|
|
|
39
|
535
|
100
|
|
|
|
2614
|
return '' if ( $line eq '' ); |
40
|
|
|
|
|
|
|
|
41
|
493
|
|
|
|
|
1297
|
my $catchall = { |
42
|
|
|
|
|
|
|
regex => $self->_build_catchall, |
43
|
|
|
|
|
|
|
n_args => 1, |
44
|
|
|
|
|
|
|
process => \&_no_match, |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
493
|
|
|
|
|
923
|
my $formatted = ''; |
48
|
|
|
|
|
|
|
|
49
|
493
|
|
|
|
|
605
|
do { |
50
|
639
|
|
|
|
|
823
|
for my $element ( @{$self->{elements}}, $catchall ) { |
|
639
|
|
|
|
|
1648
|
|
51
|
6673
|
100
|
|
|
|
569834
|
if ( $line =~ m/\G($element->{regex})/gcis ) { |
52
|
639
|
|
|
|
|
1976
|
$Text::Livedoor::Wiki::scratchpad->{core}{inline_uid}++; |
53
|
639
|
|
|
|
|
1116
|
my $arg_idx = 0; |
54
|
639
|
|
|
|
|
58677
|
my $matched = eval( q{$} . ( ++$arg_idx ) ); |
55
|
639
|
|
|
|
|
2875
|
my @args = map { eval( q{$} . ( ++$arg_idx ) ) } ( 1 .. $element->{n_args} ); |
|
1106
|
|
|
|
|
67260
|
|
56
|
639
|
|
|
|
|
1475
|
$formatted .= &{$element->{process}}( $self, @args ); |
|
639
|
|
|
|
|
1955
|
|
57
|
639
|
|
|
|
|
27581
|
last; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} while ( pos($line) < length($line) ); |
61
|
|
|
|
|
|
|
|
62
|
493
|
|
|
|
|
2699
|
return $formatted; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
207
|
|
|
207
|
1
|
2353
|
sub on_mobile { shift->{on_mobile} } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _load { |
69
|
16
|
|
|
16
|
|
36
|
my $self = shift; |
70
|
16
|
|
|
|
|
37
|
my $plugins = shift; |
71
|
16
|
|
|
|
|
74
|
$plugins = $self->_sort( $plugins ); |
72
|
15
|
|
|
|
|
49
|
my @elements = (); |
73
|
15
|
|
|
|
|
47
|
for my $plugin (@$plugins) { |
74
|
|
|
|
|
|
|
my $element = { |
75
|
|
|
|
|
|
|
regex => $plugin->regex, |
76
|
|
|
|
|
|
|
n_args => $plugin->n_args, |
77
|
207
|
100
|
|
207
|
|
566
|
process => sub { $self->on_mobile ? $plugin->process_mobile(@_) : $plugin->process(@_) } , |
78
|
139
|
|
|
|
|
843
|
}; |
79
|
139
|
|
|
|
|
2091
|
push @elements , $element; |
80
|
|
|
|
|
|
|
} |
81
|
15
|
|
|
|
|
59
|
$self->{elements} = \@elements; |
82
|
|
|
|
|
|
|
|
83
|
15
|
|
|
|
|
43
|
1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# XXX this sort function is idiot but it's work for now :-p |
87
|
|
|
|
|
|
|
sub _sort { |
88
|
16
|
|
|
16
|
|
31
|
my $self = shift; |
89
|
16
|
|
|
|
|
198
|
my $plugins = shift; |
90
|
16
|
|
|
|
|
283
|
@$plugins = sort @$plugins; |
91
|
16
|
|
|
|
|
46
|
my @sorted_plugins = (); |
92
|
16
|
|
|
|
|
39
|
my %remember_me = (); |
93
|
16
|
|
|
|
|
763
|
my @stacks = (); |
94
|
16
|
|
|
|
|
50
|
for ( @$plugins ) { |
95
|
140
|
100
|
|
|
|
1178
|
$_->require() or die $@; |
96
|
139
|
|
|
|
|
2745
|
$remember_me{ $_ } = 1; |
97
|
139
|
|
|
|
|
911
|
my $dependency = $_->dependency ; |
98
|
139
|
100
|
100
|
|
|
2396
|
if ( $dependency && !$remember_me{ $dependency } ) { |
99
|
34
|
|
|
|
|
65
|
push @stacks , $_; |
100
|
34
|
|
|
|
|
85
|
next; |
101
|
|
|
|
|
|
|
} |
102
|
105
|
|
|
|
|
277
|
push @sorted_plugins , $_; |
103
|
|
|
|
|
|
|
} |
104
|
15
|
|
|
|
|
55
|
push @sorted_plugins , @stacks; |
105
|
15
|
|
|
|
|
91
|
return \@sorted_plugins; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 NAME |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Text::Livedoor::Wiki::Inline - Wiki Inline Parser |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
inline parser |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHOD |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 function |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 new |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 on_mobile |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 parse |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
polocky |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |