The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Stream::Util - Tools used by Test::Stream and friends.

EXPERIMENTAL CODE WARNING

This is an experimental release! Test-Stream, and all its components are still in an experimental phase. This dist has been released to cpan in order to allow testers and early adopters the chance to write experimental new tools with it, or to add experimental support for it into old tools.

PLEASE DO NOT COMPLETELY CONVERT OLD TOOLS YET. This experimental release is very likely to see a lot of code churn. API's may break at any time. Test-Stream should NOT be depended on by any toolchain level tools until the experimental phase is over.

DESCRIPTION

Collection of tools used by Test::Stream and friends.

EXPORTS

All exports are optional, you must specify subs to import. If you want to import everything use '-all'.

    use Test::Stream::Util '-all';
($success, $error) = try { ... }

Eval the codeblock, return success or failure, and the error message. This code protects $@ and $!, they will be restored by the end of the run. This code also temporarily blocks $SIG{DIE} handlers.

protect { ... }

Similar to try, except that it does not catch exceptions. The idea here is to protect $@ and $! from changes. $@ and $! will be restored to whatever they were before the run so long as it is successful. If the run fails $! will still be restored, but $@ will contain the exception being thrown.

USE_THREADS

Returns true if threads are enabled, false if they are not.

get_tid

This will return the id of the current thread when threads are enabled, otherwise it returns 0.

my $file = pkg_to_file($package)

Convert a package name to a filename.

$stash = get_stash($package)

Returns the stash reference for the given package. The stash reference can be treated like a hashref, you can get keys and values from it.

$slot = sig_to_slot($sigil)

Given a sigil such as $, @, %, &, *, this will return the GLOB slot for that sigil such as SCALAR, ARRAY, HASH, CODE, GLOB.

$sigil = slot_to_sig($slot)

Given a a glob slot such as SCALAR, ARRAY, HASH, CODE, GLOB, this will return the typical sigil for that slot such as $, @, %, &, *.

($name, $type) = parse_symbol($symbol)

When given a symbol name such as $foo or @bar this will return the symbol name, and the type name. If no sigil is present in the variable name it will assume it is a subroutine and return the CODE type. $symbol should be a string containing the name of the symbol with optional sigil.

my $cols = term_size()

Attempts to find the width in columns (characters) of the current terminal. Returns 80 as a safe bet if it cannot find it another way. This is most accurate if Term::ReadKey is installed.

SOURCE

The source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>
Kent Fredric <kentnl@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html