line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MediawikiFormat::Block; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
207
|
use strict; |
|
14
|
|
|
|
|
17
|
|
|
14
|
|
|
|
|
462
|
|
4
|
14
|
|
|
14
|
|
69
|
use warnings::register; |
|
14
|
|
|
|
|
100
|
|
|
14
|
|
|
|
|
1438
|
|
5
|
|
|
|
|
|
|
|
6
|
14
|
|
|
14
|
|
65
|
use Scalar::Util qw( blessed reftype ); |
|
14
|
|
|
|
|
42
|
|
|
14
|
|
|
|
|
5190
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
11
|
|
|
|
|
|
|
{ |
12
|
315
|
|
|
315
|
0
|
882
|
my ($class, %args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
315
|
|
100
|
|
|
1065
|
$args{text} = $class->arg_to_ref (delete $args{text} || ''); |
15
|
315
|
|
100
|
|
|
923
|
$args{args} = [$class->arg_to_ref (delete $args{args} || [])]; |
16
|
|
|
|
|
|
|
|
17
|
315
|
|
|
|
|
1080
|
bless \%args, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub arg_to_ref |
21
|
|
|
|
|
|
|
{ |
22
|
630
|
|
|
630
|
0
|
531
|
my ($class, $value) = @_; |
23
|
630
|
100
|
100
|
|
|
2433
|
return $value if ( reftype( $value ) || '' ) eq 'ARRAY'; |
24
|
309
|
|
|
|
|
608
|
return [ $value ]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub shift_args |
28
|
|
|
|
|
|
|
{ |
29
|
32
|
|
|
32
|
0
|
34
|
my $self = shift; |
30
|
32
|
|
|
|
|
22
|
my $args = shift @{ $self->{args} }; |
|
32
|
|
|
|
|
43
|
|
31
|
32
|
50
|
|
|
|
106
|
return wantarray ? @$args : $args; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub all_args |
35
|
|
|
|
|
|
|
{ |
36
|
83
|
|
|
83
|
0
|
89
|
my $args = $_[0]{args}; |
37
|
83
|
50
|
|
|
|
228
|
return wantarray ? @$args : $args; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub text |
41
|
|
|
|
|
|
|
{ |
42
|
262
|
|
|
262
|
0
|
305
|
my $text = $_[0]{text}; |
43
|
262
|
50
|
|
|
|
715
|
return wantarray ? @$text : $text; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub add_text |
47
|
|
|
|
|
|
|
{ |
48
|
100
|
|
|
100
|
0
|
80
|
my $self = shift; |
49
|
100
|
|
|
|
|
85
|
push @{ $self->{text} }, @_; |
|
100
|
|
|
|
|
167
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub formatted_text |
53
|
|
|
|
|
|
|
{ |
54
|
130
|
|
|
130
|
0
|
171
|
my $self = shift; |
55
|
234
|
100
|
|
|
|
673
|
return map |
56
|
|
|
|
|
|
|
{ |
57
|
130
|
|
|
|
|
205
|
blessed( $_ ) ? $_ : $self->formatter( $_ ) |
58
|
|
|
|
|
|
|
} $self->text(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub formatter |
62
|
|
|
|
|
|
|
{ |
63
|
216
|
|
|
216
|
0
|
225
|
my ($self, $line) = @_; |
64
|
216
|
|
|
|
|
348
|
Text::MediawikiFormat::format_line ($line, $self->tags(), |
65
|
|
|
|
|
|
|
$self->opts()); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_args |
69
|
|
|
|
|
|
|
{ |
70
|
83
|
|
|
83
|
0
|
62
|
my $self = shift; |
71
|
83
|
|
|
|
|
61
|
push @{ $self->{args} }, @_; |
|
83
|
|
|
|
|
129
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
{ |
75
|
14
|
|
|
14
|
|
71
|
no strict 'refs'; |
|
14
|
|
|
|
|
15
|
|
|
14
|
|
|
|
|
3496
|
|
76
|
|
|
|
|
|
|
for my $attribute (qw( level opts tags type )) |
77
|
|
|
|
|
|
|
{ |
78
|
2073
|
|
|
2073
|
|
6513
|
*{ $attribute } = sub { $_[0]{$attribute} }; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub merge |
83
|
|
|
|
|
|
|
{ |
84
|
274
|
|
|
274
|
0
|
235
|
my ($self, $next_block) = @_; |
85
|
|
|
|
|
|
|
|
86
|
274
|
100
|
|
|
|
352
|
return $next_block unless $self->type() eq $next_block->type(); |
87
|
112
|
100
|
|
|
|
230
|
return $next_block unless $self->level() == $next_block->level(); |
88
|
|
|
|
|
|
|
|
89
|
83
|
|
|
|
|
154
|
$self->add_text( $next_block->text() ); |
90
|
83
|
|
|
|
|
230
|
$self->add_args( $next_block->all_args() ); |
91
|
83
|
|
|
|
|
259
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub nests |
95
|
|
|
|
|
|
|
{ |
96
|
191
|
|
|
191
|
0
|
184
|
my ($self, $maynest) = @_; |
97
|
191
|
|
|
|
|
191
|
my $tags = $self->{tags}; |
98
|
|
|
|
|
|
|
|
99
|
191
|
|
66
|
|
|
285
|
return exists $tags->{nests}{$self->type()} |
100
|
|
|
|
|
|
|
&& exists $tags->{nests}{$maynest->type()} |
101
|
|
|
|
|
|
|
&& $self->level() < $maynest->level() |
102
|
|
|
|
|
|
|
# tags nest anywhere, regardless of level and parent |
103
|
|
|
|
|
|
|
|| exists $tags->{nests_anywhere}{$maynest->type()}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub nest |
107
|
|
|
|
|
|
|
{ |
108
|
274
|
|
|
274
|
0
|
304
|
my ($self, $next_block) = @_; |
109
|
|
|
|
|
|
|
|
110
|
274
|
100
|
|
|
|
461
|
return unless $next_block = $self->merge ($next_block); |
111
|
191
|
100
|
|
|
|
387
|
return $next_block unless $self->nests ($next_block); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# if there's a nested block at the end, maybe it can nest too |
114
|
40
|
|
|
|
|
68
|
my $last_item = ( $self->text() )[-1]; |
115
|
40
|
100
|
|
|
|
104
|
return $last_item->nest( $next_block ) if blessed( $last_item ); |
116
|
|
|
|
|
|
|
|
117
|
17
|
|
|
|
|
29
|
$self->add_text( $next_block ); |
118
|
17
|
|
|
|
|
35
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |