4
# Copyright (c) 1997-2007 Graham Barr <gbarr@pobox.com>. All rights reserved.
5
# This program is free software; you can redistribute it and/or
6
# modify it under the same terms as Perl itself.
11
use vars qw(@ISA @EXPORT_OK $VERSION @EXPORT_FAIL);
13
require List::Util; # List::Util loads the XS
16
@EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly openhandle refaddr isvstring looks_like_number set_prototype);
18
$VERSION = eval $VERSION;
20
unless (defined &dualvar) {
21
# Load Pure Perl version if XS not loaded
22
require Scalar::Util::PP;
23
Scalar::Util::PP->import;
24
push @EXPORT_FAIL, qw(weaken isweak dualvar isvstring set_prototype);
28
if (grep { /dualvar/ } @EXPORT_FAIL) { # no XS loaded
29
my $pat = join("|", @EXPORT_FAIL);
30
if (my ($err) = grep { /^($pat)$/ } @_ ) {
32
Carp::croak("$err is only available with the XS version of Scalar::Util");
36
if (grep { /^(weaken|isweak)$/ } @_ ) {
38
Carp::croak("Weak references are not implemented in the version of perl");
41
if (grep { /^(isvstring)$/ } @_ ) {
43
Carp::croak("Vstrings are not implemented in the version of perl");
51
my $rt = reftype($fh) || '';
53
return defined(fileno($fh)) ? $fh : undef
56
if (reftype(\$fh) eq 'GLOB') { # handle openhandle(*DATA)
59
elsif ($rt ne 'GLOB') {
63
(tied(*$fh) or defined(fileno($fh)))