From 97c25a0ad1eaa253f5c81ee75612ef9b71ce8646 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 23 Oct 2023 10:39:54 +1100 Subject: [PATCH] dist/IO: move binmode from IO::File to IO::Handle since you can binmode() any handle. Fixes #17457 which is most of this change, I only added tests, such as they are. --- MANIFEST | 1 + dist/IO/lib/IO/File.pm | 21 --------------------- dist/IO/lib/IO/Handle.pm | 21 +++++++++++++++++++++ dist/IO/t/io_handle.t | 12 ++++++++++++ 4 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 dist/IO/t/io_handle.t diff --git a/MANIFEST b/MANIFEST index 86e84f4a1dbd..7ce34979138a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4283,6 +4283,7 @@ dist/IO/t/io_dup.t See if dup()-related methods from IO work dist/IO/t/io_file.t See if binmode()-related methods on IO::File work dist/IO/t/io_file_export.t Test IO::File exports dist/IO/t/io_getline.t Test getline and getlines +dist/IO/t/io_handle.t Test non-XS IO::Handle methods available dist/IO/t/io_leak.t See if IO leaks SVs (only run in core) dist/IO/t/io_linenum.t See if I/O line numbers are tracked correctly dist/IO/t/io_multihomed.t See if INET sockets work with multi-homed hosts diff --git a/dist/IO/lib/IO/File.pm b/dist/IO/lib/IO/File.pm index 537b0f7fb436..b7219fbe82d6 100644 --- a/dist/IO/lib/IO/File.pm +++ b/dist/IO/lib/IO/File.pm @@ -93,14 +93,6 @@ it passes all the three arguments to the three-argument C operator. For convenience, C exports the O_XXX constants from the Fcntl module, if this module is available. -=item binmode( [LAYER] ) - -C sets C on the underlying C object, as documented -in C. - -C accepts one optional parameter, which is the layer to be -passed on to the C call. - =back =head1 NOTE @@ -186,17 +178,4 @@ sub open { open($fh, $file); } -################################################ -## Binmode -## - -sub binmode { - ( @_ == 1 or @_ == 2 ) or croak 'usage $fh->binmode([LAYER])'; - - my($fh, $layer) = @_; - - return binmode $$fh unless $layer; - return binmode $$fh, $layer; -} - 1; diff --git a/dist/IO/lib/IO/Handle.pm b/dist/IO/lib/IO/Handle.pm index e4fc02de7bcd..95370acffee3 100644 --- a/dist/IO/lib/IO/Handle.pm +++ b/dist/IO/lib/IO/Handle.pm @@ -191,6 +191,14 @@ current setting if C is not given. If an error occurs C will return undef and C<$!> will be set. +=item binmode( [LAYER] ) + +C sets C on the underlying C object, as documented +in C. + +C accepts one optional parameter, which is the layer to be +passed on to the C call. + =back @@ -628,4 +636,17 @@ sub printflush { } } +################################################ +## Binmode +## + +sub binmode { + ( @_ == 1 or @_ == 2 ) or croak 'usage $fh->binmode([LAYER])'; + + my($fh, $layer) = @_; + + return binmode $$fh unless $layer; + return binmode $$fh, $layer; +} + 1; diff --git a/dist/IO/t/io_handle.t b/dist/IO/t/io_handle.t new file mode 100644 index 000000000000..9efd244ce210 --- /dev/null +++ b/dist/IO/t/io_handle.t @@ -0,0 +1,12 @@ +#!./perl -w + +use strict; +require($ENV{PERL_CORE} ? "../../t/test.pl" : "./t/test.pl"); + +plan(tests => 2); + +use_ok("IO::Handle"); +my $io = IO::Handle->new; + +can_ok($io, qw(fdopen close opened fileno getc eof print printf say truncate read), + qw(sysread write syswrite stat autoflush binmode fcntl ioctl));