use
vars
qw(@ISA @EXPORT_OK $VERSION @EXPORT_FAIL)
;
@ISA
=
qw(Exporter)
;
@EXPORT_OK
=
qw(blessed dualvar reftype weaken isweak tainted readonly openhandle refaddr isvstring looks_like_number set_prototype)
;
$VERSION
=
"1.21"
;
$VERSION
=
eval
$VERSION
;
unless
(
defined
&dualvar
) {
Scalar::Util::PP->
import
;
push
@EXPORT_FAIL
,
qw(weaken isweak dualvar isvstring set_prototype)
;
}
sub
export_fail {
if
(
grep
{ /dualvar/ }
@EXPORT_FAIL
) {
my
$pat
=
join
(
"|"
,
@EXPORT_FAIL
);
if
(
my
(
$err
) =
grep
{ /^(
$pat
)$/ }
@_
) {
Carp::croak(
"$err is only available with the XS version of Scalar::Util"
);
}
}
if
(
grep
{ /^(weaken|isweak)$/ }
@_
) {
Carp::croak(
"Weak references are not implemented in the version of perl"
);
}
if
(
grep
{ /^(isvstring)$/ }
@_
) {
Carp::croak(
"Vstrings are not implemented in the version of perl"
);
}
@_
;
}
sub
openhandle ($) {
my
$fh
=
shift
;
my
$rt
= reftype(
$fh
) ||
''
;
return
defined
(
fileno
(
$fh
)) ?
$fh
:
undef
if
$rt
eq
'IO'
;
if
(reftype(\
$fh
) eq
'GLOB'
) {
$fh
= \(
my
$tmp
=
$fh
);
}
elsif
(
$rt
ne
'GLOB'
) {
return
undef
;
}
(
tied
(
*$fh
) or
defined
(
fileno
(
$fh
)))
?
$fh
:
undef
;
}
1;