3 # Copyright (c) 1997-2009 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
7 # This module is normally only loaded if the XS module is not available
9 package Scalar::Util::PP;
13 use vars qw(@ISA @EXPORT $VERSION $recurse);
15 use B qw(svref_2object);
18 @EXPORT = qw(blessed reftype tainted readonly refaddr looks_like_number);
20 $VERSION = eval $VERSION;
23 return undef unless length(ref($_[0]));
24 my $b = svref_2object($_[0]);
25 return undef unless $b->isa('B::PVMG');
27 return $s->isa('B::HV') ? $s->NAME : undef;
31 return undef unless length(ref($_[0]));
34 if(defined(my $pkg = blessed($_[0]))) {
35 $addr .= bless $_[0], 'Scalar::Util::Fake';
44 no warnings 'portable';
63 return undef unless length(ref($r));
65 my $t = ref(svref_2object($r));
68 exists $tmap{$t} ? $tmap{$t}
69 : length(ref($$r)) ? 'REF'
75 local($@, $SIG{__DIE__}, $SIG{__WARN__});
78 eval { kill 0 * $_[0] };
83 return 0 if tied($_[0]) || (ref(\($_[0])) ne "SCALAR");
85 local($@, $SIG{__DIE__}, $SIG{__WARN__});
88 !eval { $_[0] = $tmp; 1 };
91 sub looks_like_number {
94 # checks from perlfaq4
95 return 0 if !defined($_);
98 return overload::Overloaded($_) ? defined(0 + $_) : 0;
100 return 1 if (/^[+-]?[0-9]+$/); # is a +/- integer
101 return 1 if (/^([+-]?)(?=[0-9]|\.[0-9])[0-9]*(\.[0-9]*)?([Ee]([+-]?[0-9]+))?$/); # a C float
102 return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i);