Test2::Plugin::OpenFixPerlIO - Override CORE::GLOBAL::open() to fix perlio via cloning.
Normally you cannot clone an IO handle that has a PerlIO::via layer applied to it, it will crash. This plugin overrides CORE::GLOBAL::open() so that it handles it better (by not trying to copy the 'via' layer).
CORE::GLOBAL::open()
use Test2::Plugin::OpenFixPerlIO; binmode(STDOUT, ':via(Some::Class)'); # This will crash without the plugin. open(my $STDOUT_CLONE, '>&', \*STDOUT);
Obviosuly this will be a problem if anything else overrides CORE::GLOBAL::open.
CORE::GLOBAL::open
Normally this is allowed:
open(CLONE, '>&', STDOUT);
This will be a syntax error with this plugin. The limitations if perl's prototypes mean we cannot make the third argument accept a bareword without breaking the 4+ arg syntax.
The prototype we use: sub (*;$@) { ... }. We could also use sub (*;$*@) { ... } which would allow the third argument to be a bareword, but that breaks things if the final arguments are provided as a list or array: open(my $fh, '>', qw/echo hi/), which would become open(my $fh, '>', 'hi') because of how a list is flattened by the '*' in the prototype.
sub (*;$@) { ... }
sub (*;$*@) { ... }
open(my $fh, '>', qw/echo hi/)
open(my $fh, '>', 'hi')
The source code repository for Test2-Plugin-IOSync can be found at http://github.com/Test-More/Test2-Plugin-IOSync/.
Copyright 2017 Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
To install Test2::Plugin::IOSync, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test2::Plugin::IOSync
CPAN shell
perl -MCPAN -e shell install Test2::Plugin::IOSync
For more information on module installation, please visit the detailed CPAN module installation guide.