NAME

IO::ReStoreFH - store/restore file handles

VERSION

version 0.13

SYNOPSIS

    use IO::ReStoreFH;

    {
       my $fhstore = IO::ReStoreFH->new( *STDOUT );

       open( STDOUT, '>', 'file' );
    } # STDOUT will be restored when $fhstore is destroyed

    # or, one at-a-time
    {
       my $fhstore = IO::ReStoreFH->new;
       $store->store( *STDOUT );
       $store->store( $myfh );

       open( STDOUT, '>', 'file' );
       open( $myfh, '>', 'another file' );
    } # STDOUT and $myfh will be restored when $fhstore is destroyed

DESCRIPTION

Redirecting and restoring I/O streams is straightforward but a chore, and can lead to strangely silent errors if you forget to restore STDOUT or STDERR.

IO::ReStoreFH helps keep track of the present state of filehandles and low-level file descriptors and restores them either explicitly or when the IO::ReStoreFH object goes out of scope.

It uses the standard Perl filehandle duplication methods (via open) for filehandles, and uses POSIX::dup and POSIX::dup2 for file descriptors.

File handles and descriptors are restored in the reverse order that they are stored.

INTERNALS

INTERFACE

DIAGNOSTICS

SUPPORT

Bugs

Please report any bugs or feature requests to bug-io-restorefh@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=IO-ReStoreFH

Source

Source is available at

https://codeberg.org/djerius/p5-IO-ReStoreFH

and may be cloned from

https://codeberg.org/djerius/p5-IO-ReStoreFH.git

AUTHOR

Diab Jerius djerius@cfa.harvard.edu

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Smithsonian Astrophysical Observatory.

This is free software, licensed under:

The GNU General Public License, Version 3, June 2007