Rand Stats

silently

zef:lizmat

Actions Status

NAME

silently - prevent any output from a block

SYNOPSIS

use silently;

DESCRIPTION

silently is module that exports a single sub called silently that takes a block to execute. Inside that block, all textual output to $*OUT and $*ERR is prevented from actually being sent to STDOUT and STDERR.

Note that if you're only interested in surpressing output from warnings, you should use the quietly statement prefix.

SUBROUTINES

silently

silently { say "hello world" }  # no output

my $captured = silently { note "tis wrong" }
if $captured.err -> $error {
    say "something went wrong: $error";
}

The "silently" subroutine takes a block as a parameter, and runs that block catching all output to $*OUT and $*ERR.

If the output is actually needed for inspection: the subroutine returns an object that provides two methods: out and err, giving the captured output to $*OUT and $*ERR respectively.

AUTHOR

Elizabeth Mattijsen liz@raku.rocks

Source can be located at: https://github.com/lizmat/silently . Comments and Pull Requests are welcome.

If you like this module, or what I’m doing more generally, committing to a small sponsorship would mean a great deal to me!

COPYRIGHT AND LICENSE

Copyright 2020, 2021, 2022 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.