From: Shawn M Moore Date: Sun, 28 Sep 2008 03:46:22 +0000 (+0000) Subject: looks_like_number X-Git-Tag: 0.19~213 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=58fe9fb7641a3bb817b773339bc1b81a5a373e62;p=gitmo%2FMouse.git looks_like_number --- diff --git a/lib/Mouse/TypeRegistry.pm b/lib/Mouse/TypeRegistry.pm index a8992c2..48d2610 100644 --- a/lib/Mouse/TypeRegistry.pm +++ b/lib/Mouse/TypeRegistry.pm @@ -3,8 +3,8 @@ package Mouse::TypeRegistry; use strict; use warnings; -use Mouse::Util 'blessed'; -use Scalar::Util qw/looks_like_number openhandle/; +use Mouse::Util qw/blessed looks_like_number/; +use Scalar::Util qw/openhandle/; no warnings 'uninitialized'; sub optimized_constraints { diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index c8b3c67..9fb77ae 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -30,6 +30,17 @@ our %dependencies = ( : undef; }, }, + 'looks_like_number' => sub { + local $_ = shift; + + # checks from perlfaq4 + return 0 if !defined($_) or ref($_); + return 1 if (/^[+-]?\d+$/); # is a +/- integer + return 1 if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/); # a C float + return 1 if ($] >= 5.008 and /^(Inf(inity)?|NaN)$/i) or ($] >= 5.006001 and /^Inf$/i); + + 0; + }, }, 'MRO::Compat' => { 'get_linear_isa' => {