our
@ISA
= (
'Pod::Simple::PullParser'
);
our
$VERSION
=
'3.45'
;
BEGIN {
if
(
defined
&DEBUG
) { }
elsif
(
defined
&Pod::Simple::DEBUG
) {
*DEBUG
= \
&Pod::Simple::DEBUG
}
else
{
*DEBUG
=
sub
() {0}; }
}
our
$Doctype_decl
||=
''
;
our
$Content_decl
||=
q{<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >}
;
our
$HTML_EXTENSION
;
$HTML_EXTENSION
=
'.html'
unless
defined
$HTML_EXTENSION
;
our
$Computerese
;
$Computerese
=
""
unless
defined
$Computerese
;
our
$LamePad
;
$LamePad
=
''
unless
defined
$LamePad
;
our
$Linearization_Limit
;
$Linearization_Limit
= 120
unless
defined
$Linearization_Limit
;
our
$Perldoc_URL_Prefix
;
unless
defined
$Perldoc_URL_Prefix
;
our
$Perldoc_URL_Postfix
;
$Perldoc_URL_Postfix
=
''
unless
defined
$Perldoc_URL_Postfix
;
our
$Man_URL_Postfix
=
''
;
our
$Title_Prefix
;
$Title_Prefix
=
''
unless
defined
$Title_Prefix
;
our
$Title_Postfix
;
$Title_Postfix
=
''
unless
defined
$Title_Postfix
;
our
%ToIndex
=
map
{;
$_
=> 1 }
qw(head1 head2 head3 head4 )
;
__PACKAGE__->_accessorize(
'perldoc_url_prefix'
,
'perldoc_url_postfix'
,
'man_url_prefix'
,
'man_url_postfix'
,
'batch_mode'
,
'batch_mode_current_level'
,
'title_prefix'
,
'title_postfix'
,
'html_h_level'
,
'html_header_before_title'
,
'html_header_after_title'
,
'html_footer'
,
'top_anchor'
,
'index'
,
'html_css'
,
'html_javascript'
,
'force_title'
,
'default_title'
,
);
my
@_to_accept
;
our
%Tagmap
= (
'Verbatim'
=>
"\n<pre$Computerese>"
,
'/Verbatim'
=>
"</pre>\n"
,
'VerbatimFormatted'
=>
"\n<pre$Computerese>"
,
'/VerbatimFormatted'
=>
"</pre>\n"
,
'VerbatimB'
=>
"<b>"
,
'/VerbatimB'
=>
"</b>"
,
'VerbatimI'
=>
"<i>"
,
'/VerbatimI'
=>
"</i>"
,
'VerbatimBI'
=>
"<b><i>"
,
'/VerbatimBI'
=>
"</i></b>"
,
'Data'
=>
"\n"
,
'/Data'
=>
"\n"
,
'head1'
=>
"\n<h1>"
,
'head2'
=>
"\n<h2>"
,
'head3'
=>
"\n<h3>"
,
'head4'
=>
"\n<h4>"
,
'head5'
=>
"\n<h5>"
,
'head6'
=>
"\n<h6>"
,
'/head1'
=>
"</a></h1>\n"
,
'/head2'
=>
"</a></h2>\n"
,
'/head3'
=>
"</a></h3>\n"
,
'/head4'
=>
"</a></h4>\n"
,
'/head5'
=>
"</a></h5>\n"
,
'/head6'
=>
"</a></h6>\n"
,
'X'
=>
"<!--\n\tINDEX: "
,
'/X'
=>
"\n-->"
,
changes(
qw(
Para=p
B=b I=i
over-bullet=ul
over-number=ol
over-text=dl
over-block=blockquote
item-bullet=li
item-number=li
item-text=dt
)
),
changes2(
map
{; m/^([-a-z]+)/s &&
push
@_to_accept
, $1;
$_
}
qw[
sample=samp
definition=dfn
keyboard=kbd
variable=var
citation=cite
abbreviation=abbr
acronym=acronym
subscript=sub
superscript=sup
big=big
small=small
underline=u
strikethrough=s
preformat=pre
teletype=tt
]
),
'/item-bullet'
=>
"</li>$LamePad\n"
,
'/item-number'
=>
"</li>$LamePad\n"
,
'/item-text'
=>
"</a></dt>$LamePad\n"
,
'item-body'
=>
"\n<dd>"
,
'/item-body'
=>
"</dd>\n"
,
'B'
=>
"<b>"
,
'/B'
=>
"</b>"
,
'I'
=>
"<i>"
,
'/I'
=>
"</i>"
,
'F'
=>
"<em$Computerese>"
,
'/F'
=>
"</em>"
,
'C'
=>
"<code$Computerese>"
,
'/C'
=>
"</code>"
,
'L'
=>
"<a href='YOU_SHOULD_NEVER_SEE_THIS'>"
,
'/L'
=>
"</a>"
,
);
sub
changes {
return
map
{; m/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s
? ( $1, =>
"\n<$2>"
,
"/$1"
, =>
"</$2>\n"
) :
die
"Funky $_"
}
@_
;
}
sub
changes2 {
return
map
{; m/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s
? ( $1, =>
"<$2>"
,
"/$1"
, =>
"</$2>"
) :
die
"Funky $_"
}
@_
;
}
sub
go { Pod::Simple::HTML->parse_from_file(
@ARGV
);
exit
0 }
sub
new {
my
$new
=
shift
->SUPER::new(
@_
);
$new
->nbsp_for_S(1);
$new
->accept_targets(
'html'
,
'HTML'
);
$new
->accept_codes(
'VerbatimFormatted'
);
$new
->accept_codes(
@_to_accept
);
DEBUG > 2 and
print
STDERR
"To accept: "
,
join
(
' '
,
@_to_accept
),
"\n"
;
$new
->perldoc_url_prefix(
$Perldoc_URL_Prefix
);
$new
->perldoc_url_postfix(
$Perldoc_URL_Postfix
);
$new
->man_url_prefix(
$Man_URL_Prefix
);
$new
->man_url_postfix(
$Man_URL_Postfix
);
$new
->title_prefix(
$Title_Prefix
);
$new
->title_postfix(
$Title_Postfix
);
$new
->html_header_before_title(
qq[$Doctype_decl<html><head><title>]
);
$new
->html_header_after_title(
join
"\n"
=>
"</title>"
,
$Content_decl
,
"</head>\n<body class='pod'>"
,
$new
->version_tag_comment,
"<!-- start doc -->\n"
,
);
$new
->html_footer(
qq[\n<!-- end doc -->\n\n</body></html>\n]
);
$new
->top_anchor(
"<a name='___top' class='dummyTopAnchor' ></a>\n"
);
$new
->{
'Tagmap'
} = {
%Tagmap
};
return
$new
;
}
sub
__adjust_html_h_levels {
my
(
$self
) =
@_
;
my
$Tagmap
=
$self
->{
'Tagmap'
};
my
$add
=
$self
->html_h_level;
return
unless
defined
$add
;
return
if
(
$self
->{
'Adjusted_html_h_levels'
}||0) ==
$add
;
$add
-= 1;
for
(1 .. 6) {
$Tagmap
->{
"head$_"
} =~ s/
$_
/
$_
+
$add
/e;
$Tagmap
->{
"/head$_"
} =~ s/
$_
/
$_
+
$add
/e;
}
}
sub
batch_mode_page_object_init {
my
(
$self
,
$batchconvobj
,
$module
,
$infile
,
$outfile
,
$depth
) =
@_
;
DEBUG and
print
STDERR
"Initting $self\n for $module\n"
,
" in $infile\n out $outfile\n depth $depth\n"
;
$self
->batch_mode(1);
$self
->batch_mode_current_level(
$depth
);
return
$self
;
}
sub
run {
my
$self
=
$_
[0];
return
$self
->do_middle
if
$self
->bare_output;
return
$self
->do_beginning &&
$self
->do_middle &&
$self
->do_end;
}
sub
do_beginning {
my
$self
=
$_
[0];
my
$title
;
if
(
defined
$self
->force_title) {
$title
=
$self
->force_title;
DEBUG and
print
STDERR
"Forcing title to be $title\n"
;
}
else
{
$title
=
$self
->get_short_title();
unless
(
$self
->content_seen) {
DEBUG and
print
STDERR
"No content seen in search for title.\n"
;
return
;
}
$self
->{
'Title'
} =
$title
;
if
(
defined
$title
and
$title
=~ m/\S/) {
$title
=
$self
->title_prefix . esc(
$title
) .
$self
->title_postfix;
}
else
{
$title
=
$self
->default_title;
$title
=
''
unless
defined
$title
;
DEBUG and
print
STDERR
"Title defaults to $title\n"
;
}
}
my
$after
=
$self
->html_header_after_title ||
''
;
if
(
$self
->html_css) {
my
$link
=
$self
->html_css =~ m/</
?
$self
->html_css
:
sprintf
(
qq[<link rel="stylesheet" type="text/css" title="pod_stylesheet" href="%s">\n]
,
$self
->html_css,
);
$after
=~ s{(</head>)}{
$link
\n$1}i;
}
$self
->_add_top_anchor(\
$after
);
if
(
$self
->html_javascript) {
my
$link
=
$self
->html_javascript =~ m/</
?
$self
->html_javascript
:
sprintf
(
qq[<script type="text/javascript" src="%s"></script>\n]
,
$self
->html_javascript,
);
$after
=~ s{(</head>)}{
$link
\n$1}i;
}
print
{
$self
->{
'output_fh'
}}
$self
->html_header_before_title ||
''
,
$title
,
$after
,
;
DEBUG and
print
STDERR
"Returning from do_beginning...\n"
;
return
1;
}
sub
_add_top_anchor {
my
(
$self
,
$text_r
) =
@_
;
unless
(
$$text_r
and
$$text_r
=~ m/name=[
'"]___top['
"]/) {
$$text_r
.=
$self
->top_anchor ||
''
;
}
return
;
}
sub
version_tag_comment {
my
$self
=
shift
;
return
sprintf
"<!--\n generated by %s v%s,\n using %s v%s,\n under Perl v%s at %s GMT.\n\n %s\n\n-->\n"
,
esc(
ref
(
$self
),
$self
->VERSION(),
$ISA
[0],
$ISA
[0]->VERSION(),
$],
scalar
(
gmtime
(
$ENV
{SOURCE_DATE_EPOCH} ||
time
)),
),
$self
->_modnote(),
;
}
sub
_modnote {
my
$class
=
ref
(
$_
[0]) ||
$_
[0];
return
join
"\n "
=>
grep
m/\S/,
split
"\n"
,
qq{
If you want to change this HTML document, you probably shouldn't do that
by changing it directly. Instead, see about changing the calling options
to $class, and/or subclassing $class,
then reconverting this document from the Pod source.
When in doubt, email the author of $class for advice.
See 'perldoc $class' for more info.
}
;
}
sub
do_end {
my
$self
=
$_
[0];
print
{
$self
->{
'output_fh'
}}
$self
->html_footer ||
''
;
return
1;
}
sub
do_middle {
my
$self
=
$_
[0];
return
$self
->_do_middle_main_loop
unless
$self
->
index
;
if
(
$self
->output_string ) {
my
$out
=
$self
->output_string;
my
$sneakytag
=
"\f\f\e\e\b\bIndex Here\e\e\b\b\f\f\n"
;
$$out
.=
$sneakytag
;
$self
->_do_middle_main_loop;
$sneakytag
=
quotemeta
(
$sneakytag
);
my
$index
=
$self
->index_as_html();
if
(
$$out
=~ s/
$sneakytag
/
$index
/s ) {
DEBUG and
print
STDERR
"Inserted "
,
length
(
$index
),
" bytes of index HTML into $out.\n"
;
}
else
{
DEBUG and
print
STDERR
"Odd, couldn't find where to insert the index in the output!\n"
;
}
return
1;
}
unless
(
$self
->output_fh ) {
Carp::confess(
"Parser object \$p doesn't seem to have any output object! I don't know how to deal with that."
);
}
my
$fh
=
$self
->output_fh;
my
$content
=
''
;
{
$self
->output_string( \
$content
);
$self
->_do_middle_main_loop;
$self
->abandon_output_string();
$self
->output_fh(
$fh
);
}
print
$fh
$self
->index_as_html();
print
$fh
$content
;
return
1;
}
sub
index_as_html {
my
$self
=
$_
[0];
my
$points
=
$self
->{
'PSHTML_index_points'
} || [];
@$points
> 1 or
return
qq[<div class='indexgroupEmpty'></div>\n]
;
my
(
@out
) =
qq{\n<div class='indexgroup'>}
;
my
$level
= 0;
my
(
$target_level
,
$previous_tagname
,
$tagname
,
$text
,
$anchorname
,
$indent
);
foreach
my
$p
(
@$points
, [
'head0'
,
'(end)'
]) {
(
$tagname
,
$text
) =
@$p
;
$anchorname
=
$self
->section_escape(
$text
);
if
(
$tagname
=~ m{^head(\d+)$} ) {
$target_level
= 0 + $1;
}
else
{
if
(
$previous_tagname
=~ m{^head\d+$} ) {
$target_level
=
$level
+ 1;
}
else
{
$target_level
=
$level
;
}
}
while
(
$level
>
$target_level
)
{ --
$level
;
push
@out
, (
" "
x
$level
) .
"</ul>"
; }
while
(
$level
<
$target_level
)
{ ++
$level
;
push
@out
, (
" "
x (
$level
-1))
.
"<ul class='indexList indexList$level'>"
; }
$previous_tagname
=
$tagname
;
next
unless
$level
;
$indent
=
' '
x
$level
;
push
@out
,
sprintf
"%s<li class='indexItem indexItem%s'><a href='#%s'>%s</a>"
,
$indent
,
$level
, esc(
$anchorname
), esc(
$text
)
;
}
push
@out
,
"</div>\n"
;
return
join
"\n"
,
@out
;
}
sub
_do_middle_main_loop {
my
$self
=
$_
[0];
my
$fh
=
$self
->{
'output_fh'
};
my
$tagmap
=
$self
->{
'Tagmap'
};
$self
->__adjust_html_h_levels;
my
(
$token
,
$type
,
$tagname
,
$linkto
,
$linktype
);
my
@stack
;
my
$dont_wrap
= 0;
while
(
$token
=
$self
->get_token) {
if
( (
$type
=
$token
->type) eq
'start'
) {
if
((
$tagname
=
$token
->tagname) eq
'L'
) {
$linktype
=
$token
->attr(
'type'
) ||
'insane'
;
$linkto
=
$self
->do_link(
$token
);
if
(
defined
$linkto
and
length
$linkto
) {
esc(
$linkto
);
print
$fh
qq{<a href="$linkto" class="podlink$linktype"\n>}
;
}
else
{
print
$fh
"<a>"
;
}
}
elsif
(
$tagname
eq
'item-text'
or
$tagname
=~ m/^head\d$/s) {
print
$fh
$tagmap
->{
$tagname
} ||
next
;
my
@to_unget
;
while
(1) {
push
@to_unget
,
$self
->get_token;
last
if
$to_unget
[-1]->is_end
and
$to_unget
[-1]->tagname eq
$tagname
;
}
my
$name
=
$self
->linearize_tokens(
@to_unget
);
$name
=
$self
->do_section(
$name
,
$token
)
if
defined
$name
;
print
$fh
"<a "
;
if
(
$tagname
=~ m/^head\d$/s) {
print
$fh
"class='u'"
,
$self
->
index
?
" href='#___top' title='click to go to top of document'\n"
:
"\n"
;
}
if
(
defined
$name
) {
my
$esc
= esc(
$self
->section_name_tidy(
$name
) );
print
$fh
qq[name="$esc"]
;
DEBUG and
print
STDERR
"Linearized "
,
scalar
(
@to_unget
),
" tokens as \"$name\".\n"
;
push
@{
$self
->{
'PSHTML_index_points'
} }, [
$tagname
,
$name
]
if
$ToIndex
{
$tagname
};
}
else
{
DEBUG and
print
STDERR
"Linearized "
,
scalar
(
@to_unget
),
" tokens, but it was too long, so nevermind.\n"
;
}
print
$fh
"\n>"
;
$self
->unget_token(
@to_unget
);
}
elsif
(
$tagname
eq
'Data'
) {
my
$next
=
$self
->get_token;
next
unless
defined
$next
;
unless
(
$next
->type eq
'text'
) {
$self
->unget_token(
$next
);
next
;
}
DEBUG and
print
STDERR
" raw text "
,
$next
->text,
"\n"
;
(
my
$text
=
$next
->text) =~ s/\n\z//;
print
$fh
$text
,
"\n"
;
next
;
}
else
{
if
(
$tagname
=~ m/^over-/s ) {
push
@stack
,
''
;
}
elsif
(
$tagname
=~ m/^item-/s and
@stack
and
$stack
[-1] ) {
print
$fh
$stack
[-1];
$stack
[-1] =
''
;
}
print
$fh
$tagmap
->{
$tagname
} ||
next
;
++
$dont_wrap
if
$tagname
eq
'Verbatim'
or
$tagname
eq
"VerbatimFormatted"
or
$tagname
eq
'X'
;
}
}
elsif
(
$type
eq
'end'
) {
if
( (
$tagname
=
$token
->tagname) =~ m/^over-/s ) {
if
(
my
$end
=
pop
@stack
) {
print
$fh
$end
;
}
}
elsif
(
$tagname
=~ m/^item-/s and
@stack
) {
$stack
[-1] =
$tagmap
->{
"/$tagname"
};
if
(
$tagname
eq
'item-text'
and
defined
(
my
$next
=
$self
->get_token) ) {
$self
->unget_token(
$next
);
if
(
$next
->type eq
'start'
) {
print
$fh
$tagmap
->{
"/item-text"
},
$tagmap
->{
"item-body"
};
$stack
[-1] =
$tagmap
->{
"/item-body"
};
}
}
next
;
}
print
$fh
$tagmap
->{
"/$tagname"
} ||
next
;
--
$dont_wrap
if
$tagname
eq
'Verbatim'
or
$tagname
eq
'X'
;
}
elsif
(
$type
eq
'text'
) {
esc(
$type
=
$token
->text);
$type
=~ s/([\?\!\"\'\.\,]) /$1\n/g
unless
$dont_wrap
;
print
$fh
$type
;
}
}
return
1;
}
sub
do_section {
my
(
$self
,
$name
,
$token
) =
@_
;
return
$name
;
}
sub
do_link {
my
(
$self
,
$token
) =
@_
;
my
$type
=
$token
->attr(
'type'
);
if
(!
defined
$type
) {
$self
->whine(
"Typeless L!?"
,
$token
->attr(
'start_line'
));
}
elsif
(
$type
eq
'pod'
) {
return
$self
->do_pod_link(
$token
);
}
elsif
(
$type
eq
'url'
) {
return
$self
->do_url_link(
$token
);
}
elsif
(
$type
eq
'man'
) {
return
$self
->do_man_link(
$token
);
}
else
{
$self
->whine(
"L of unknown type $type!?"
,
$token
->attr(
'start_line'
));
}
return
'FNORG'
;
}
sub
do_url_link {
return
$_
[1]->attr(
'to'
) }
sub
do_man_link {
my
(
$self
,
$link
) =
@_
;
my
$to
=
$link
->attr(
'to'
);
my
$frag
=
$link
->attr(
'section'
);
return
undef
unless
defined
$to
and
length
$to
;
$frag
=
$self
->section_escape(
$frag
)
if
defined
$frag
and
length
(
$frag
.=
''
);
DEBUG and
print
STDERR
"Resolving \"$to/$frag\"\n\n"
;
return
$self
->resolve_man_page_link(
$to
,
$frag
);
}
sub
do_pod_link {
my
(
$self
,
$link
) =
@_
;
my
$to
=
$link
->attr(
'to'
);
my
$section
=
$link
->attr(
'section'
);
return
undef
unless
(
(
defined
$to
and
length
$to
) or
(
defined
$section
and
length
$section
)
);
$section
=
$self
->section_escape(
$section
)
if
defined
$section
and
length
(
$section
.=
''
);
DEBUG and
printf
STDERR
"Resolving \"%s\" \"%s\"...\n"
,
$to
||
"(nil)"
,
$section
||
"(nil)"
;
{
my
$complete_url
=
$self
->resolve_pod_link_by_table(
$to
,
$section
);
if
(
$complete_url
) {
DEBUG > 1 and
print
STDERR
"resolve_pod_link_by_table(T,S) gives "
,
$complete_url
,
"\n (Returning that.)\n"
;
return
$complete_url
;
}
else
{
DEBUG > 4 and
print
STDERR
" resolve_pod_link_by_table(T,S)"
,
" didn't return anything interesting.\n"
;
}
}
if
(
defined
$to
and
length
$to
) {
my
$there
=
$self
->resolve_pod_link_by_table(
$to
);
if
(
defined
$there
and
length
$there
) {
DEBUG > 1
and
print
STDERR
"resolve_pod_link_by_table(T) gives $there\n"
;
}
else
{
$there
=
$self
->resolve_pod_page_link(
$to
,
$section
);
DEBUG > 1 and
print
STDERR
"resolve_pod_page_link gives "
,
$there
||
"(nil)"
,
"\n"
;
unless
(
defined
$there
and
length
$there
) {
DEBUG and
print
STDERR
"Can't resolve $to\n"
;
return
undef
;
}
}
$to
=
$there
;
}
my
$out
= (
defined
$to
and
length
$to
) ?
$to
:
''
;
$out
.=
"#"
.
$section
if
defined
$section
and
length
$section
;
unless
(
length
$out
) {
DEBUG and
printf
STDERR
"Oddly, couldn't resolve \"%s\" \"%s\"...\n"
,
$to
||
"(nil)"
,
$section
||
"(nil)"
;
return
undef
;
}
DEBUG and
print
STDERR
"Resolved to $out\n"
;
return
$out
;
}
sub
section_escape {
my
(
$self
,
$section
) =
@_
;
return
$self
->section_url_escape(
$self
->section_name_tidy(
$section
)
);
}
sub
section_name_tidy {
my
(
$self
,
$section
) =
@_
;
$section
=~ s/^\s+//;
$section
=~ s/\s+$//;
$section
=~
tr
/ /_/;
if
($] ge 5.006) {
$section
=~ s/[[:cntrl:][:^ascii:]]//g;
}
elsif
(
'A'
eq
chr
(65)) {
$section
=~
tr
/\x00-\x1F\x80-\x9F//d;
}
$section
=
$self
->unicode_escape_url(
$section
);
$section
=
'_'
unless
length
$section
;
return
$section
;
}
sub
section_url_escape {
shift
->general_url_escape(
@_
) }
sub
pagepath_url_escape {
shift
->general_url_escape(
@_
) }
sub
manpage_url_escape {
shift
->general_url_escape(
@_
) }
sub
general_url_escape {
my
(
$self
,
$string
) =
@_
;
$string
=~ s/([^\x00-\xFF])/
join
''
,
map
sprintf
(
'%%%02X'
,
$_
),
unpack
'C*'
, $1/eg;
if
($] ge 5.007_003) {
$string
=~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/
sprintf
(
'%%%02X'
,utf8::native_to_unicode(
ord
($1)))/eg;
}
else
{
$string
=~ s/([^-_\.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/
sprintf
(
'%%%02X'
,
ord
($1))/eg;
}
return
$string
;
}
sub
resolve_pod_page_link {
my
$self
=
shift
;
return
$self
->batch_mode()
?
$self
->resolve_pod_page_link_batch_mode(
@_
)
:
$self
->resolve_pod_page_link_singleton_mode(
@_
)
;
}
sub
resolve_pod_page_link_singleton_mode {
my
(
$self
,
$it
) =
@_
;
return
undef
unless
defined
$it
and
length
$it
;
my
$url
=
$self
->pagepath_url_escape(
$it
);
$url
=~ s{::$}{}s;
$url
=~ s{::}{/}g
unless
$self
->perldoc_url_prefix =~ m/\?/s;
return
undef
unless
length
$url
;
return
$self
->perldoc_url_prefix .
$url
.
$self
->perldoc_url_postfix;
}
sub
resolve_pod_page_link_batch_mode {
my
(
$self
,
$to
) =
@_
;
DEBUG > 1 and
print
STDERR
" During batch mode, resolving $to ...\n"
;
my
@path
=
grep
length
(
$_
),
split
m/::/s,
$to
, -1;
unless
(
@path
) {
DEBUG and
print
STDERR
"Very odd! Splitting $to gives (nil)!\n"
;
return
undef
;
}
$self
->batch_mode_rectify_path(\
@path
);
my
$out
=
join
(
'/'
,
map
$self
->pagepath_url_escape(
$_
),
@path
)
.
$HTML_EXTENSION
;
DEBUG > 1 and
print
STDERR
" => $out\n"
;
return
$out
;
}
sub
batch_mode_rectify_path {
my
(
$self
,
$pathbits
) =
@_
;
my
$level
=
$self
->batch_mode_current_level;
$level
--;
if
(
$level
< 1) {
unshift
@$pathbits
,
'.'
;
}
else
{
unshift
@$pathbits
, (
'..'
) x
$level
;
}
return
;
}
sub
resolve_man_page_link {
my
(
$self
,
$to
,
$frag
) =
@_
;
my
(
$page
,
$section
) =
$to
=~ /^([^(]+)(?:[(](\d+)[)])?$/;
return
undef
unless
defined
$page
and
length
$page
;
$section
||= 1;
return
$self
->man_url_prefix .
"$section/"
.
$self
->manpage_url_escape(
$page
)
.
$self
->man_url_postfix;
}
sub
resolve_pod_link_by_table {
return
unless
$_
[0]->{
'podhtml_LOT'
};
my
(
$self
,
$to
,
$section
) =
@_
;
if
(
defined
$section
) {
$to
=
''
unless
defined
$to
and
length
$to
;
return
$self
->{
'podhtml_LOT'
}{
"$to#$section"
}; # quite possibly
undef
!
}
else
{
return
$self
->{
'podhtml_LOT'
}{
$to
};
}
return
;
}
sub
linearize_tokens {
my
$self
=
shift
;
my
$out
=
''
;
my
$t
;
while
(
$t
=
shift
@_
) {
if
(!
ref
$t
or !UNIVERSAL::can(
$t
,
'is_text'
)) {
$out
.=
$t
;
}
elsif
(
$t
->is_text) {
$out
.=
$t
->text;
}
elsif
(
$t
->is_start and
$t
->tag eq
'X'
) {
my
$x_open
= 1;
while
(
$x_open
) {
next
if
( (
$t
=
shift
@_
)->is_text );
if
(
$t
->is_start and
$t
->tag eq
'X'
) { ++
$x_open
}
elsif
(
$t
->is_end and
$t
->tag eq
'X'
) { --
$x_open
}
}
}
}
return
undef
if
length
$out
>
$Linearization_Limit
;
return
$out
;
}
sub
unicode_escape_url {
my
(
$self
,
$string
) =
@_
;
$string
=~ s/([^\x00-\xFF])/
'('
.
ord
($1).
')'
/eg;
return
$string
;
}
sub
esc {
if
(
defined
wantarray
) {
if
(
wantarray
) {
@_
=
splice
@_
;
}
else
{
my
$x
=
shift
;
if
($] ge 5.007_003) {
$x
=~ s/([^-\n\t !\
}
else
{
$x
=~ s/([^-\n\t !\
}
return
$x
;
}
}
foreach
my
$x
(
@_
) {
if
(
defined
$x
) {
if
($] ge 5.007_003) {
$x
=~ s/([^-\n\t !\
}
else
{
$x
=~ s/([^-\n\t !\
}
}
}
return
@_
;
}
1;