The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

thanks - no thanks, I don't want that module

SYNOPSIS

        no thanks 'strict';
        use strict; # no-op

DESCRIPTION

This module asks Perl politely not to load a module you don't want loading. It's just a polite request; we're not forcing Perl to do anything it doesn't want to. And if the module is already loaded, then we won't try to unload it or anything like that.

Specifically, Perl's use Module::Name syntax does two things. It reads, compiles and executes Module/Name.pm, and calls the class method Module::Name->import. This module is designed to prevent the first thing happening, not the second thing.

How does it work? Perl keeps a record of what modules have already been loaded in the %INC global hash, to avoid reloading them. This module just adds an entry to that hash to trick Perl into thinking that a module has already been loaded.

Methods

unimport
        no thanks @LIST;

If @LIST is empty, then the caller package is assumed.

Use Case 1: You Really Want to Prevent a Module from Loading

It's quite a messy thing to do, but if you really need to silently prevent a module from being loaded, then no thanks will do the trick. Just make sure you do it early.

This is almost always a bad idea.

Use Case 2: Multiple Packages in the Same File

Perl's use keyword muddies the distinction between packages (which are just namespaces) and modules (which are just files). Sometimes you wish to define two packages (say My::Package and My::Package::Helper) in the same file (say My/Package.pm). If anybody tries to load My::Package::Helper with use, then they'll get an error message. If My/Package.pm includes:

        no thanks 'My::Package::Helper';

then this will prevent use My::Package::Helper from throwing an error message, provided My/Package.pm is already loaded.

BUGS

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=thanks.

SEE ALSO

again, Module::Reload, Class::Unload.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2012 by Toby Inkster.

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

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.