line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Livedoor::Wiki::Function; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
30330
|
use warnings; |
|
13
|
|
|
|
|
20
|
|
|
13
|
|
|
|
|
387
|
|
4
|
13
|
|
|
13
|
|
68
|
use strict; |
|
13
|
|
|
|
|
32
|
|
|
13
|
|
|
|
|
392
|
|
5
|
13
|
|
|
13
|
|
996
|
use UNIVERSAL::require; |
|
13
|
|
|
|
|
1823
|
|
|
13
|
|
|
|
|
85
|
|
6
|
13
|
|
|
13
|
|
6549
|
use Text::Livedoor::Wiki::Utils; |
|
13
|
|
|
|
|
35
|
|
|
13
|
|
|
|
|
163
|
|
7
|
13
|
|
|
13
|
|
360
|
use Scalar::Util (); |
|
13
|
|
|
|
|
22
|
|
|
13
|
|
|
|
|
8684
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
16
|
|
|
16
|
1
|
111
|
my $class = shift; |
11
|
16
|
|
|
|
|
40
|
my $self = shift; |
12
|
16
|
|
|
|
|
48
|
$self = bless $self, $class; |
13
|
16
|
|
|
|
|
60
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub setup { |
17
|
16
|
|
|
16
|
1
|
38
|
my $self = shift; |
18
|
16
|
|
|
|
|
34
|
my $inline = shift; |
19
|
16
|
|
|
|
|
102
|
my $plugins = delete $self->{plugins}; |
20
|
16
|
|
|
|
|
59
|
$self->{inline} = $inline ; |
21
|
16
|
|
|
|
|
97
|
Scalar::Util::weaken($self->{inline}); |
22
|
16
|
|
|
|
|
74
|
$self->_load( $plugins ); |
23
|
15
|
|
|
|
|
72
|
return 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
sub inline { |
26
|
126
|
|
|
126
|
1
|
169
|
my $self = shift; |
27
|
126
|
|
|
|
|
647
|
return $self->{inline}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
sub has_function { |
30
|
152
|
|
|
152
|
1
|
247
|
my $self = shift; |
31
|
152
|
|
|
|
|
241
|
my $function_name = shift; |
32
|
152
|
100
|
|
|
|
954
|
return $self->{function}{ $function_name } ? 1 : 0; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
sub get_args { |
35
|
151
|
|
|
151
|
1
|
200
|
my $self = shift; |
36
|
151
|
|
100
|
|
|
406
|
my $opr = shift || ''; |
37
|
151
|
|
|
|
|
318
|
$opr =~ s/\s//g; |
38
|
151
|
|
|
|
|
606
|
my @args = split(',',$opr ); |
39
|
151
|
|
|
|
|
379
|
return \@args; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
sub prepare { |
42
|
151
|
|
|
151
|
1
|
220
|
my $self = shift; |
43
|
151
|
|
|
|
|
284
|
my $function_name = shift; |
44
|
151
|
|
|
|
|
229
|
my $opr = shift; |
45
|
151
|
|
|
|
|
210
|
my $tail_part = shift; |
46
|
151
|
|
|
|
|
383
|
my $args = $self->get_args( $opr ); |
47
|
151
|
|
|
|
|
241
|
my $res = {}; |
48
|
151
|
|
|
|
|
203
|
eval { |
49
|
151
|
|
|
|
|
568
|
my $my_args = $self->{function}->{$function_name}{prepare_args}->( $args ); |
50
|
126
|
|
|
|
|
498
|
my $value = $self->{function}->{$function_name}{prepare_value}->( $tail_part ); |
51
|
126
|
|
|
|
|
585
|
$res = { args => $my_args , value => $value }; |
52
|
|
|
|
|
|
|
}; |
53
|
151
|
100
|
|
|
|
674
|
if ($@ ){ |
54
|
|
|
|
|
|
|
#warn $@; |
55
|
25
|
|
|
|
|
101
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
126
|
|
|
|
|
432
|
return $res; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub parse { |
62
|
126
|
|
|
126
|
1
|
190
|
my $self = shift; |
63
|
126
|
|
|
|
|
175
|
my $function_name = shift; |
64
|
126
|
|
|
|
|
530
|
$self->{function}->{$function_name}{process}->(@_); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
126
|
|
|
126
|
1
|
559
|
sub on_mobile { shift->{on_mobile} } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _load { |
70
|
16
|
|
|
16
|
|
33
|
my $self = shift; |
71
|
16
|
|
|
|
|
31
|
my $plugins = shift; |
72
|
16
|
|
|
|
|
41
|
my %function = (); |
73
|
16
|
|
|
|
|
45
|
for my $plugin (@$plugins) { |
74
|
159
|
100
|
|
|
|
4237
|
$plugin->require or die $@; |
75
|
|
|
|
|
|
|
$function{$plugin->function_name} = { |
76
|
|
|
|
|
|
|
operation_regexp => $plugin->operation_regexp, |
77
|
126
|
100
|
|
126
|
|
374
|
process => sub { $self->on_mobile ? $plugin->process_mobile( $self->inline , @_) : $plugin->process( $self->inline , @_) } , |
78
|
151
|
|
|
151
|
|
1020
|
prepare_args => sub { $plugin->prepare_args(@_) }, |
79
|
126
|
|
|
126
|
|
655
|
prepare_value => sub { $plugin->prepare_value(@_) } |
80
|
|
|
|
|
|
|
} |
81
|
158
|
|
|
|
|
3408
|
} |
82
|
15
|
|
|
|
|
368
|
$self->{function} = \%function; |
83
|
|
|
|
|
|
|
|
84
|
15
|
|
|
|
|
95
|
1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Text::Livedoor::Wiki::Function - Wiki Function Parser Class |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Function Parser |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHOD |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 get_args |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 has_function |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 inline |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 new |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 on_mobile |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 parse |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 prepare |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 setup |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
polocky |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |