NAME
IO::Capture::Stderr - Capture all output sent to STDERR
SYNOPSYS
use IO::Capture::Stderr;
$capture = IO::Capture::Stderr->new();
$capture->start(); # STDERR Output captured
print STDERR "Test Line One\n";
print STDERR "Test Line Two\n";
print STDERR "Test Line Three\n";
$capture->stop(); # STDERR output sent to wherever it was before 'start'
# In 'scalar context' returns next line
$line = $capture->read;
print "$line"; # prints "Test Line One"
$line = $capture->read;
print "$line"; # prints "Test Line Two"
# move line pointer to line 1
$capture->line_pointer(1);
$line = $capture->read;
print "$line"; # prints "Test Line One"
# Find out current line number
$current_line_position = $capture->line_pointer;
# In 'List Context' return an array(list)
@all_lines = $capture->read;
DESCRIPTION
The module IO::Capture::Stderr, is derived from the abstract class IO::Capture. See IO::Capture. The purpose of the module (as the name suggests) is to capture any output sent to STDOUT. After the capture is stopped, the STDOUT filehandle will be reset to the previous location. E.g., If previously redirected to a file, when IO::Capture->stop is called, output will start going into that file again.
METHODS
new
Creates a new capture object.
An object can be reused as needed, so will only need to do one of these.
Be aware, any data previously captured will be discarded if a new capture session is started.
start
Start capturing data into the
IO::CaptureObject.Can not be called on an object that is already capturing.
Can not be called while STDERR tied to an object.
undefwill be returned on an error.
stop
Stop capturing data and point STDERR back to it's previous output location I.e., untie STDERR
read
In Scalar Context
Lines are read from the buffer at the position of the
line_pointer, and the pointer is incremented by one.$next_line = $capture->read;
In List Context
The array is returned. The
line_pointeris not affected.@buffer = $capture->read;
Data lines are returned exactly as they were captured. You may want to use
chompon them if you don't want the end of line character(s)while (my $line = $capture->read) { chomp $line; $cat_line = join '', $cat_line, $line; }
line_pointer
Reads or sets the
line_pointer.my $current_line = $capture->line_pointer; $capture->line_pointer(1);
SUB-CLASSING
Adding Features
If you would like to sub-class this module to add a feature (method) or two, here is a couple of easy steps. Also see IO::Capture::Overview.
Give your package a name
package MyPackage;Use this
IO::Capture::Stderras your base class like this:package MyPackage; use base qw/IO::Capture::Stderr/;Add your new method like this
package MyPackage; use base qw/IO::Capture::Stderr/; sub grep { my $self = shift; for $line ( }
See Also
AUTHORS
Mark Reynolds reynolds@sgi.com
Jon Morgan jmorgan@sgi.com
COPYRIGHT
Copyright (c) 2003, Mark Reynolds. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.