IO-NestedCapture
view release on metacpan or search on metacpan
lib/IO/NestedCapture.pm view on Meta::CPAN
This will run the subroutine foo (with no arguments) and capture the streams it reads/writes. Also, each of the capture subroutines return the return value of the block or rethrow the exceptions raised in the block after stopping the capture.
=over
=item capture_in { };
This subroutine captures C<STDIN> for the duration of the given block.
=cut
sub capture_in(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture input and then turn off capture, even on error
$self->start(CAPTURE_STDIN);
my $result = eval {
$code->();
};
my $ERROR = $@;
$self->stop(CAPTURE_STDIN);
lib/IO/NestedCapture.pm view on Meta::CPAN
die $ERROR if $ERROR;
return $result;
}
=item capture_out { };
This subroutine captures C<STDOUT> for the duration of the given block.
=cut
sub capture_out(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture output and then turn off capture, even on error
$self->start(CAPTURE_STDOUT);
my $result = eval {
$code->();
};
my $ERROR = $@;
$self->stop(CAPTURE_STDOUT);
lib/IO/NestedCapture.pm view on Meta::CPAN
die $ERROR if $ERROR;
return $result;
}
=item capture_err { };
This subroutine captures C<STDERR> for the duration of the given block.
=cut
sub capture_err(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture error output and then turn off capture, even on error
$self->start(CAPTURE_STDERR);
my $result = eval {
$code->();
};
my $ERROR = $@;
$self->stop(CAPTURE_STDERR);
lib/IO/NestedCapture.pm view on Meta::CPAN
die $ERROR if $ERROR;
return $result;
}
=item capture_in_out { };
This subroutine captures C<STDIN> and C<STDOUT> for the duration of the given block.
=cut
sub capture_in_out(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture input and output and then turn off capture, even on error
$self->start(CAPTURE_IN_OUT);
my $result = eval {
$code->();
};
my $ERROR = $@;
$self->stop(CAPTURE_IN_OUT);
lib/IO/NestedCapture.pm view on Meta::CPAN
die $ERROR if $ERROR;
return $result;
}
=item capture_in_err { };
This subroutine captures C<STDIN> and C<STDERR> for the duration of the given block.
=cut
sub capture_in_err(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture input and error output and then turn off capture, even on error
$self->start(CAPTURE_IN_ERR);
my $result = eval {
$code->();
};
my $ERROR = $@;
$self->stop(CAPTURE_IN_ERR);
lib/IO/NestedCapture.pm view on Meta::CPAN
die $ERROR if $ERROR;
return $result;
}
=item capture_out_err { };
This subroutine captures C<STDOUT> and C<STDERR> for the duration of the given block.
=cut
sub capture_out_err(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture output and error output and then turn off capture, even on error
$self->start(CAPTURE_OUT_ERR);
my $result = eval {
$code->();
};
my $ERROR = $@;
$self->stop(CAPTURE_OUT_ERR);
lib/IO/NestedCapture.pm view on Meta::CPAN
die $ERROR if $ERROR;
return $result;
}
=item capture_all { };
This subroutine captures C<STDIN>, C<STDOUT>, and C<STDERR> for the duration of the given block.
=cut
sub capture_all(&) {
my $self = IO::NestedCapture->instance;
my $code = shift;
# capture input, output and error output and then turn off capture, even on
# error
$self->start(CAPTURE_ALL);
my $result = eval {
$code->();
};
my $ERROR = $@;
( run in 0.231 second using v1.01-cache-2.11-cpan-49f99fa48dc )