Skip Menu |

This queue is for tickets about the encoding-stdio CPAN distribution.

Report information
The Basics
Id: 109420
Status: open
Priority: 0/
Queue: encoding-stdio

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.02
Fixed in: (no value)



Subject: Use of the encoding pragma is deprecated
Tests fail with perl 5.22 and later, see http://matrix.cpantesters.org/?dist=encoding-stdio%200.02
On 2015-11-22 13:18:40, SREZIC wrote: Show quoted text
> Tests fail with perl 5.22 and later, see > http://matrix.cpantesters.org/?dist=encoding-stdio%200.02
With perl 5.25.x, the error message is different: PERL_DL_NONLAZY=1 "/bbbike/perl-5.25.4/bin/perl5.25.4" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t The encoding pragma is no longer supported at t/encoding-stdio-notsource.t line 2. BEGIN failed--compilation aborted at t/encoding-stdio-notsource.t line 2. t/encoding-stdio-notsource.t .. Dubious, test returned 255 (wstat 65280, 0xff00) No subtests run The encoding pragma is no longer supported at t/encoding-stdio.t line 12. BEGIN failed--compilation aborted at t/encoding-stdio.t line 12.
On Wed Sep 07 16:42:15 2016, SREZIC wrote: Show quoted text
> On 2015-11-22 13:18:40, SREZIC wrote:
> > Tests fail with perl 5.22 and later, see > > http://matrix.cpantesters.org/?dist=encoding-stdio%200.02
> > With perl 5.25.x, the error message is different: > > PERL_DL_NONLAZY=1 "/bbbike/perl-5.25.4/bin/perl5.25.4" "- > MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef > *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" > t/*.t > The encoding pragma is no longer supported at t/encoding-stdio- > notsource.t line 2. > BEGIN failed--compilation aborted at t/encoding-stdio-notsource.t line > 2. > t/encoding-stdio-notsource.t .. > Dubious, test returned 255 (wstat 65280, 0xff00) > No subtests run > The encoding pragma is no longer supported at t/encoding-stdio.t line > 12. > BEGIN failed--compilation aborted at t/encoding-stdio.t line 12.
I don’t really understand why this module needed to be written to begin with. It provides the same functionality as the open pragma, but in a very hackish way (including ignoring any Filter arguments explicitly passed, instead of rejecting them). The attached patch gets it passing tests (but now Filter will die) in a hackish-but-slightly-less-hackish way, but I think it would be better to point users to the open pragma instead. I am not offering to rewrite the documentation, but I have some comments on it: Show quoted text
> The C<encoding> pragma assumes that the development environment and the > environment in which the program will run, use the same character encoding. > Typically, they will be different, but unfortunately, it's too late to change > C<encoding> now.
We can deprecate encoding. :-) Show quoted text
> We can add new modules, though.
But open.pm already existed. Show quoted text
> C<encoding::stdio> only installs the PerlIO C<:encoding> layers on STDOUT and > STDIN, without installing a source filter. > > See C<encoding::source> by Rafael Garcia-Suarez for handling source encoding > without touching stdio encodings.
But encoding::source does not handle source encoding per se; rather, it changes the way string are upgraded, breaking assumptions that most code makes (that if ord($a) == ord($b) and both are of length 1, then $a eq $b; this was the main reason encoding got deprecated). For something that deal *just* with source encoding, see Filter::Encoding, which was written to replace that functionality of encoding.pm. Show quoted text
> See L<encoding> for usage information.
Or, better yet, just use L<open>.
Subject: open_N0omX9Ih.txt
diff -rup encoding-stdio-0.02-0-orig/lib/encoding/stdio.pm encoding-stdio-0.02-0/lib/encoding/stdio.pm --- encoding-stdio-0.02-0-orig/lib/encoding/stdio.pm 2007-06-20 04:08:23.000000000 -0700 +++ encoding-stdio-0.02-0/lib/encoding/stdio.pm 2016-09-11 18:52:37.000000000 -0700 @@ -1,34 +1,21 @@ package encoding::stdio; use strict; -require encoding; our $VERSION = '0.02'; -our @ISA = ('encoding'); +require 'open.pm'; sub DEBUG () { 0 } +sub _args { + shift; + ':std', map /^:/ ? $_ : ":encoding($_)", @_ +} + sub import { - my $class = shift; - my ($name, %arg) = @_; - local ${^ENCODING}; - if ($arg{Filter}) { - local $INC{"Filter/Util/Call.pm"} = "dummy"; - local *Filter::Util::Call::import = sub { - DEBUG && warn "F'U'C->i faked"; - }; - local *encoding::filter_add = sub { - DEBUG && warn "filter_add faked"; - }; - $class->SUPER::import(@_); - } else { - $class->SUPER::import(@_); - } + 'open'->import(&_args); } sub unimport { - my $class = shift; - local $INC{"Filter/Util/Call.pm"} = 0; # pretend it's not there - local ${^ENCODING}; - $class->SUPER::unimport(@_); + 'open'->unimport(&_args); } 1;