our
@EXPORT_OK
=
qw(
RGB
canonical_alignment
canonical_pattern
canonical_datetime
convert_cygwin_path
_defined_or
)
;
sub
_defined_or {
my
(
$target
,
$alternative
) =
@_
;
return
defined
$target
?
$target
:
$alternative
;
}
sub
RGB {
my
@color
;
if
(
@_
== 1 && !
ref
$_
[0] ) {
my
$str
=
shift
;
$str
=~ s/^RGB//i;
$str
=~
tr
/()//d;
@color
= _check_colors(
split
/[\s,]+/,
$str
);
}
elsif
(
@_
== 1 &&
ref
$_
[0] eq
'ARRAY'
) {
@color
= _check_colors( @{
$_
[0] } );
}
elsif
(
@_
== 3 ) {
@color
= _check_colors(
@_
);
}
croak
"wrong color specification"
unless
@color
== 3;
return
$color
[2] * 65536 +
$color
[1] * 256 +
$color
[0];
}
sub
_check_colors {
my
@colors
=
@_
;
return
map
{
$_
= 0
if
$_
< 0;
$_
= 255
if
$_
> 255;
$_
}
grep
{
defined
$_
&& /^\d+$/ }
@colors
;
}
sub
canonical_alignment {
my
$align
=
shift
;
$align
=~ s/^(?:pp)?align(?:ment)?//gi;
$align
=
'ppAlign'
. (
ucfirst
lc
$align
);
$align
=
'ppAlignCenter'
if
$align
eq
'ppAlignCentre'
;
$align
=
'ppAlignmentMixed'
if
$align
eq
'ppAlignMixed'
;
$align
;
}
sub
canonical_pattern {
my
$pattern
=
shift
;
$pattern
=~ s/^(?:mso)?Pattern//gi;
$pattern
=~ s/_([a-z])/\U$1\E/g;
$pattern
=~ s/(^|[0-9])([a-z])/$1\U$2\E/g;
$pattern
=
"msoPattern$pattern"
;
$pattern
;
}
sub
canonical_datetime {
my
$pattern
=
shift
;
$pattern
=~ s/^(?:pp)?DateTime//gi;
$pattern
=
"ppDateTime$pattern"
;
$pattern
;
}
sub
convert_cygwin_path {
my
$path
=
shift
;
return
$path
unless
$^O eq
'cygwin'
;
return
Cygwin::posix_to_win_path(
$path
,
'absolute'
)
if
$] >= 5.010;
return
Filesys::CygwinPaths::fullwin32path(
$path
);
}
1;