Skip to content

Commit

Permalink
dist/IO: move binmode from IO::File to IO::Handle
Browse files Browse the repository at this point in the history
since you can binmode() any handle.

Fixes Perl#17457 which is most of this change, I only added tests, such
as they are.
  • Loading branch information
tonycoz committed Dec 6, 2023
1 parent 49e6c78 commit 97c25a0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions dist/IO/lib/IO/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ it passes all the three arguments to the three-argument C<open> operator.
For convenience, C<IO::File> exports the O_XXX constants from the
Fcntl module, if this module is available.
=item binmode( [LAYER] )
C<binmode> sets C<binmode> on the underlying C<IO> object, as documented
in C<perldoc -f binmode>.
C<binmode> accepts one optional parameter, which is the layer to be
passed on to the C<binmode> call.
=back
=head1 NOTE
Expand Down Expand Up @@ -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;
21 changes: 21 additions & 0 deletions dist/IO/lib/IO/Handle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ current setting if C<BOOL> is not given.
If an error occurs C<blocking> will return undef and C<$!> will be set.
=item binmode( [LAYER] )
C<binmode> sets C<binmode> on the underlying C<IO> object, as documented
in C<perldoc -f binmode>.
C<binmode> accepts one optional parameter, which is the layer to be
passed on to the C<binmode> call.
=back
Expand Down Expand Up @@ -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;
12 changes: 12 additions & 0 deletions dist/IO/t/io_handle.t
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit 97c25a0

Please sign in to comment.