line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MediawikiFormat::Block; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
56
|
use strict; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
520
|
|
4
|
14
|
|
|
14
|
|
59
|
use warnings::register; |
|
14
|
|
|
|
|
115
|
|
|
14
|
|
|
|
|
1305
|
|
5
|
|
|
|
|
|
|
|
6
|
14
|
|
|
14
|
|
70
|
use Scalar::Util qw( blessed reftype ); |
|
14
|
|
|
|
|
18
|
|
|
14
|
|
|
|
|
5872
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
315
|
|
|
315
|
0
|
1007
|
my ( $class, %args ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
315
|
|
100
|
|
|
1171
|
$args{text} = $class->arg_to_ref( delete $args{text} || '' ); |
14
|
315
|
|
100
|
|
|
976
|
$args{args} = [ $class->arg_to_ref( delete $args{args} || [] ) ]; |
15
|
|
|
|
|
|
|
|
16
|
315
|
|
|
|
|
1193
|
bless \%args, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub arg_to_ref { |
20
|
630
|
|
|
630
|
0
|
594
|
my ( $class, $value ) = @_; |
21
|
630
|
100
|
100
|
|
|
2733
|
return $value if ( reftype($value) || '' ) eq 'ARRAY'; |
22
|
309
|
|
|
|
|
686
|
return [$value]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub shift_args { |
26
|
32
|
|
|
32
|
0
|
35
|
my $self = shift; |
27
|
32
|
|
|
|
|
26
|
my $args = shift @{ $self->{args} }; |
|
32
|
|
|
|
|
49
|
|
28
|
32
|
50
|
|
|
|
121
|
return wantarray ? @$args : $args; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub all_args { |
32
|
83
|
|
|
83
|
0
|
122
|
my $args = $_[0]{args}; |
33
|
83
|
50
|
|
|
|
268
|
return wantarray ? @$args : $args; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub text { |
37
|
262
|
|
|
262
|
0
|
348
|
my $text = $_[0]{text}; |
38
|
262
|
50
|
|
|
|
786
|
return wantarray ? @$text : $text; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_text { |
42
|
100
|
|
|
100
|
0
|
104
|
my $self = shift; |
43
|
100
|
|
|
|
|
93
|
push @{ $self->{text} }, @_; |
|
100
|
|
|
|
|
202
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub formatted_text { |
47
|
130
|
|
|
130
|
0
|
161
|
my $self = shift; |
48
|
130
|
100
|
|
|
|
244
|
return map { blessed($_) ? $_ : $self->formatter($_) } $self->text(); |
|
234
|
|
|
|
|
791
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub formatter { |
52
|
216
|
|
|
216
|
0
|
242
|
my ( $self, $line ) = @_; |
53
|
216
|
|
|
|
|
381
|
Text::MediawikiFormat::format_line( $line, $self->tags(), $self->opts() ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub add_args { |
57
|
83
|
|
|
83
|
0
|
79
|
my $self = shift; |
58
|
83
|
|
|
|
|
75
|
push @{ $self->{args} }, @_; |
|
83
|
|
|
|
|
151
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
{ |
62
|
14
|
|
|
14
|
|
76
|
no strict 'refs'; |
|
14
|
|
|
|
|
17
|
|
|
14
|
|
|
|
|
3810
|
|
63
|
|
|
|
|
|
|
for my $attribute (qw( level opts tags type )) { |
64
|
2073
|
|
|
2073
|
|
7798
|
*{$attribute} = sub { $_[0]{$attribute} }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub merge { |
69
|
274
|
|
|
274
|
0
|
255
|
my ( $self, $next_block ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
274
|
100
|
|
|
|
414
|
return $next_block unless $self->type() eq $next_block->type(); |
72
|
112
|
100
|
|
|
|
258
|
return $next_block unless $self->level() == $next_block->level(); |
73
|
|
|
|
|
|
|
|
74
|
83
|
|
|
|
|
193
|
$self->add_text( $next_block->text() ); |
75
|
83
|
|
|
|
|
210
|
$self->add_args( $next_block->all_args() ); |
76
|
83
|
|
|
|
|
277
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub nests { |
80
|
191
|
|
|
191
|
0
|
174
|
my ( $self, $maynest ) = @_; |
81
|
191
|
|
|
|
|
218
|
my $tags = $self->{tags}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return |
84
|
191
|
|
66
|
|
|
342
|
exists $tags->{nests}{ $self->type() } |
85
|
|
|
|
|
|
|
&& exists $tags->{nests}{ $maynest->type() } |
86
|
|
|
|
|
|
|
&& $self->level() |
87
|
|
|
|
|
|
|
< $maynest->level() |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# tags nest anywhere, regardless of level and parent |
90
|
|
|
|
|
|
|
|| exists $tags->{nests_anywhere}{ $maynest->type() }; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub nest { |
94
|
274
|
|
|
274
|
0
|
356
|
my ( $self, $next_block ) = @_; |
95
|
|
|
|
|
|
|
|
96
|
274
|
100
|
|
|
|
499
|
return unless $next_block = $self->merge($next_block); |
97
|
191
|
100
|
|
|
|
441
|
return $next_block unless $self->nests($next_block); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# if there's a nested block at the end, maybe it can nest too |
100
|
40
|
|
|
|
|
82
|
my $last_item = ( $self->text() )[-1]; |
101
|
40
|
100
|
|
|
|
134
|
return $last_item->nest($next_block) if blessed($last_item); |
102
|
|
|
|
|
|
|
|
103
|
17
|
|
|
|
|
32
|
$self->add_text($next_block); |
104
|
17
|
|
|
|
|
40
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |