Toby Inkster avatar Toby Inkster committed 6d0a566

initial version

Comments (0)

Files changed (12)

+use inc::Module::Package 'RDF 0.009';
+
+package thanks;
+
+use 5.006;
+
+BEGIN {
+	$thanks::AUTHORITY = 'cpan:TOBYINK';
+	$thanks::VERSION   = '0.001';	
+}
+
+sub _module_notional_filename
+{
+	(my $name = shift) =~ s!::!/!g;
+	return $name . q[.pm];
+}
+
+sub unimport
+{
+	my $class = shift;
+	my @caller = caller(0);
+	@_ = $caller[0] unless @_;
+	my $file = $caller[1];
+	foreach my $module (@_)
+		{ $INC{ _module_notional_filename($module) } = $file }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+thanks - no thanks, I don't want that module
+
+=head1 SYNOPSIS
+
+	no thanks 'strict';
+	use strict; # no-op
+
+=head1 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 C<< use Module::Name >> syntax does two things. It reads,
+compiles and executes C<< Module/Name.pm >>, and calls the class method
+C<< 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 C<< %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.
+
+=head2 Methods
+
+=over
+
+=item C<< unimport >>
+
+	no thanks @LIST;
+
+If C<< @LIST >> is empty, then the caller package is assumed.
+
+=back
+
+=head2 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 C<< no thanks >> will do the trick. Just
+make sure you do it early.
+
+This is almost always a bad idea.
+
+=head2 Use Case 2: Multiple Packages in the Same File
+
+Perl's C<< 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 C<< My::Package >> and
+C<< My::Package::Helper >>) in the same file (say C<< My/Package.pm >>). If
+anybody tries to load C<< My::Package::Helper >> with C<use>, then they'll
+get an error message. If C<< My/Package.pm >> includes:
+
+	no thanks 'My::Package::Helper';
+
+then this will prevent C<< use My::Package::Helper >> from throwing an error
+message, provided C<< My/Package.pm >> is already loaded.
+
+=head1 BUGS
+
+Please report any bugs to
+L<http://rt.cpan.org/Dist/Display.html?Queue=thanks>.
+
+=head1 SEE ALSO
+
+L<again>,
+L<Module::Reload>,
+L<Class::Unload>.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 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.
+
+=head1 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.
+

meta/changes.pret

+# This file acts as the project's changelog.
+
+`thanks 0.001 cpan:TOBYINK`
+	issued  2012-09-07;
+	label   "Initial release".
+
+# This file contains general metadata about the project.
+
+@prefix : <http://usefulinc.com/ns/doap#>.
+
+`thanks`
+	:programming-language "Perl" ;
+	:shortdesc            "no thanks, I don't want that module";
+	:homepage             <https://metacpan.org/release/thanks>;
+	:download-page        <https://metacpan.org/release/thanks>;
+	:bug-database         <http://rt.cpan.org/Dist/Display.html?Queue=thanks>;
+	:repository           [ a :HgRepository; :browse <https://bitbucket.org/tobyink/p5-thanks> ];
+	:created              2012-09-07;
+	:license              <http://dev.perl.org/licenses/>;
+	:maintainer           cpan:TOBYINK;
+	:developer            cpan:TOBYINK.
+
+<http://dev.perl.org/licenses/>
+	dc:title  "the same terms as the perl 5 programming language system itself".
+
+cpan:TOBYINK
+	foaf:name  "Toby Inkster";
+	foaf:mbox  <mailto:tobyink@cpan.org>.
+

meta/makefile.pret

+# This file provides instructions for packaging.
+
+`thanks`
+	perl_version_from m`thanks`;
+	version_from      m`thanks`;
+	readme_from       m`thanks`;
+	test_requires     p`Test::More 0.61`  .
+
+use strict;
+use Test::More tests => 2;
+BEGIN { use_ok('thanks') };
+
+ok(strict->can('unimport'));
+no thanks 'strict';
+use Test::More tests => 1;
+use strict;
+
+ok not(strict->can('unimport'));
+package strict;
+no thanks;
+package main;
+use Test::More tests => 1;
+use strict;
+
+ok not(strict->can('unimport'));
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();
+

xt/02pod_coverage.t

+use Test::More;
+use Test::Pod::Coverage;
+
+my @modules = qw(thanks);
+pod_coverage_ok($_, "$_ is covered") for @modules;
+done_testing(scalar @modules);
+

xt/03meta_uptodate.t

+use Test::More tests => 1;
+use Test::RDF::DOAP::Version;
+doap_version_ok('thanks', 'thanks');
+
+use Test::EOL;
+all_perl_files_ok();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.