#!/usr/bin/env perl
my
$man
= 0;
my
$help
= 0;
my
$verbose
= 0;
my
$outfile
=
'docker-names.yml'
;
GetOptions(
'help|?'
=> \
$help
,
'man!'
=> \
$man
,
'verbose!'
=> \
$verbose
,
'out=s'
=> \
$outfile
) or pod2usage(2);
pod2usage(1)
if
$help
;
pod2usage(
-exitval
=> 0,
-verbose
=> 2)
if
$man
;
my
$code
= path(
'names-generator.go'
)->slurp_utf8;
my
(
$left
,
$right
) =
$code
=~ m/var \s{1,} \( \s{0,1} \n
\s{0,} left \s{1,} = \s{1,} \[\.\.\.\]string \s{0,} \{ \s{0,} \n
(?<adjectives> (?: \s{0,} \
" [^"
]{1,} \" \s{0,} , \s{0,} \n )+ )
\s{0,} } \n
\s{0,} \n
\s{0,} \/\/.*\n
\s{0,} \/\/.*\n
\s{0,} right \s{1,} = \s{1,} \[\.\.\.\]string \s{0,} \{ \s{0,} \n
(?<names> (?:
(?: \s{0,} \/\/.*\n){1,}
\s{0,} \
" [^"
]{1,} \" \s{0,} , \s{0,} \n
(?: \s{0,} \n){0,1}
)+ )
\s{0,} \} \n
\s{0,} \)
/x;
my
@adjectives
;
while
(
$left
=~ m/
" (?<adjective> [^"
]{1,} ) " /gx ) {
dd($1)
if
(
$verbose
);
push
@adjectives
, $1;
}
my
@names
;
while
(
$right
=~ m/
(?<comments>
\s{0,} \/{2} \s{1} [^\n]{1,}
(?: \n \s{0,} \/{2} \s{1} [^\n]{1,} ){0,}
)
\n
\s{0,}
" (?<surname> [^"
]{1,} ) " \s{0,} ,
/gx ) {
my
$surname
= $+{surname};
dd($1)
if
(
$verbose
);
my
(
$info
,
$link
) = $1 =~ m/
(?<info>
\s{0,} \/{2} \s{1} [^\n]{1,}
(?: \n \s{0,} \/{2} \s{1} [^\n]{1,} ){0,}
)
(?<url> http [s]{0,1} :\/\/ .* ) $
/x;
if
( !
defined
$info
) {
(
$info
,
$link
) = ($1,
''
);
}
$info
=~ s/(\n*)//msx;
$info
=~ s/(\t*)//msx;
$info
=~ s/(\/*)//msx;
(
$info
) =
$info
=~ m/^ \s* (.*?) \s* $/msx;
push
@names
, {
'surname'
=>
$surname
,
'explanation'
=>
$info
,
'link'
=>
$link
, };
}
my
%serialize_me
= (
'adjectives'
=> [
map
{ {
'word'
=>
$_
} }
@adjectives
],
'names'
=> [
@names
],
);
my
$ypp
= YAML::PP->new;
$ypp
->dump_file( path(
$outfile
), \
%serialize_me
);
exit
0;