NAME

IO::Util - Captures the output sent to a file handler

VERSION 1.1

SYNOPSIS

use IO::Util qw(capture);

# captures the selected file handler
$output_ref = capture { some_printing_code } ;

sub some_printing_code {
    print 'something'
}

# captures FILEHANDLER
$output_ref = capture { some_special_printing_code } FILEHEANDLER ;

sub some_special_printing_code {
    print FILEHANDLER 'something'
}

DESCRIPTION

This is a micro-weight module that exports just the capture function. It executes the code inside the first argument block, and captures the output it sends to the selected file handler (or to a specific file handler). It "hijacks" all the print and printf statements addressed to the captured filehandler, returning the scalar reference of the output. Sort of "print to scalar" function.

INSTALLATION

CPAN
perl -MCPAN -e 'install IO::Util'
Standard installation

From the directory where this file is located, type:

perl Makefile.PL
make
make test
make install

FUNCTIONS

capture { code } [ FILEHANDLER ]

The capture function espects a code block as the first argument and an optional FILEHANDLER as the second argument. If FILEHANDLER is omitted the selected file handler will be used by default (usually STDOUT). The function returns the reference to the captured output.

Note: This function ties the FILEHANDLER to IO::Util class and unties it after the execution of the code. If FILEHANDLER is already tied to some other class, it just re-bless the tied object to IO::Util class and re-bless again the tied object to its original class after the execution of the code, thus preserving the original FILEHANDLER configuration.

SUPPORT and FEEDBACK

If you need support or if you want just to send me some feedback or request, please use this link: http://perl.4pro.net/?IO::Util.

AUTHOR and COPYRIGHT

© 2004 by Domizio Demichelis.

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 112:

Non-ASCII character seen before =encoding in '©'. Assuming CP1252