Change 15283 by gbarr@monty on 2002/03/18 10:10:55

        Sync with Scalar-List-Utils-1.07

Affected files ...

.... //depot/perl/MANIFEST#775 edit
.... //depot/perl/ext/List/Util/ChangeLog#6 edit
.... //depot/perl/ext/List/Util/lib/List/Util.pm#9 edit
.... //depot/perl/ext/List/Util/lib/Scalar/Util.pm#7 edit
.... //depot/perl/ext/List/Util/t/openhan.t#1 add

Differences ...

==== //depot/perl/MANIFEST#775 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST.~1~   Mon Mar 18 03:15:05 2002
+++ perl/MANIFEST       Mon Mar 18 03:15:05 2002
@@ -459,6 +459,7 @@
 ext/List/Util/t/maxstr.t       List::Util
 ext/List/Util/t/min.t          List::Util
 ext/List/Util/t/minstr.t       List::Util
+ext/List/Util/t/openhan.t      Scalar::Util
 ext/List/Util/t/readonly.t     Scalar::Util
 ext/List/Util/t/reduce.t       List::Util
 ext/List/Util/t/reftype.t      Scalar::Util

==== //depot/perl/ext/List/Util/ChangeLog#6 (text) ====
Index: perl/ext/List/Util/ChangeLog
--- perl/ext/List/Util/ChangeLog.~1~    Mon Mar 18 03:15:05 2002
+++ perl/ext/List/Util/ChangeLog        Mon Mar 18 03:15:05 2002
@@ -1,3 +1,11 @@
+Change 713 on 2002/03/18 by <[EMAIL PROTECTED]> (Graham Barr)
+
+       Add Scalar::Util::openhandle()
+
+Change 647 on 2001/09/18 by <[EMAIL PROTECTED]> (Graham Barr)
+
+       Release 1.06
+
 Change 645 on 2001/09/07 by <[EMAIL PROTECTED]> (Graham Barr)
 
        Some platforms require the main executable to export symbols

==== //depot/perl/ext/List/Util/lib/List/Util.pm#9 (text) ====
Index: perl/ext/List/Util/lib/List/Util.pm
--- perl/ext/List/Util/lib/List/Util.pm.~1~     Mon Mar 18 03:15:05 2002
+++ perl/ext/List/Util/lib/List/Util.pm Mon Mar 18 03:15:05 2002
@@ -11,7 +11,7 @@
 
 our @ISA       = qw(Exporter DynaLoader);
 our @EXPORT_OK = qw(first min max minstr maxstr reduce sum shuffle);
-our $VERSION   = "1.06_00";
+our $VERSION   = "1.07_00";
 
 bootstrap List::Util $VERSION;
 

==== //depot/perl/ext/List/Util/lib/Scalar/Util.pm#7 (text) ====
Index: perl/ext/List/Util/lib/Scalar/Util.pm
--- perl/ext/List/Util/lib/Scalar/Util.pm.~1~   Mon Mar 18 03:15:05 2002
+++ perl/ext/List/Util/lib/Scalar/Util.pm       Mon Mar 18 03:15:05 2002
@@ -10,9 +10,27 @@
 require List::Util; # List::Util loads the XS
 
 our @ISA       = qw(Exporter);
-our @EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly);
+our @EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly 
+openhandle);
 our $VERSION   = $List::Util::VERSION;
 
+sub openhandle ($) {
+  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;
+}
+
 1;
 
 __END__
@@ -69,6 +87,16 @@
     weaken($ref);
     $weak = isweak($ref);               # true
 
+=item openhandle FH
+
+Returns FH if FH may be used as a filehandle and is open, or FH is a tied
+handle. Otherwise C<undef> is returned.
+
+    $fh = openhandle(*STDIN);          # \*STDIN
+    $fh = openhandle(\*STDIN);         # \*STDIN
+    $fh = openhandle(*NOTOPEN);                # undef
+    $fh = openhandle("scalar");                # undef
+    
 =item readonly SCALAR
 
 Returns true if SCALAR is readonly.

==== //depot/perl/ext/List/Util/t/openhan.t#1 (text) ====
Index: perl/ext/List/Util/t/openhan.t
--- perl/ext/List/Util/t/openhan.t.~1~  Mon Mar 18 03:15:05 2002
+++ perl/ext/List/Util/t/openhan.t      Mon Mar 18 03:15:05 2002
@@ -0,0 +1,33 @@
+#!./perl
+
+BEGIN {
+    unless (-d 'blib') {
+       chdir 't' if -d 't';
+       @INC = '../lib';
+       require Config; import Config;
+       keys %Config; # Silence warning
+       if ($Config{extensions} !~ /\bList\/Util\b/) {
+           print "1..0 # Skip: List::Util was not built\n";
+           exit 0;
+       }
+    }
+}
+
+
+use Scalar::Util qw(openhandle);
+
+print "1..4\n";
+
+print "not " unless defined &openhandle;
+print "ok 1\n";
+
+my $fh = \*STDERR;
+print "not " unless openhandle($fh) == $fh;
+print "ok 2\n";
+
+print "not " unless fileno(openhandle(*STDERR)) == fileno(STDERR);
+print "ok 3\n";
+
+print "not " if openhandle(CLOSED);
+print "ok 4\n";
+
End of Patch.

Reply via email to