#!/usr/bin/env perl
my
$file
=
shift
|| quit
"no file specified"
;
-f
$file
|| quit
"$file does not exist or is not a file"
;
eval
'use Pod::Markdown; 1'
|| quit
"no Pod::Markdown"
;
my
$parser
= Local::Pod::Markdown->new (
markdown_fragment_format
=>
sub
{
s/[^\w\-\s]//gi;
s/\s/-/g;
lc
;
});
open
my
$outfh
,
">"
,
"README.md"
||
die
"can't open README.md for writing: $!"
;
$parser
->output_fh (
$outfh
);
$parser
->parse_file (
$file
);
print
"README.md generated."
, $/;
sub
quit
{
print
STDERR
"skipping $0: "
,
shift
, $/;
exit
0
}
BEGIN {
eval
'use parent "Pod::Markdown"'
;
}
sub
end_Verbatim
{
my
(
$self
) =
@_
;
my
$text
=
$self
->_pop_stack_text;
my
$indent
=
' '
x 4;
foreach
my
$line
(
split
/\n/,
$text
)
{
next
unless
$line
=~ /^(\s+)/;
$indent
= $1
if
length
($1) <
length
(
$indent
);
}
$text
=~ s/^
$indent
//mg;
$self
->_private->{no_escape} = 0;
$self
->_save_block (
join
''
,
'```perl'
, $/,
$text
, $/,
'```'
);
}
sub
_end_head
{
my
(
$self
,
$num
) =
@_
;
my
$h
=
'#'
x
$num
;
my
$text
=
$self
->_pop_stack_text;
$self
->_private->{search_header} =
$text
=~ /NAME/ ?
'Title'
:
$text
=~ /AUTHOR/ ?
'Author'
:
undef
;
$text
=
ucfirst
lc
$text
if
lc
$text
ne
$text
and
$text
ne
'AUTOLOAD'
;
$text
=~ s/([$@%][^\s]+)/
uc
$1/e;
$self
->_save_block (
join
' '
,
$h
,
$text
);
}
1;