Devel-Hide-0.0015/000755 000765 000024 00000000000 14124715305 013741 5ustar00davidstaff000000 000000 Devel-Hide-0.0015/README000644 000765 000024 00000001324 14042105444 014615 0ustar00davidstaff000000 000000 Devel-Hide version 0.0010 ========================= Simple tool for developers which allows to hide installed Perl modules. Used like this: perl -MDevel::Hide=Module/ToHide.pm script.pl INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires File::Temp (for perls older than 5.8.0) and Test::More for the testing part and recommends Test::Pod 1.18 Test::Pod::Coverage 1.04 also for testing - the POD part. COPYRIGHT AND LICENCE Copyright (C) 2005-2007, 2018 by Adriano R. Ferreira This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Devel-Hide-0.0015/Changes000644 000765 000024 00000004375 14124713761 015251 0ustar00davidstaff000000 000000 Revision history for Perl extension Devel::Hide. 0.0015 2021-09-28 - Test warnings more carefully to avoid spurious test failures caused by a bug in Test2::Util (http://www.cpantesters.org/cpan/report/c01ff7be-1e8a-11ec-bc66-57723b537541) 0.0014 2021-04-27 - Bump version requirement of Test::More to one that supports note() 0.0013 2020-02-16 - Cope with changes to how the hints hash works in perl 5.31.7 0.0012 2020-02-15 - Add -lexically argument to import() to support hiding modules just during the current scope 0.0011 2020-02-12 - Fix https://rt.cpan.org/Public/Bug/Display.html?id=120220 - Fix https://rt.cpan.org/Public/Bug/Display.html?id=120221 - Add -quiet option to suppress some notices 0.0010 2018-06-15 09:12:54-07:00 America/Los_Angeles - Makefile.PL: better prereqs declaration - typo fix - from dsteinbrunner/patch-1 0.0009 Mon Jan 28 2013 - avoid "defined @HIDDEN" which generates a warning since Perl 5.15.7 CPAN RT #74225 0.0008 Thu Nov 15 2007 - no real code changes - make t/050child-processes.t less clever for Windows' sake: which choked with too long argument and exec() 0.0007 Mon Nov 5 2007 - promoted: no longer a development release 0.0006_01 - some POD fixes - new option -from:children makes the selected modules hidden from process children as well (thanks to David Cantrell) 0.0005 Wed May 30 2007 - code reformatting with perltidy - now warns about already loaded modules - META.yml is auto-generated by Makefile.PL - a bit of refactoring to affect code readability - side effect: warnings are emitted at compile time and at every import call - a hopefully better timing - the package variable @HIDDEN does not change anymore 0.0004 Tue May 29 2007 - slight implementation change preparing for the big time 0.0003 Wed Oct 4 2006 - not a development version anymore - get rid of warning at "t/003user.t" - new test "t/098pod-coverage.t" 0.00_02 Sun Sep 25 2005 - lifted the requirement on perl 5.8: now 5.6.1 will do (because it may use File::Temp to fake bad modules) 0.00_01 Tue Sep 20 2005 - first release to CPAN 0.00_00 Tue Sep 13 2005 - absolute beginning Devel-Hide-0.0015/MANIFEST000644 000765 000024 00000001760 14124715305 015076 0ustar00davidstaff000000 000000 Changes Makefile.PL MANIFEST README t/001use.t t/002basic.t t/003user.t t/004env.t t/005lib.t t/006before.t t/050child-processes.t Tests -from:children t/child.pl script run from t/050child-processes.t t/090pod.t Tests POD for errors t/098pod-coverage.t Tests for POD coverage t/quiet.t Test that -quiet suppresses (some) warnings t/too-late-quiet.t Test that -quiet doesn't suppress warnings about not hiding stuff t/lexically.t Test that restricting hiding to a lexical scope works t/P.pm Dummy module used in tests t/Q.pm " t/R.pm " lib/Devel/Hide.pm META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Devel-Hide-0.0015/t/000755 000765 000024 00000000000 14124715305 014204 5ustar00davidstaff000000 000000 Devel-Hide-0.0015/META.yml000644 000765 000024 00000001307 14124715305 015213 0ustar00davidstaff000000 000000 --- abstract: 'Forces the unavailability of specified Perl modules (for testing)' author: - 'Adriano Ferreira ' build_requires: ExtUtils::MakeMaker: '0' Test::More: '0.82' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 7.56, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Devel-Hide no_index: directory: - t - inc requires: File::Temp: '0' perl: '5.006001' resources: repository: https://github.com/aferreira/cpan-Devel-Hide.git version: '0.0015' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Devel-Hide-0.0015/META.json000644 000765 000024 00000002656 14124715305 015373 0ustar00davidstaff000000 000000 { "abstract" : "Forces the unavailability of specified Perl modules (for testing)", "author" : [ "Adriano Ferreira " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 7.56, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Devel-Hide", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::Pod" : "1.18", "Test::Pod::Coverage" : "1.04" } }, "runtime" : { "requires" : { "File::Temp" : "0", "perl" : "5.006001" } }, "test" : { "requires" : { "Test::More" : "0.82" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/aferreira/cpan-Devel-Hide.git", "web" : "https://github.com/aferreira/cpan-Devel-Hide" } }, "version" : "0.0015", "x_serialization_backend" : "JSON::PP version 4.02" } Devel-Hide-0.0015/lib/000755 000765 000024 00000000000 14124715305 014507 5ustar00davidstaff000000 000000 Devel-Hide-0.0015/Makefile.PL000644 000765 000024 00000002526 14124715250 015717 0ustar00davidstaff000000 000000 use 5.006001; use ExtUtils::MakeMaker; my $EUMM_VERSION = $ExtUtils::MakeMaker::VERSION; $EUMM_VERSION =~ tr/_//d; my %write_makefile_args = ( NAME => 'Devel::Hide', VERSION_FROM => 'lib/Devel/Hide.pm', PREREQ_PM => { 'perl' => 5.006001, 'File::Temp' => 0, # perl ≤ 5.8.0 }, ABSTRACT_FROM => 'lib/Devel/Hide.pm', AUTHOR => 'Adriano Ferreira ', LICENSE => 'perl', META_MERGE => { 'dynamic_config' => 0, 'meta-spec' => { version => 2 }, 'prereqs' => { test => { requires => { 'Test::More' => 0.82, }, }, develop => { requires => { 'Test::Pod' => 1.18, 'Test::Pod::Coverage' => 1.04, }, }, }, resources => { repository => { type => 'git', url => 'https://github.com/aferreira/cpan-Devel-Hide.git', web => 'https://github.com/aferreira/cpan-Devel-Hide', }, }, }, ); delete $write_makefile_args{LICENSE} if $EUMM_VERSION < 6.31; delete $write_makefile_args{META_MERGE} if $EUMM_VERSION < 6.4501; WriteMakefile(%write_makefile_args); Devel-Hide-0.0015/lib/Devel/000755 000765 000024 00000000000 14124715305 015546 5ustar00davidstaff000000 000000 Devel-Hide-0.0015/lib/Devel/Hide.pm000644 000765 000024 00000031730 14124713661 016764 0ustar00davidstaff000000 000000 package Devel::Hide; use 5.006001; use strict; use warnings; our $VERSION = '0.0015'; # blech! package variables # # @HIDDEN is one of the ways to populate the global hidden list # $phase is used to identify which version of the hints hash to # use - either %^H when we're updating it, or pulling it out # of caller() when we want to read it use vars qw( @HIDDEN $phase ); BEGIN { $phase = 'runtime'; } # settings are a comma- (and only comma, no quotes or spaces) # -separated list of key,value,key,value,... There is no # attempt to support data containing commas. # # The list of hidden modules is a comma (and *only* comma, # no white space, no quotes) separated list of module # names. # # yes, this is a ridiculous way of storing data. It is, # however, compatible with what we're going to have to # store in the hints hash for lexical hiding, as that # only supports string data. my %GLOBAL_SETTINGS; _set_setting('global', children => 0); _set_setting('global', verbose => defined $ENV{DEVEL_HIDE_VERBOSE} ? $ENV{DEVEL_HIDE_VERBOSE} : 1 ); # convert a mixed list of modules and filenames to a list of # filenames sub _as_filenames { return map { /^(\w+::)*\w+$/ ? do { my $f = "$_.pm"; $f =~ s|::|/|g; $f } : $_ } @_; } # Pushes a list to the set of hidden modules/filenames # warns about the modules which could not be hidden (always) # and about the ones that were successfully hidden (if verbose) # # It works as a batch producing warning messages # at each invocation (when appropriate). # # the first arg is a reference to the config hash to use, # either global or lexical sub _push_hidden { my $config = shift; return unless @_; my @too_late; for ( _as_filenames(@_) ) { if ( $INC{$_} ) { push @too_late, $_; } else { $config->{'Devel::Hide/hidden'} = $config->{'Devel::Hide/hidden'} ? join(',', $config->{'Devel::Hide/hidden'}, $_) : $_; } } if ( @too_late ) { warn __PACKAGE__, ': Too late to hide ', join( ', ', @too_late ), "\n"; } if ( _get_setting('verbose') && $config->{'Devel::Hide/hidden'}) { no warnings 'uninitialized'; warn __PACKAGE__ . ' hides ' . join( ', ', sort split( /,/, $config->{'Devel::Hide/hidden'} ) ) . "\n"; } } sub _dont_load { my $filename = shift; my $hidden_by = _get_setting('verbose') ? 'hidden' : 'hidden by ' . __PACKAGE__; die "Can't locate $filename in \@INC ($hidden_by)\n"; } =begin private =item B<_core_modules> @core = _core_modules($perl_version); Returns the list of core modules according to Module::CoreList. !!! UNUSED BY NOW It is aimed to expand the tag ':core' into all core modules in the current version of Perl ($]). Requires Module::CoreList. =end private =cut sub _core_modules { require Module::CoreList; # XXX require 2.05 or newer return Module::CoreList->find_modules( qr/.*/, shift ); } # _append_to_perl5opt(@to_be_hidden) sub _append_to_perl5opt { $ENV{PERL5OPT} = join( ' ', defined($ENV{PERL5OPT}) ? $ENV{PERL5OPT} : (), '-MDevel::Hide=' . join(',', @_) ); } sub _is_hidden { no warnings 'uninitialized'; my $module = shift; +{ map { $_ => 1 } map { split(',', _get_config_ref($_)->{'Devel::Hide/hidden'}) } qw(global lexical) }->{$module}; } sub _get_setting { my $name = shift; _exists_setting('lexical', $name) ? _get_setting_from('lexical', $name) : _get_setting_from('global', $name) } sub _get_setting_from { my($source, $name) = @_; my $config = _get_config_ref($source); _setting_hashref($config)->{$name}; } sub _exists_setting { my($source, $name) = @_; my $config = _get_config_ref($source); exists(_setting_hashref($config)->{$name}); } sub _set_setting { my($source, $name, $value) = @_; my $config = _get_config_ref($source); my %hash = ( %{_setting_hashref($config)}, $name => $value ); _get_config_ref($source) ->{'Devel::Hide/settings'} = join(',', %hash); } sub _setting_hashref { my $settings = shift->{'Devel::Hide/settings'}; no warnings 'uninitialized'; +{ split(/,/, $settings) }; } sub _get_config_ref { my $type = shift; if($type eq 'lexical') { if($phase eq 'compile') { return \%^H; } else { my $depth = 1; while(my @fields = caller($depth)) { my $hints_hash = $fields[10]; if($hints_hash && grep { /^Devel::Hide\// } keys %{$hints_hash}) { # return a copy return { %{$hints_hash} }; } $depth++; } return {}; } } else { return \%GLOBAL_SETTINGS; } } sub import { shift; my $which_config = 'global'; local $phase = 'compile'; while(@_ && $_[0] =~ /^-/) { if( $_[0] eq '-lexically' ) { $which_config = 'lexical'; if($] < 5.010) { die("Can't 'use Devel::Hide qw(-lexically ...)' on perl 5.8 and below\n"); } } elsif( $_[0] eq '-from:children' ) { _set_setting($which_config, children => 1); } elsif( $_[0] eq '-quiet' ) { _set_setting($which_config, verbose => 0); } else { die("Devel::Hide: don't recognize $_[0]\n"); } shift; } if (@_) { _push_hidden( _get_config_ref($which_config), @_ ); if (_get_setting('children')) { _append_to_perl5opt( (_get_setting('verbose') ? () : '-quiet'), @_ ); } } } # $ENV{DEVEL_HIDE_PM} is split in ' ' # as well as @HIDDEN it accepts Module::Module as well as File/Names.pm BEGIN { # unless @HIDDEN was user-defined elsewhere, set default if ( !@HIDDEN && $ENV{DEVEL_HIDE_PM} ) { # NOTE. "split ' ', $s" is special. Read "perldoc -f split". _push_hidden( _get_config_ref('global'), split q{ }, $ENV{DEVEL_HIDE_PM} ); } else { _push_hidden( _get_config_ref('global'), @HIDDEN ); } } sub _inc_hook { my ( $coderef, $filename ) = @_; if ( _is_hidden($filename) ) { _dont_load($filename); } else { return undef; } } use lib ( \&_inc_hook ); # TO DO: # * write unimport() sub # * write decent docs # * refactor private function names # * RT #25528 =begin private perl -MDevel::Hide=!:core -e script.pl # hide all non-core modules perl -MDevel::Hide=M,!N -e script.pl # hide all modules but N plus M how to implement %GLOBAL_SETTINGS %IS_EXCEPTION if there is an exception, all but the set of exceptions are to be hidden plus the set of hidden modules :core(5.8) :core synonym to :core($]) =end private =cut 1; __END__ =head1 NAME Devel::Hide - Forces the unavailability of specified Perl modules (for testing) =head1 SYNOPSIS # hide modules globally, across the entire process use Devel::Hide qw(Module/ToHide.pm); require Module::ToHide; # fails use Devel::Hide qw(Test::Pod Test::Pod::Coverage); require Test::More; # ok use Test::Pod 1.18; # fails # hide modules lexically { use Devel::Hide qw(-lexically Foo::Bar); # this will fail to load eval 'use Foo::Bar'; } # but this will load use Foo::Bar; Other common usage patterns: $ perl -MDevel::Hide=Module::ToHide Makefile.PL $ perl -MDevel::Hide=Module::ToHide,Test::Pod Makefile.PL $ PERL5OPT=-MDevel::Hide $ DEVEL_HIDE_PM='Module::ToHide Test::Pod' $ export PERL5OPT DEVEL_HIDE_PM $ perl Makefile.PL =head1 COMPATIBILITY =over =item global hiding At some point global hiding may B and only lexical hiding be supported. At that point support for perl versions below 5.10 will be dropped. There will be at least a two year deprecation cycle before that happens. You are strongly encouraged to only use lexical hiding and to update existing code. =item perl 5.6 Support will be dropped at some point after 2022-01-01 with no further warning. This is because bugs in older perls prevent some code improvements. See commit dd27e50 in the repository if you care to know what those are. =back =head1 DESCRIPTION Given a list of Perl modules/filenames, this module makes C and C statements fail (no matter the specified files/modules are installed or not). They I with a message like: Can't locate Module/ToHide.pm in @INC (hidden) The original intent of this module is to allow Perl developers to test for alternative behavior when some modules are not available. In a Perl installation, where many modules are already installed, there is a chance to screw things up because you take for granted things that may not be there in other machines. For example, to test if your distribution does the right thing when a module is missing, you can do perl -MDevel::Hide=Test::Pod Makefile.PL forcing C to not be found (whether it is installed or not). Another use case is to force a module which can choose between two requisites to use the one which is not the default. For example, C needs a parser module and may use C or C (preferring the latter). If you have both of them installed, it will always try C. But you can say: perl -MDevel::Hide=XML::SAX script_which_uses_xml_simple.pl NOTE. This module does not use L. As said before, denial I. This module is pretty trivial. It uses a code reference in @INC to get rid of specific modules during require - denying they can be successfully loaded and stopping the search before they have a chance to be found. There are three alternative ways to include modules in the hidden list: =over 4 =item import() this is probably the most commonly used method, called automagically when you do this: use Devel::Hide qw(Foo Bar::Baz); or perl -MDevel::Hide=... =item setting @Devel::Hide::HIDDEN =item environment variable DEVEL_HIDE_PM both of these two only support 'global' hiding, whereas C supports lexical hiding as well. =back Optionally, you can provide some arguments *before* the list of modules: =over =item -from:children propagate the list of hidden modules to your process' child processes. This works by populating C, and is incompatible with Taint mode, as explained in L. Of course, this is unnecessary if your child processes are just forks of the current one. =item -lexically This is only available on perl 5.10.0 and later. It is a fatal error to try to use it on an older perl. Everything following this will only have effect until the end of the current scope. Yes, that includes C<-quiet>. =begin private PERL5OPT is populated globally even when -lexically is in use. How can its value be lexicalised? Or how can all the various ways of spawning a child be lexicalised? =end private =item -quiet suppresses diagnostic output. You will still get told about errors. This is passed to child processes if -from:children is in effect. =back =head1 CAVEATS There is some interaction between C and this module use Devel::Hide qw(Module/ToHide.pm); use lib qw(my_lib); In this case, 'my_lib' enters the include path before the Devel::Hide hook and if F is found in 'my_lib', it succeeds. More generally, any code that adds anything to the front of the C<@INC> list after Devel::Hide is loaded will have this effect. Also for modules that were loaded before Devel::Hide, C and C succeeds. Since 0.0005, Devel::Hide warns about modules already loaded. $ perl -MDevel::Hide=Devel::Hide -e '' Devel::Hide: Too late to hide Devel/Hide.pm =head1 EXPORTS Nothing is exported. =head1 ENVIRONMENT VARIABLES DEVEL_HIDE_PM - if defined, the list of modules is added to the list of hidden modules DEVEL_HIDE_VERBOSE - on by default. If off, suppresses the initial message which shows the list of hidden modules in effect PERL5OPT - used if you specify '-from:children' =head1 SEE ALSO L L =head1 BUGS =over =item bug C<-from:children> and C<-lexically> don't like each other. Anything hidden lexically may be hidden from all child processes without regard for scope. Don't use them together. =back Please report any other bugs you find via CPAN RT L. =head1 AUTHORS Adriano R. Ferreira, Eferreira@cpan.orgE with contributions from David Cantrell Edcantrell@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2005-2007, 2018 by Adriano R. Ferreira Some parts copyright (C) 2020 by David Cantrell This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Devel-Hide-0.0015/t/004env.t000644 000765 000024 00000000657 14042105444 015411 0ustar00davidstaff000000 000000 use strict; use Test::More tests => 5; use_ok('lib', 't'); # this script tests Devel::Hide respects environment variable DEVEL_HIDE_PM $ENV{DEVEL_HIDE_PM} = 'Q.pm R'; use_ok('Devel::Hide'); eval { require P }; ok(!$@, "P was loaded (as it should)"); eval { require Q }; like($@, qr/^Can't locate Q\.pm/, "Q not found (as it should)"); eval { require R }; like($@, qr/^Can't locate R\.pm/, "R not found (as it should)"); Devel-Hide-0.0015/t/090pod.t000644 000765 000024 00000000241 14042105444 015375 0ustar00davidstaff000000 000000 use strict; use Test::More; eval "use Test::Pod 1.18"; plan skip_all => "Test::Pod 1.18 required for testing POD" if $@; all_pod_files_ok(all_pod_files(".")); Devel-Hide-0.0015/t/R.pm000644 000765 000024 00000000021 14042105444 014730 0ustar00davidstaff000000 000000 package R; 1; Devel-Hide-0.0015/t/too-late-quiet.t000644 000765 000024 00000001134 14042105444 017235 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More tests => 6; use lib 't'; my @expected_warnings; BEGIN { push @expected_warnings, 'Devel::Hide: Too late to hide P.pm'; $SIG{__WARN__} = sub { ok($_[0] eq shift(@expected_warnings)."\n", "got expected warning: $_[0]"); } } END { ok(!@expected_warnings, "got all expected warnings") } use_ok('P'); # loads P # too late to hide P. Q will be hidden, but not mentioned use_ok('Devel::Hide', '-quiet', 'P', 'Q'); eval { require P }; ok(!$@, "P was loaded (as it should)"); eval { require Q }; ok($@, "Q was not loaded"); Devel-Hide-0.0015/t/003user.t000644 000765 000024 00000000752 14042105444 015572 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More tests => 5; use_ok('lib', 't'); # this script tests setting @HIDDEN before using Devel::Hide { no warnings 'once'; # @HIDDEN is used by Devel::Hide @Devel::Hide::HIDDEN = qw(Q.pm R); } use_ok('Devel::Hide'); eval { require P }; ok(!$@, "P was loaded (as it should)"); eval { require Q }; like($@, qr/^Can't locate Q\.pm/, "Q not found (as it should)"); eval { require R }; like($@, qr/^Can't locate R\.pm/, "R not found (as it should)"); Devel-Hide-0.0015/t/098pod-coverage.t000644 000765 000024 00000000243 14042105444 017200 0ustar00davidstaff000000 000000 use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok();Devel-Hide-0.0015/t/001use.t000644 000765 000024 00000000203 14042105444 015375 0ustar00davidstaff000000 000000 use strict; use Test::More tests => 1; use_ok('Devel::Hide'); diag( "Testing Devel::Hide $Devel::Hide::VERSION, Perl $], $^X" );Devel-Hide-0.0015/t/002basic.t000644 000765 000024 00000002071 14042105444 015670 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More tests => 14; use lib 't'; my @expected_warnings; BEGIN { push @expected_warnings, 'Devel::Hide hides Q.pm, R.pm'; $SIG{__WARN__} = sub { ok($_[0] eq shift(@expected_warnings)."\n", "got expected warning: $_[0]"); } } END { ok(!@expected_warnings, "got all expected warnings") } use Devel::Hide qw(Q.pm R); # do this twice, see https://rt.cpan.org/Ticket/Display.html?id=120220 foreach my $pass (1, 2) { eval { require P }; ok(!$@, "nothing moaned about loading P". ($pass == 2 ? ' again' : '')); ok(exists($INC{"P.pm"}), "P is loaded"); eval { require Q }; like($@, qr/^Can't locate Q\.pm in \@INC/, "correctly moaned about loading Q". ($pass == 2 ? ' again' : '')); ok(!exists($INC{"Q.pm"}), "correctly didn't load Q"); eval { require R }; like($@, qr/^Can't locate R\.pm in \@INC/, "correctly moaned about loading R". ($pass == 2 ? ' again' : '')); ok(!exists($INC{"R.pm"}), "correctly didn't load R"); } Devel-Hide-0.0015/t/lexically.t000644 000765 000024 00000003057 14042105444 016360 0ustar00davidstaff000000 000000 use strict; use warnings; BEGIN { require Test::More; $] < 5.010 ? Test::More->import(skip_all => "perl too old") : Test::More->import(tests => 9); } use lib 't'; my @expected_warnings; BEGIN { push @expected_warnings, 'Devel::Hide hides R.pm', 'Devel::Hide hides Q.pm'; $SIG{__WARN__} = sub { if(!@expected_warnings) { fail("Got unexpected warning '$_[0]'") } else { is($_[0], shift(@expected_warnings)."\n", "got expected warning: $_[0]"); } } } END { ok(!@expected_warnings, "got all expected warnings") } # hide R globally use Devel::Hide qw(R); note("R hidden globally, and noisily"); eval { require R }; like($@, qr/^Can't locate R\.pm in \@INC/, "correctly moaned about hiding R (globally)"); { use Devel::Hide qw(-lexically -quiet Q.pm); note("Q hidden lexically, quietly"); eval { require Q }; like($@, qr/^Can't locate Q\.pm in \@INC/, "correctly moaned about loading Q"); eval { require R }; like($@, qr/^Can't locate R\.pm in \@INC/, "still can't load R which is globally hidden"); } { use Devel::Hide qw(-lexically Q); note("Q hidden in a different scope, noisily"); eval { require Q }; like($@, qr/^Can't locate Q\.pm in \@INC/, "correctly moaned about loading Q"); } note("Now we're outside that lexical scope"); eval { require Q }; ok(!$@, "nothing moaned about loading Q"); eval { require R }; like($@, qr/^Can't locate R\.pm in \@INC/, "still can't load R"); Devel-Hide-0.0015/t/006before.t000644 000765 000024 00000001116 14042105444 016054 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More tests => 7; use lib 't'; my @expected_warnings; BEGIN { push @expected_warnings, 'Devel::Hide: Too late to hide P.pm', 'Devel::Hide hides Q.pm'; $SIG{__WARN__} = sub { ok($_[0] eq shift(@expected_warnings)."\n", "got expected warning: $_[0]"); } } END { ok(!@expected_warnings, "got all expected warnings") } use_ok('P'); # loads P use_ok('Devel::Hide', 'P', 'Q'); # too late to hide P eval { require P }; ok(!$@, "P was loaded (as it should)"); eval { require Q }; ok($@, "Q was not loaded"); Devel-Hide-0.0015/t/050child-processes.t000644 000765 000024 00000000701 14042105444 017677 0ustar00davidstaff000000 000000 use strict; use warnings; use Devel::Hide qw(-quiet -from:children Q.pm R); # Mlib=t is to get around 'use lib' etc being annoying $ENV{PERL5OPT} = '-Mblib '.$ENV{PERL5OPT} if($INC{'blib.pm'}); $ENV{PERL5OPT} = '-Mlib=t '.$ENV{PERL5OPT}; # run this script and tell it to: # try to load P, Q and R; # expect only P to succeed; # moan about Q and R my $ans = system( $^X, qw( t/child.pl try:PQR succeed:P moan:QR ) ); exit( $ans >> 8 ); Devel-Hide-0.0015/t/005lib.t000644 000765 000024 00000000414 14042105444 015357 0ustar00davidstaff000000 000000 use strict; use Test::More tests => 4; use_ok('lib', 't'); # this script tests "use lib" after "use Devel::Hide" use_ok('Devel::Hide'); use_ok('lib', 't'); # put 't' before the Devel::Hide hook in @INC eval { require P }; ok(!$@, "P was loaded (as it should)"); Devel-Hide-0.0015/t/child.pl000644 000765 000024 00000001442 14124714126 015625 0ustar00davidstaff000000 000000 use strict; use warnings; my $warnings; BEGIN { $SIG{__WARN__} = sub { $warnings++ if($_[0] =~ /^Devel::Hide/) } } my %args; BEGIN { %args = map { my($k, $v) = split(/:/, $_); $k => [split(//, $v)] } @ARGV; } # the command line had -MDevel::Hide=-quiet so # the warning this generates should be suppressed use Devel::Hide 'Q'; use Test::More tests => 2 + @{$args{try}}; ok($ENV{PERL5OPT} =~ /\bMlib=t\b/, "PERL5OPT is added to, not overwritten: $ENV{PERL5OPT}"); foreach my $try (@{$args{try}}) { eval "require $try"; if(!grep { $_ eq $try } @{$args{moan}}) { ok(!$@, "nothing moaned about loading $try"); } else { like($@, qr/^Can't locate $try\.pm/, "correctly moaned about loading $try"); } } ok(!$warnings, "suppressed warnings"); Devel-Hide-0.0015/t/P.pm000644 000765 000024 00000000021 14042105444 014726 0ustar00davidstaff000000 000000 package P; 1; Devel-Hide-0.0015/t/quiet.t000644 000765 000024 00000000471 14042105444 015516 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More tests => 2; use lib 't'; my $warnings; BEGIN { $SIG{__WARN__} = sub { $warnings++ } } END { ok(!$warnings, "suppressed warnings"); } use Devel::Hide qw(-quiet Q); eval { require Q }; like($@, qr/^Can't locate Q\.pm in \@INC/, "correctly moaned about loading Q"); Devel-Hide-0.0015/t/Q.pm000644 000765 000024 00000000021 14042105444 014727 0ustar00davidstaff000000 000000 package Q; 1;