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

NAME

TB2::CanLoad - load modules without effecting global variables

SYNOPSIS

    package My::Thing;

    use TB2::Mouse;
    with "TB2::CanLoad";

    My::Thing->load("Some::Module");

DESCRIPTION

Test::Builder2 must be careful to leave the global state of the test alone. This especially includes things like $@ and $!. Unfortunately, a lot of things change them. require is one of them.

This module provides load as a safe replacement for require which does not affect global variables (except the obvious ones like %INC).

load

    $class->load($module);

This works like require to load a module, except it will not affect $! and $@ and not trip a $SIG{__DIE__} handler. Use it internally in your test module when you want to load a module.

It will die on failure if the $module fails to load in which case it will set $@. If you want to trap the failure, see TB2::CanTry.

SEE ALSO

TB2::CanTry