1#line 1
2# Scalar::Util.pm
3#
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.
7
8package Scalar::Util;
9
10use strict;
11use vars qw(@ISA @EXPORT_OK $VERSION @EXPORT_FAIL);
12require Exporter;
13require List::Util; # List::Util loads the XS
14
15@ISA       = qw(Exporter);
16@EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly openhandle refaddr isvstring looks_like_number set_prototype);
17$VERSION    = "1.21";
18$VERSION   = eval $VERSION;
19
20unless (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);
25}
26
27sub export_fail {
28  if (grep { /dualvar/ } @EXPORT_FAIL) { # no XS loaded
29    my $pat = join("|", @EXPORT_FAIL);
30    if (my ($err) = grep { /^($pat)$/ } @_ ) {
31      require Carp;
32      Carp::croak("$err is only available with the XS version of Scalar::Util");
33    }
34  }
35
36  if (grep { /^(weaken|isweak)$/ } @_ ) {
37    require Carp;
38    Carp::croak("Weak references are not implemented in the version of perl");
39  }
40
41  if (grep { /^(isvstring)$/ } @_ ) {
42    require Carp;
43    Carp::croak("Vstrings are not implemented in the version of perl");
44  }
45
46  @_;
47}
48
49sub openhandle ($) {
50  my $fh = shift;
51  my $rt = reftype($fh) || '';
52
53  return defined(fileno($fh)) ? $fh : undef
54    if $rt eq 'IO';
55
56  if (reftype(\$fh) eq 'GLOB') { # handle  openhandle(*DATA)
57    $fh = \(my $tmp=$fh);
58  }
59  elsif ($rt ne 'GLOB') {
60    return undef;
61  }
62
63  (tied(*$fh) or defined(fileno($fh)))
64    ? $fh : undef;
65}
66
671;
68
69__END__
70
71#line 283
72