diff options
Diffstat (limited to 'gnu/usr.bin/perl/cpan/Module-Pluggable/t')
11 files changed, 166 insertions, 4 deletions
diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/19can_ok_clobber.t b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/19can_ok_clobber.t index 07c598b4ba1..60616f6a300 100755 --- a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/19can_ok_clobber.t +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/19can_ok_clobber.t @@ -10,7 +10,7 @@ use Test::More tests=>5; #use_ok( 'MyTest' ); #diag "Module::Pluggable::VERSION $Module::Pluggable::VERSION"; -my @plugins = MyTest->plugins; +my @plugins = sort MyTest->plugins; my @plugins_after; use_ok( 'MyTest::Plugin::Foo' ); @@ -21,16 +21,16 @@ is_deeply( \@plugins_after, \@plugins, "plugins haven't been clobbered", -); +) or diag Dumper(\@plugins_after,\@plugins); can_ok ($foo, 'frobnitz'); -@plugins_after = MyTest->plugins; +@plugins_after = sort MyTest->plugins; is_deeply( \@plugins_after, \@plugins, "plugins haven't been clobbered", -) or diag Dumper ; +) or diag Dumper(\@plugins_after,\@plugins); diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/22trigger.t b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/22trigger.t new file mode 100644 index 00000000000..819e9ef20f0 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/22trigger.t @@ -0,0 +1,54 @@ +#!perl -w + +use strict; +use FindBin; +use lib (($FindBin::Bin."/lib")=~/^(.*)$/); +use Test::More tests => 7; + +my $foo; +my @plugins; +my @errors; +ok($foo = TriggerTest->new(), "Created new TriggerTest"); +ok(@plugins = $foo->plugins, "Ran plugins"); +ok(@errors = $foo->errors, "Got errors"); +is_deeply([sort @plugins], ['TriggerTest::Plugin::After', 'TriggerTest::Plugin::CallbackAllow'], "Got the correct plugins"); +is_deeply([@errors], ['TriggerTest::Plugin::Error'], "Got the correct errors"); +ok(_is_loaded('TriggerTest::Plugin::CallbackDeny'), "CallbackDeny has been required"); +ok(!_is_loaded('TriggerTest::Plugin::Deny'), "Deny has not been required"); + + +# Stolen from Module::Loaded by Chris Williams (bingOs) +sub _is_loaded { + my $pm = shift; + my $file = __PACKAGE__->_pm_to_file( $pm ) or return; + return $INC{$file} if exists $INC{$file}; + return; +} + +sub _pm_to_file { + my $pkg = shift; + my $pm = shift or return; + my $file = join '/', split '::', $pm; + $file .= '.pm'; + return $file; +} + +package TriggerTest; + +our @ERRORS; +use strict; +use Module::Pluggable require => 1, + on_require_error => sub { my $p = shift; push @ERRORS, $p; return 0 }, + before_require => sub { my $p = shift; return !($p eq "TriggerTest::Plugin::Deny") }, + after_require => sub { my $p = shift; return !($p->can('exclude') && $p->exclude) }; + +sub new { + my $class = shift; + return bless {}, $class; +} + +sub errors { + @ERRORS; +} +1; + diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/23depth.t b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/23depth.t new file mode 100644 index 00000000000..ef3fb31f49a --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/23depth.t @@ -0,0 +1,38 @@ +#!perl -w + +use strict; +use FindBin; +use lib (($FindBin::Bin."/lib")=~/^(.*)$/); +use Test::More tests => 2; + + +my $min = MinTest->new(); +my $max = MaxTest->new(); +is_deeply([sort qw(MyOtherTest::Plugin::Bar MyOtherTest::Plugin::Foo MyOtherTest::Plugin::Quux)], [sort $max->plugins], "min depth"); +is_deeply([qw(MyOtherTest::Plugin::Quux::Foo)], [sort $min->plugins], "max depth"); + + +package MinTest; +use File::Spec::Functions qw(catdir); +use strict; +use File::Spec::Functions qw(catdir); +use Module::Pluggable search_path => "MyOtherTest::Plugin", min_depth => 4; + + +sub new { + my $class = shift; + return bless {}, $class; +} + +package MaxTest; +use File::Spec::Functions qw(catdir); +use strict; +use File::Spec::Functions qw(catdir); +use Module::Pluggable search_path => "MyOtherTest::Plugin", max_depth => 3; + + +sub new { + my $class = shift; + return bless {}, $class; +} +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/24local_inc_object.t b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/24local_inc_object.t new file mode 100644 index 00000000000..c8e00facfce --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/24local_inc_object.t @@ -0,0 +1,23 @@ +#!perl -w + +use strict; +use FindBin; +use Test::More tests => 2; + +my $inc = IncTest->new(); +my ($ta) = grep { ref($_) eq 'Text::Abbrev'} eval { local ($^W) = 0; $inc->plugins }; +ok($ta); +is($ta->MPCHECK, "HELLO"); + +package IncTest; +use Module::Pluggable search_path => "Text", + search_dirs => "t/lib", + instantiate => 'module_pluggable', + on_require_error => sub { }, + on_instantiate_error => sub { }; + +sub new { + my $class = shift; + return bless {}, $class; +} +1; diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/24local_inc_package.t b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/24local_inc_package.t new file mode 100644 index 00000000000..ef0f330f1d2 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/24local_inc_package.t @@ -0,0 +1,17 @@ +#!perl -w + +use strict; +use FindBin; +use Test::More tests => 1; + +IncTest->new()->plugins; +is(Text::Abbrev->MPCHECK, "HELLO"); + +package IncTest; +use Module::Pluggable search_path => "Text", search_dirs => "t/lib", require => 1; + +sub new { + my $class = shift; + return bless {}, $class; +} +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/Text/Abbrev.pm b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/Text/Abbrev.pm new file mode 100644 index 00000000000..8417072f3ec --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/Text/Abbrev.pm @@ -0,0 +1,10 @@ +package Text::Abbrev; +use strict; + +sub module_pluggable { + return bless {}, shift; +} + +sub MPCHECK { "HELLO" } + +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/After.pm b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/After.pm new file mode 100644 index 00000000000..b5f69015575 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/After.pm @@ -0,0 +1,3 @@ +package TriggerTest::Plugin::After; + +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/CallbackAllow.pm b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/CallbackAllow.pm new file mode 100644 index 00000000000..589b154ca4d --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/CallbackAllow.pm @@ -0,0 +1,6 @@ +package TriggerTest::Plugin::CallbackAllow; + +sub exclude { + return 0; +} +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/CallbackDeny.pm b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/CallbackDeny.pm new file mode 100644 index 00000000000..e63227f59c1 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/CallbackDeny.pm @@ -0,0 +1,6 @@ +package TriggerTest::Plugin::CallbackDeny; + +sub exclude { + return 1; +} +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/Deny.pm b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/Deny.pm new file mode 100644 index 00000000000..311e2a07a04 --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/Deny.pm @@ -0,0 +1,3 @@ +package TriggerTest::Plugin::Deny; + +1;
\ No newline at end of file diff --git a/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/Error.pm b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/Error.pm new file mode 100644 index 00000000000..620465a942c --- /dev/null +++ b/gnu/usr.bin/perl/cpan/Module-Pluggable/t/lib/TriggerTest/Plugin/Error.pm @@ -0,0 +1,2 @@ +package TriggerTest::Plugin::Error; + |