The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test2::Plugin::OpenFixPerlIO - Override CORE::GLOBAL::open() to fix perlio via cloning.

DESCRIPTION

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).

SYNOPSIS

    use Test2::Plugin::OpenFixPerlIO;

    binmode(STDOUT, ':via(Some::Class)');

    # This will crash without the plugin.
    open(my $STDOUT_CLONE, '>&', \*STDOUT);

CAVEATS

CORE::GLOBAL::open override

Obviosuly this will be a problem if anything else overrides CORE::GLOBAL::open.

Cannot use a bareword as the third argument

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.

SOURCE

The source code repository for Test2-Plugin-IOSync can be found at http://github.com/Test-More/Test2-Plugin-IOSync/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

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/