doc
[gitmo/Mouse.git] / lib / Mouse / Util.pm
index 5b34083..b2ab6c6 100644 (file)
@@ -6,6 +6,8 @@ use base 'Exporter';
 
 our %dependencies = (
     'Scalar::Util' => {
+
+#       VVVVV   CODE TAKEN FROM SCALAR::UTIL   VVVVV
         'blessed' => do {
             do {
                 no strict 'refs';
@@ -69,8 +71,31 @@ 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;
+        },
+        weaken => {
+            loaded => \&Scalar::Util::weaken,
+            not_loaded => sub { die "Scalar::Util required for weak reference support" },
+        },
+#       ^^^^^   CODE TAKEN FROM SCALAR::UTIL   ^^^^^
     },
     'MRO::Compat' => {
+#       VVVVV   CODE TAKEN FROM MRO::COMPAT   VVVVV
         'get_linear_isa' => {
             loaded     => \&mro::get_linear_isa,
             not_loaded => do {
@@ -95,6 +120,7 @@ our %dependencies = (
                 }
             },
         },
+#       ^^^^^   CODE TAKEN FROM MRO::COMPAT   ^^^^^
     },
 );
 
@@ -128,5 +154,35 @@ for my $module_name (keys %dependencies) {
     }
 }
 
+
 1;
 
+__END__
+
+=head1 NAME
+
+Mouse::Util - features, with or without their dependencies
+
+=head1 IMPLEMENTATIONS FOR
+
+=head2 L<MRO::Compat>
+
+=head3 get_linear_isa
+
+=head2 L<Scalar::Util>
+
+=head3 blessed
+
+=head3 looks_like_number
+
+=head3 reftype
+
+=head3 openhandle
+
+=head3 weaken
+
+C<weaken> I<must> be implemented in XS. If the user tries to use C<weaken>
+without L<Scalar::Util>, an error is thrown.
+
+=cut
+