From: Shawn M Moore Date: Sun, 28 Sep 2008 04:00:33 +0000 (+0000) Subject: reftype (which is used by openhandle but not Mouse directly) X-Git-Tag: 0.19~212 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d8aea268546acbcb18c45b2cfbb9787b31d93cd7;p=gitmo%2FMouse.git reftype (which is used by openhandle but not Mouse directly) --- diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 9fb77ae..5b34083 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -41,6 +41,34 @@ our %dependencies = ( 0; }, + 'reftype' => sub { + local($@, $SIG{__DIE__}, $SIG{__WARN__}); + my $r = shift; + my $t; + + length($t = ref($r)) or return undef; + + # This eval will fail if the reference is not blessed + eval { $r->a_sub_not_likely_to_be_here; 1 } + ? do { + $t = eval { + # we have a GLOB or an IO. Stringify a GLOB gives it's name + my $q = *$r; + $q =~ /^\*/ ? "GLOB" : "IO"; + } + or do { + # OK, if we don't have a GLOB what parts of + # a glob will it populate. + # NOTE: A glob always has a SCALAR + local *glob = $r; + defined *glob{ARRAY} && "ARRAY" + or defined *glob{HASH} && "HASH" + or defined *glob{CODE} && "CODE" + or length(ref(${$r})) ? "REF" : "SCALAR"; + } + } + : $t + }, }, 'MRO::Compat' => { 'get_linear_isa' => {