From: Shawn M Moore Date: Sun, 28 Sep 2008 04:00:48 +0000 (+0000) Subject: openhandle X-Git-Tag: 0.19~211 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=29312fc307382e973fe3c35e79d87551fe6af40c;p=gitmo%2FMouse.git openhandle --- diff --git a/lib/Mouse/TypeRegistry.pm b/lib/Mouse/TypeRegistry.pm index 48d2610..1aef7a8 100644 --- a/lib/Mouse/TypeRegistry.pm +++ b/lib/Mouse/TypeRegistry.pm @@ -3,8 +3,7 @@ package Mouse::TypeRegistry; use strict; use warnings; -use Mouse::Util qw/blessed looks_like_number/; -use Scalar::Util qw/openhandle/; +use Mouse::Util qw/blessed looks_like_number openhandle/; no warnings 'uninitialized'; sub optimized_constraints { diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 5b34083..51aa3f9 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -69,6 +69,23 @@ our %dependencies = ( } : $t }, + 'openhandle' => sub { + my $fh = shift; + my $rt = reftype($fh) || ''; + + return defined(fileno($fh)) ? $fh : undef + if $rt eq 'IO'; + + if (reftype(\$fh) eq 'GLOB') { # handle openhandle(*DATA) + $fh = \(my $tmp=$fh); + } + elsif ($rt ne 'GLOB') { + return undef; + } + + (tied(*$fh) or defined(fileno($fh))) + ? $fh : undef; + }, }, 'MRO::Compat' => { 'get_linear_isa' => {