~ubuntu-branches/ubuntu/trusty/liburi-namespacemap-perl/trusty

« back to all changes in this revision

Viewing changes to inc/Scalar/Util.pm

  • Committer: Package Import Robot
  • Author(s): gregor herrmann
  • Date: 2013-01-22 20:40:25 UTC
  • Revision ID: package-import@ubuntu.com-20130122204025-ne97x0q6a562tz38
Tags: upstream-0.06
ImportĀ upstreamĀ versionĀ 0.06

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
8
package Scalar::Util;
 
9
 
 
10
use strict;
 
11
use vars qw(@ISA @EXPORT_OK $VERSION @EXPORT_FAIL);
 
12
require Exporter;
 
13
require 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.23";
 
18
$VERSION   = eval $VERSION;
 
19
 
 
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);
 
25
}
 
26
 
 
27
sub 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
 
 
49
sub 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
 
 
67
1;
 
68
 
 
69
__END__
 
70