line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xatena::Inline::Base; |
2
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
101
|
use strict; |
|
20
|
|
|
|
|
36
|
|
|
20
|
|
|
|
|
569
|
|
4
|
20
|
|
|
20
|
|
104
|
use warnings; |
|
20
|
|
|
|
|
41
|
|
|
20
|
|
|
|
|
478
|
|
5
|
20
|
|
|
20
|
|
18468
|
use List::MoreUtils qw(any); |
|
20
|
|
|
|
|
25941
|
|
|
20
|
|
|
|
|
2928
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub import { |
8
|
43
|
|
|
43
|
|
769
|
my $class = shift; |
9
|
43
|
|
|
|
|
98
|
my $caller = caller(0); |
10
|
43
|
100
|
|
21
|
|
3215
|
if (any { $_ eq '-Base' } @_) { |
|
21
|
|
|
|
|
121
|
|
11
|
20
|
|
|
20
|
|
148
|
no strict 'refs'; |
|
20
|
|
|
|
|
40
|
|
|
20
|
|
|
|
|
1063
|
|
12
|
21
|
|
|
|
|
39
|
push @{"$caller\::ISA"}, $class; |
|
21
|
|
|
|
|
382
|
|
13
|
|
|
|
|
|
|
|
14
|
21
|
|
|
|
|
52
|
for my $method (qw/match/) { |
15
|
20
|
|
|
20
|
|
111
|
no warnings 'redefine'; |
|
20
|
|
|
|
|
39
|
|
|
20
|
|
|
|
|
2329
|
|
16
|
21
|
|
|
|
|
34
|
*{"$caller\::$method"} = \&{"$class\::$method"}; |
|
21
|
|
|
|
|
633
|
|
|
21
|
|
|
|
|
91
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub inlines { |
22
|
537
|
|
|
537
|
0
|
770
|
my ($caller) = @_; |
23
|
537
|
|
66
|
|
|
1636
|
$caller = ref($caller) || $caller; |
24
|
20
|
|
|
20
|
|
116
|
no strict 'refs'; |
|
20
|
|
|
|
|
58
|
|
|
20
|
|
|
|
|
7878
|
|
25
|
537
|
|
66
|
|
|
555
|
${$caller.'::_inlines'} ||= do { |
|
537
|
|
|
|
|
3223
|
|
26
|
41
|
|
|
|
|
116
|
my $parents = []; |
27
|
41
|
|
|
|
|
73
|
for my $isa (@{$caller.'::ISA'}) { |
|
41
|
|
|
|
|
207
|
|
28
|
21
|
|
|
|
|
156
|
my $isa = $isa->inlines; |
29
|
21
|
|
|
|
|
78
|
push @$parents, @$isa; |
30
|
|
|
|
|
|
|
} |
31
|
41
|
|
|
|
|
235
|
$parents; |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub match ($$) { ## no critic |
36
|
222
|
|
|
222
|
0
|
334
|
my ($regexp, $block) = @_; |
37
|
222
|
|
|
|
|
346
|
my $pkg = caller(0); |
38
|
222
|
|
|
|
|
484
|
push @{ $pkg->inlines }, { regexp => $regexp, block => $block }; |
|
222
|
|
|
|
|
557
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
104
|
|
|
104
|
0
|
270
|
my ($class, %opts) = @_; |
43
|
104
|
|
|
|
|
809
|
bless { |
44
|
|
|
|
|
|
|
%opts |
45
|
|
|
|
|
|
|
}, $class; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub format { |
49
|
248
|
|
|
248
|
0
|
404
|
my ($self, $text) = @_; |
50
|
248
|
|
|
|
|
453
|
$text =~ s{^\n}{}g; |
51
|
248
|
|
|
|
|
315
|
my $re = join("|", map { $_->{regexp} } @{ $self->inlines }); |
|
2710
|
|
|
|
|
4995
|
|
|
248
|
|
|
|
|
719
|
|
52
|
248
|
|
|
1
|
|
7038
|
$text =~ s{($re)}{$self->_format($1)}eg; |
|
46
|
|
|
|
|
228
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
53
|
248
|
|
|
|
|
27730
|
$text; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _format { |
57
|
46
|
|
|
46
|
|
139
|
my ($self, $string) = @_; |
58
|
46
|
|
|
|
|
66
|
for my $inline (@{ $self->inlines }) { |
|
46
|
|
|
|
|
103
|
|
59
|
312
|
100
|
|
|
|
2159
|
if (my @matched = ($string =~ $inline->{regexp})) { |
60
|
46
|
|
|
|
|
316
|
$string = $inline->{block}->($self, @matched); |
61
|
46
|
|
|
|
|
296
|
last; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
46
|
|
|
|
|
284
|
$string; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |