#! perl
no
warnings
"experimental::signatures"
;
our
@EXPORT
;
sub
parse_kv (
@lines
) {
my
@words
= shellwords(
@lines
);
my
$res
= {};
foreach
(
@words
) {
if
( /^(.*?)=(.+)/ ) {
$res
->{$1} = $2;
}
elsif
( /^
no
[-_]?(.+)/ ) {
$res
->{$1} = 0;
}
else
{
$res
->{
$_
}++;
}
}
return
$res
;
}
push
(
@EXPORT
,
'parse_kv'
);
sub
demarkup (
$t
) {
return
join
(
''
,
grep
{ ! /^\</ } splitmarkup(
$t
) );
}
push
(
@EXPORT
,
'demarkup'
);
sub
splitmarkup (
$t
) {
my
@t
=
split
(
qr;(<
/?(?:[-\w]+|span\s.*?)>);,
$t
);
return
@t
;
}
push
(
@EXPORT
,
'splitmarkup'
);
sub
maybe (
$key
,
$value
,
@rest
) {
if
(
defined
$key
and
defined
$value
) {
return
(
$key
,
$value
,
@rest
);
}
else
{
(
defined
(
$key
) ||
@rest
) ?
@rest
: ();
}
}
push
(
@EXPORT
,
"maybe"
);
sub
min {
$_
[0] <
$_
[1] ?
$_
[0] :
$_
[1] }
sub
max {
$_
[0] >
$_
[1] ?
$_
[0] :
$_
[1] }
push
(
@EXPORT
,
"min"
,
"max"
);
1;