line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# DESCRIPTION: Utils for Perl6 Pod |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# AUTHOR: Aliaksandr P. Zahatski, |
6
|
|
|
|
|
|
|
#=============================================================================== |
7
|
|
|
|
|
|
|
package Perl6::Pod::Utl; |
8
|
6
|
|
|
6
|
|
84700
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
155
|
|
9
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
150
|
|
10
|
6
|
|
|
6
|
|
5069
|
use utf8; |
|
6
|
|
|
|
|
59
|
|
|
6
|
|
|
|
|
33
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head2 parse_pod [default_pod => 0 ] |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=item * default_pod => 0/1 , |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
switch on/off ambient mode for para out of =pod blocks. Default 0 (ambient mode) |
19
|
|
|
|
|
|
|
return ref to tree |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse_pod { |
24
|
5
|
|
|
5
|
1
|
829
|
my ( $src, %args ) = @_; |
25
|
5
|
|
|
|
|
10
|
my $r = do { |
26
|
6
|
|
|
6
|
|
9942
|
use Regexp::Grammars; |
|
6
|
|
|
|
|
104370
|
|
|
6
|
|
|
|
|
57
|
|
|
5
|
|
|
|
|
12
|
|
27
|
6
|
|
|
6
|
|
23697
|
use Perl6::Pod::Grammars; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
222
|
|
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
69
|
qr{ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
\A \Z |
33
|
|
|
|
|
|
|
}xms; |
34
|
|
|
|
|
|
|
}; |
35
|
5
|
|
|
|
|
10
|
my $tree; |
36
|
5
|
100
|
|
|
|
218
|
if ( $src =~ $r ) { |
37
|
6
|
|
|
6
|
|
4311
|
use Perl6::Pod::Lex; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
1505
|
|
38
|
4
|
|
|
|
|
51
|
$tree = Perl6::Pod::Lex->new(%args)->make_tree( $/{File} ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
1
|
|
|
|
|
16
|
return undef; |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
|
|
39
|
$tree; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 strip_vmargin $vmargin, $txt |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=begin pod |
49
|
|
|
|
|
|
|
=para |
50
|
|
|
|
|
|
|
text |
51
|
|
|
|
|
|
|
=end pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub strip_vmargin { |
56
|
20
|
|
|
20
|
1
|
42
|
my ( $vmargin, $content ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#get min margin of text |
59
|
20
|
|
|
|
|
28
|
my $min = $vmargin; |
60
|
20
|
|
|
|
|
87
|
foreach ( split( /[\n\r]/, $content ) ) { |
61
|
23
|
100
|
|
|
|
87
|
if (m/(\s+)/) { |
62
|
10
|
|
|
|
|
21
|
my $length = length($1); |
63
|
10
|
50
|
|
|
|
33
|
$min = $length if $length < $min; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#remove only if $min > 0 |
68
|
20
|
100
|
|
|
|
55
|
if ( $min > 0 ) { |
69
|
4
|
|
|
|
|
8
|
my $new_content = ''; |
70
|
4
|
|
|
|
|
15
|
foreach ( split( /[\n\r]/, $content ) ) { |
71
|
4
|
|
|
|
|
13
|
$new_content .= substr( $_, $min ) . "\n"; |
72
|
|
|
|
|
|
|
} |
73
|
4
|
|
|
|
|
7
|
$content = $new_content; |
74
|
|
|
|
|
|
|
} |
75
|
20
|
|
|
|
|
56
|
return $content; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 parse_para $text |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
parse formatting codes |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Optrions: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * allow=>[ 'A', 'B'] |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub parse_para { |
90
|
6
|
|
|
6
|
|
2638
|
use Perl6::Pod::Codeactions; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
715
|
|
91
|
13
|
|
50
|
13
|
1
|
8542
|
my $text = shift || return []; |
92
|
13
|
|
|
|
|
65
|
my %delim = ( '<' => '>', '«' => '»', '<<' => '>>' ); |
93
|
13
|
|
|
|
|
31
|
my %allow = ( '*' => 1 ); |
94
|
|
|
|
|
|
|
|
95
|
13
|
|
|
|
|
22
|
my %args = @_; |
96
|
13
|
50
|
|
|
|
39
|
if ( my $allow = $args{allow} ) { |
97
|
0
|
0
|
|
|
|
0
|
my @list = ref($allow) ? @$allow : ($allow); |
98
|
0
|
|
|
|
|
0
|
%allow = (); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#fill allowed fcodes |
101
|
0
|
|
|
|
|
0
|
@allow{@list} = (); |
102
|
|
|
|
|
|
|
} |
103
|
13
|
|
|
|
|
19
|
my $DEFER_REGEX_COMPILATION = ""; |
104
|
13
|
|
33
|
|
|
44
|
my $r = $args{reg} || do { |
105
|
6
|
|
|
6
|
|
43
|
use Regexp::Grammars; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
47
|
|
106
|
6
|
|
|
6
|
|
796
|
use Perl6::Pod::Grammars; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
391
|
|
107
|
|
|
|
|
|
|
qr{ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
\A \Z |
113
|
|
|
|
|
|
|
<[content]>+ |
114
|
|
|
|
|
|
|
.+? |
115
|
|
|
|
|
|
|
[ \t]* |
116
|
|
|
|
|
|
|
\# |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
| |
119
|
|
|
|
|
|
|
| |
120
|
|
|
|
|
|
|
| |
121
|
|
|
|
|
|
|
| |
122
|
|
|
|
|
|
|
| |
123
|
|
|
|
|
|
|
| <.text> |
124
|
|
|
|
|
|
|
<%delim> |
125
|
|
|
|
|
|
|
(??{ quotemeta $delim{$ARG{ldelim}} }) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
( $ARG{name} && ( $ARG{name} eq uc($ARG{name} ) ) ) |
129
|
|
|
|
|
|
|
&& |
130
|
|
|
|
|
|
|
( exists $allow{'*'} || exists $allow{$ARG{name}} ) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
})> |
133
|
|
|
|
|
|
|
(?! \s+) |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
(?! \s+) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
(?: \| <[syns=(\S+)]>+ % ;)? |
139
|
|
|
|
|
|
|
(?! \s+) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
(?! \s+) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#alternate presentation |
147
|
|
|
|
|
|
|
(?: \| )? #(.*) \| not work for |
148
|
|
|
|
|
|
|
#L< http://cpan.org > B L< haname | http:perl.html > |
149
|
|
|
|
|
|
|
# '' => 'L< http://cpan.org > B L< haname | http:perl.html >' |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# (?:)? #hack |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
? #scheme specifier |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
(?: )? |
156
|
|
|
|
|
|
|
? |
157
|
|
|
|
|
|
|
(?: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
<[entry=([^,\;]+?)]>* % (\s*,\s*) |
160
|
|
|
|
|
|
|
(?! \s+) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# X |
164
|
|
|
|
|
|
|
( (?{$MATCH{entry}=$MATCH{text}; $MATCH{form} = 1 }) |
165
|
|
|
|
|
|
|
| |
166
|
|
|
|
|
|
|
? \| <[entries=X_code_entry]>* % (\s*\;\s*) |
167
|
|
|
|
|
|
|
(?{$MATCH{form} = 2}) |
168
|
|
|
|
|
|
|
) |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
<.hs> |
174
|
|
|
|
|
|
|
? #scheme specifier |
175
|
|
|
|
|
|
|
(?: )? |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
<.hs> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
<.hs> <[content]>*? <.hs> |
182
|
|
|
|
|
|
|
$DEFER_REGEX_COMPILATION |
183
|
|
|
|
|
|
|
}xms; |
184
|
|
|
|
|
|
|
}; |
185
|
|
|
|
|
|
|
|
186
|
13
|
50
|
|
|
|
389
|
if ( $text =~ $r->with_actions( Perl6::Pod::Codeactions->new ) ) { |
187
|
13
|
|
|
|
|
93
|
return $/{Text}; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
else { |
190
|
0
|
|
|
|
|
|
return undef; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |
196
|
|
|
|
|
|
|
|