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

NAME

lib::noop::except - no-op loading of all modules except some

VERSION

This document describes version 0.006 of lib::noop::except (from Perl distribution lib-noop), released on 2021-06-07.

SYNOPSIS

 use lib::noop::except qw(Foo::Bar Baz);
 use Foo::Bar; # not no-op'ed
 use Qux; # no-op'ed

DESCRIPTION

Given a list of module names, it will make subsequent loading of all but those modules a no-op. It works by installing a require hook in @INC and return "1;" as the source code for no-op'ed modules.

This makes loading a no-op'ed module a success, even though the module does not exist on the filesystem. And the %INC entry for the module will be added, making subsequent loading of the same module a no-op too because Perl's require will see that the entry for the module in %INC already exists.

But, since the loading is a no-op operation, no code other than "1;" is executed and if the original module contains function or package variable definition, they will not be defined.

This pragma can be used e.g. for testing.

To cancel the effect of lib::noop::except, you can unimport it. If you then want to actually load a module that has been no-op'ed, you have to delete its %INC entry first:

 use lib::noop::except qw(Foo);
 use Data::Dumper; # no-op'ed

 # this code will die because Data::Dumper::Dumper is not defined
 BEGIN { print Data::Dumper::Dumper([1,2,3]) }

 no lib::noop::except;
 BEGIN { delete $INC{"Data/Dumper.pm"} }
 use Data::Dumper;

 # this code now runs ok
 BEGIN { print Data::Dumper::Dumper([1,2,3]) }

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/lib-noop.

SOURCE

Source repository is at https://github.com/perlancar/perl-lib-noop.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=lib-noop

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

lib::noop

lib::noop::all

lib::noop::all_missing

lib::allow will do sort-of the opposite: only allow loading some modules while disallowing the others.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021, 2016 by perlancar@cpan.org.

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