4
# Copyright (c) 1997-2009 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.
8
# This module is normally only loaded if the XS module is not available
10
package Scalar::Util::PP;
14
use vars qw(@ISA @EXPORT $VERSION $recurse);
16
use B qw(svref_2object);
19
@EXPORT = qw(blessed reftype tainted readonly refaddr looks_like_number);
21
$VERSION = eval $VERSION;
24
return undef unless length(ref($_[0]));
25
my $b = svref_2object($_[0]);
26
return undef unless $b->isa('B::PVMG');
28
return $s->isa('B::HV') ? $s->NAME : undef;
32
return undef unless length(ref($_[0]));
35
if(defined(my $pkg = blessed($_[0]))) {
36
$addr .= bless $_[0], 'Scalar::Util::Fake';
65
return undef unless length(ref($r));
67
my $t = ref(svref_2object($r));
70
exists $tmap{$t} ? $tmap{$t}
71
: length(ref($$r)) ? 'REF'
77
local($@, $SIG{__DIE__}, $SIG{__WARN__});
80
eval { kill 0 * $_[0] };
85
return 0 if tied($_[0]) || (ref(\($_[0])) ne "SCALAR");
87
local($@, $SIG{__DIE__}, $SIG{__WARN__});
90
!eval { $_[0] = $tmp; 1 };
93
sub looks_like_number {
96
# checks from perlfaq4
97
return 0 if !defined($_);
100
return overload::Overloaded($_) ? defined(0 + $_) : 0;
102
return 1 if (/^[+-]?\d+$/); # is a +/- integer
103
return 1 if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); # a C float
104
return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i);