use Test::Without::Modules qw( HTML::Template ); use Test::Without::Modules qr/^POE::/; #### BEGIN { @SAVED_INC = @INC; }; sub import { @INC = sub { # return undef if it's a blocked module # Look if the module is in @SAVED_INC # Return a filehandle to it }; }; #### BEGIN { @SAVED_INC = @INC; }; sub import { @INC = sub { # return undef if it's a blocked module }; }; #### sub import { $INC{$module} = 1; *{$module."::import"} = sub { die 'ugh'; }; }; #### eval { require Optional::Module }; if ($@) { # module is not available }; #### sub import { unshift @INC, sub { # return dummy module filehandle if it's a blocked module }; }; #### use vars qw( %forbidden ); sub import { my ($self,@forbidden_modules) = @_; scrub( $module ) for @forbidden_modules; unshift @INC, sub { my (undef,$filename,undef) = @_; if (exists $forbidden{$filename}) { # return faked, failing module }; }; }; #### package Test::Without::Module; use strict; use File::Temp; use Carp qw( croak ); use vars qw( %forbidden $VERSION ); $VERSION = 0.01; sub import { my ($self,@forbidden_modules) = @_; $forbidden{$_} = $_ for @forbidden_modules; # Scrub %INC, so that loaded modules disappear my ($module); for $module (@forbidden_modules) { scrub( $module ); }; # Move our handler to the front of the list @INC = grep { $_ ne \&fake_module } @INC; unshift @INC, \&fake_module; }; sub fake_module { my ($self,$module_file,$member_only) = @_; warn $@ if $@; my $modulename = file2module($module_file); # Deliver a faked, nonworking module if (grep { $modulename =~ $_ } keys %forbidden) { my $fh = File::Temp::tmpfile(); print $fh < and C. =begin testing no warnings 'once'; eval 'use Test::Without::Module qw( File::Temp )'; eval 'no Test::Without::Module qw( File::Temp )'; is_deeply( [keys %Test::Without::Module::forbidden],[],"Module list" ); eval { require File::Temp; }; is( $@, '', "unimport" ); =end testing =head1 BUGS =over 4 =item * There is no lexicalic scoping (yet) =back =head1 AUTHOR Max Maischein, Ecorion@cpan.orgE =head1 SEE ALSO L, L, L =cut #### perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web