diff options
author | Craig A. Berry <craigberry@mac.com> | 2007-04-22 14:34:28 +0000 |
---|---|---|
committer | Craig A. Berry <craigberry@mac.com> | 2007-04-22 14:34:28 +0000 |
commit | a2afd30e9deb0557e418d7a2be7b6d880dd5ee21 (patch) | |
tree | ba94057b463b3bc8b22d093fe0ca1f03f15f680b /t/Module_Pluggable | |
parent | 65e807b815b1236dd131a40c532f9d657948ba20 (diff) | |
download | perl-a2afd30e9deb0557e418d7a2be7b6d880dd5ee21.tar.gz |
Move Module::Pluggable tests up under main test directory.
p4raw-id: //depot/perl@31019
Diffstat (limited to 't/Module_Pluggable')
50 files changed, 1432 insertions, 0 deletions
diff --git a/t/Module_Pluggable/01use.t b/t/Module_Pluggable/01use.t new file mode 100644 index 0000000000..be0b8481ac --- /dev/null +++ b/t/Module_Pluggable/01use.t @@ -0,0 +1,9 @@ +#!perl -w + +use strict; +use Test::More tests => 3; + +use_ok('Module::Pluggable'); +use_ok('Module::Pluggable::Object'); +use_ok('Devel::InnerPackage'); + diff --git a/t/Module_Pluggable/02alsoworks.t b/t/Module_Pluggable/02alsoworks.t new file mode 100644 index 0000000000..c7b00adbe2 --- /dev/null +++ b/t/Module_Pluggable/02alsoworks.t @@ -0,0 +1,42 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 5; + +my $foo; +ok($foo = MyOtherTest->new()); + +my @plugins; +my @expected = qw(MyOtherTest::Plugin::Bar MyOtherTest::Plugin::Foo MyOtherTest::Plugin::Quux MyOtherTest::Plugin::Quux::Foo); +ok(@plugins = sort $foo->plugins); + + + +is_deeply(\@plugins, \@expected, "is deeply"); + +@plugins = (); + +ok(@plugins = sort MyOtherTest->plugins); + + + + +is_deeply(\@plugins, \@expected, "is deeply class"); + + + +package MyOtherTest; + +use strict; +use Module::Pluggable; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/02works.t b/t/Module_Pluggable/02works.t new file mode 100644 index 0000000000..6c39452ac8 --- /dev/null +++ b/t/Module_Pluggable/02works.t @@ -0,0 +1,42 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 5; + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Foo MyTest::Plugin::Quux::Foo); +ok(@plugins = sort $foo->plugins); + + + +is_deeply(\@plugins, \@expected, "is deeply"); + +@plugins = (); + +ok(@plugins = sort MyTest->plugins); + + + + +is_deeply(\@plugins, \@expected, "is deeply class"); + + + +package MyTest; + +use strict; +use Module::Pluggable; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/02works_taint.t b/t/Module_Pluggable/02works_taint.t new file mode 100644 index 0000000000..0e1baa3dc0 --- /dev/null +++ b/t/Module_Pluggable/02works_taint.t @@ -0,0 +1,41 @@ +#!perl -wT + +# NOTE: Module::Pluggable is going into core +# and CORE tests can't modify @INC under taint +# so this is a work around to make sure it +# still works under taint checking. + +use strict; +use Test::More tests => 5; + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(Module::Pluggable::Object); +ok(@plugins = sort $foo->plugins); + + +ok(grep {/Module::Pluggable::Object/} @plugins, "Contains Module::Pluggable::Object"); + +@plugins = (); + +ok(@plugins = sort MyTest->plugins); + +ok(grep {/Module::Pluggable::Object/} @plugins, "Contains Module::Pluggable::Object under class method"); + + + +package MyTest; + +use strict; +use Module::Pluggable search_path => 'Module::Pluggable'; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/03diffname.t b/t/Module_Pluggable/03diffname.t new file mode 100644 index 0000000000..b4a881b6e8 --- /dev/null +++ b/t/Module_Pluggable/03diffname.t @@ -0,0 +1,30 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Foo MyTest::Plugin::Quux::Foo); +ok(@plugins = sort $foo->foo); +is_deeply(\@plugins, \@expected); + + + +package MyTest; + +use strict; +use Module::Pluggable ( sub_name => 'foo'); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/04acmedir.t b/t/Module_Pluggable/04acmedir.t new file mode 100644 index 0000000000..71544860b8 --- /dev/null +++ b/t/Module_Pluggable/04acmedir.t @@ -0,0 +1,30 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(Acme::MyTest::Plugin::Foo); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable search_path => ["Acme::MyTest::Plugin"], search_dirs => [ "t/acme" ]; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/04acmedir_single.t b/t/Module_Pluggable/04acmedir_single.t new file mode 100644 index 0000000000..e2abce9d4e --- /dev/null +++ b/t/Module_Pluggable/04acmedir_single.t @@ -0,0 +1,30 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(Acme::MyTest::Plugin::Foo); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable search_path => "Acme::MyTest::Plugin", search_dirs => "t/acme" ; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/04acmepath.t b/t/Module_Pluggable/04acmepath.t new file mode 100644 index 0000000000..bb1b88b7b8 --- /dev/null +++ b/t/Module_Pluggable/04acmepath.t @@ -0,0 +1,30 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(Acme::MyTest::Plugin::Foo); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable (search_path => ["Acme::MyTest::Plugin"]); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/04acmepath_single.t b/t/Module_Pluggable/04acmepath_single.t new file mode 100644 index 0000000000..bf02854c22 --- /dev/null +++ b/t/Module_Pluggable/04acmepath_single.t @@ -0,0 +1,30 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(Acme::MyTest::Plugin::Foo); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable search_path => "Acme::MyTest::Plugin"; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/05postpath.t b/t/Module_Pluggable/05postpath.t new file mode 100644 index 0000000000..be16010bbb --- /dev/null +++ b/t/Module_Pluggable/05postpath.t @@ -0,0 +1,31 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(MyTest::Extend::Plugin::Bar); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected); + + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable (search_path => ["MyTest::Extend::Plugin"]); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/06multipath.t b/t/Module_Pluggable/06multipath.t new file mode 100644 index 0000000000..4c9a16b589 --- /dev/null +++ b/t/Module_Pluggable/06multipath.t @@ -0,0 +1,33 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(Acme::MyTest::Plugin::Foo MyTest::Extend::Plugin::Bar); +ok(@plugins = sort $foo->plugins); + +is_deeply(\@plugins, \@expected); + + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use File::Spec::Functions qw(catdir); +use Module::Pluggable (search_path => ["MyTest::Extend::Plugin", "Acme::MyTest::Plugin"]); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/07instantiate.t b/t/Module_Pluggable/07instantiate.t new file mode 100644 index 0000000000..befc15a819 --- /dev/null +++ b/t/Module_Pluggable/07instantiate.t @@ -0,0 +1,40 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 6; + +my $foo; +ok($foo = MyTest->new()); + + + +my @plugins; +ok(@plugins = sort $foo->booga(nork => 'fark')); +is(ref $plugins[0],'MyTest::Extend::Plugin::Bar'); +is($plugins[0]->nork,'fark'); + + +@plugins = (); +eval { @plugins = $foo->wooga( nork => 'fark') }; +is($@, ''); +is(scalar(@plugins),0); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Module::Pluggable (search_path => ["MyTest::Extend::Plugin"], sub_name => 'booga', instantiate => 'new'); +use Module::Pluggable (search_path => ["MyTest::Extend::Plugin"], sub_name => 'wooga', instantiate => 'nosomuchmethod'); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/08nothing.t b/t/Module_Pluggable/08nothing.t new file mode 100644 index 0000000000..78d1007923 --- /dev/null +++ b/t/Module_Pluggable/08nothing.t @@ -0,0 +1,30 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 2; + + +my $foo; +ok($foo = MyTest->new()); + +my @expected = (); +my @plugins = sort $foo->plugins; +is_deeply(\@plugins, \@expected); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable (search_path => ["No::Such::Modules"]); +use base qw(Module::Pluggable); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/09require.t b/t/Module_Pluggable/09require.t new file mode 100644 index 0000000000..106e2c46df --- /dev/null +++ b/t/Module_Pluggable/09require.t @@ -0,0 +1,29 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 2; + +my $t = MyTest->new(); + + +ok($t->plugins()); + +ok(keys %{MyTest::Plugin::Foo::}); + + +package MyTest; +use File::Spec::Functions qw(catdir); +use strict; +use Module::Pluggable (require => 1); +use base qw(Module::Pluggable); + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/10innerpack.t b/t/Module_Pluggable/10innerpack.t new file mode 100644 index 0000000000..fc7a213052 --- /dev/null +++ b/t/Module_Pluggable/10innerpack.t @@ -0,0 +1,35 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 4; + + + +my $t = InnerTest->new(); + +my %plugins = map { $_ => 1 } $t->plugins; + +ok(keys %plugins, "Got some plugins"); +ok($plugins{'InnerTest::Plugin::Foo'}, "Got Foo"); +ok($plugins{'InnerTest::Plugin::Bar'}, "Got Bar - the inner package"); +ok($plugins{'InnerTest::Plugin::Quux'}, "Got Quux - the other inner package"); + + + +package InnerTest; +use strict; +use Module::Pluggable require => 1; +use base qw(Module::Pluggable); + + +sub new { + my $class = shift; + return bless {}, $class; + +} + + +1; + diff --git a/t/Module_Pluggable/10innerpack_inner.t b/t/Module_Pluggable/10innerpack_inner.t new file mode 100644 index 0000000000..55edcd9246 --- /dev/null +++ b/t/Module_Pluggable/10innerpack_inner.t @@ -0,0 +1,34 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + + +my $t = InnerTest->new(); + +my %plugins = map { $_ => 1 } $t->plugins; + +ok(keys %plugins, "Got some plugins"); +ok($plugins{'InnerTest::Plugin::Foo'}, "Got Foo"); +ok($plugins{'InnerTest::Plugin::Bar'}, "Got Bar - the inner package"); + + + +package InnerTest; +use strict; +use Module::Pluggable inner => 1; +use base qw(Module::Pluggable); + + +sub new { + my $class = shift; + return bless {}, $class; + +} + + +1; + diff --git a/t/Module_Pluggable/10innerpack_noinner.t b/t/Module_Pluggable/10innerpack_noinner.t new file mode 100644 index 0000000000..5d40cd5cff --- /dev/null +++ b/t/Module_Pluggable/10innerpack_noinner.t @@ -0,0 +1,34 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + + +my $t = InnerTest->new(); + +my %plugins = map { $_ => 1 } $t->plugins; + +ok(keys %plugins, "Got some plugins"); +ok($plugins{'InnerTest::Plugin::Foo'}, "Got Foo"); +ok(!$plugins{'InnerTest::Plugin::Bar'}, "Didn't get Bar - the inner package"); + + + +package InnerTest; +use strict; +use Module::Pluggable require => 1, inner => 0; +use base qw(Module::Pluggable); + + +sub new { + my $class = shift; + return bless {}, $class; + +} + + +1; + diff --git a/t/Module_Pluggable/10innerpack_override.t b/t/Module_Pluggable/10innerpack_override.t new file mode 100644 index 0000000000..039b845267 --- /dev/null +++ b/t/Module_Pluggable/10innerpack_override.t @@ -0,0 +1,34 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + + + +my $t = InnerTest->new(); + +my %plugins = map { $_ => 1 } $t->plugins; + +ok(keys %plugins, "Got some plugins"); +ok($plugins{'InnerTest::Plugin::Foo'}, "Got Foo"); +ok($plugins{'InnerTest::Plugin::Bar'}, "Got Bar - the inner package"); + + + +package InnerTest; +use strict; +use Module::Pluggable require => 0, inner => 1; +use base qw(Module::Pluggable); + + +sub new { + my $class = shift; + return bless {}, $class; + +} + + +1; + diff --git a/t/Module_Pluggable/11usetwice.t b/t/Module_Pluggable/11usetwice.t new file mode 100644 index 0000000000..0f6a1bae7a --- /dev/null +++ b/t/Module_Pluggable/11usetwice.t @@ -0,0 +1,44 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 3; + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(MyTest::Extend::Plugin::Bar MyTest::Plugin::Bar MyTest::Plugin::Foo MyTest::Plugin::Quux::Foo); + +push @plugins, $foo->plugins; +push @plugins, $foo->foo; + +@plugins = sort @plugins; +is_deeply(\@plugins, \@expected); + +@plugins = (); + +push @plugins, MyTest->plugins; +push @plugins, MyTest->foo; +@plugins = sort @plugins; +is_deeply(\@plugins, \@expected); + + + +package MyTest; + +use strict; +use Module::Pluggable; +use Module::Pluggable ( search_path => [ "MyTest::Extend::Plugin" ] , sub_name => 'foo' ); + + +sub new { + my $class = shift; + return bless {}, $class; + +} + + +1; + diff --git a/t/Module_Pluggable/12only.t b/t/Module_Pluggable/12only.t new file mode 100644 index 0000000000..6164c42ac9 --- /dev/null +++ b/t/Module_Pluggable/12only.t @@ -0,0 +1,64 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 10; + +{ + my $foo; + ok($foo = MyTest->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Foo); + ok(@plugins = sort $foo->plugins); + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTest->plugins); + is_deeply(\@plugins, \@expected); +} + +{ + my $foo; + ok($foo = MyTestSub->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Foo); + ok(@plugins = sort $foo->plugins); + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTestSub->plugins); + is_deeply(\@plugins, \@expected); +} + +package MyTest; + +use strict; +use Module::Pluggable only => "MyTest::Plugin::Foo"; + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +package MyTestSub; + +use strict; +use Module::Pluggable search_path => "MyTest::Plugin"; + + +sub new { + my $class = shift; + my $self = bless {}, $class; + + $self->only("MyTest::Plugin::Foo"); + + return $self; +} +1; diff --git a/t/Module_Pluggable/12onlyarray.t b/t/Module_Pluggable/12onlyarray.t new file mode 100644 index 0000000000..5ecc65435f --- /dev/null +++ b/t/Module_Pluggable/12onlyarray.t @@ -0,0 +1,65 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 10; + +{ + my $foo; + ok($foo = MyTest->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Foo); + ok(@plugins = sort $foo->plugins); + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTest->plugins); + is_deeply(\@plugins, \@expected); +} + +{ + my $foo; + ok($foo = MyTestSub->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Foo); + ok(@plugins = sort $foo->plugins); + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTestSub->plugins); + is_deeply(\@plugins, \@expected); +} + +package MyTest; + +use strict; +use Module::Pluggable only => [ "MyTest::Plugin::Foo" ]; + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +package MyTestSub; + +use strict; +use Module::Pluggable search_path => "MyTest::Plugin"; + + +sub new { + my $class = shift; + my $self = bless {}, $class; + + $self->only(["MyTest::Plugin::Foo"]); + + return $self; +} +1; + diff --git a/t/Module_Pluggable/12onlyregex.t b/t/Module_Pluggable/12onlyregex.t new file mode 100644 index 0000000000..eff6a16256 --- /dev/null +++ b/t/Module_Pluggable/12onlyregex.t @@ -0,0 +1,65 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 10; + +{ + my $foo; + ok($foo = MyTest->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Foo); + ok(@plugins = sort $foo->plugins); + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTest->plugins); + is_deeply(\@plugins, \@expected); +} + +{ + my $foo; + ok($foo = MyTestSub->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Foo); + ok(@plugins = sort $foo->plugins); + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTestSub->plugins); + is_deeply(\@plugins, \@expected); +} + +package MyTest; + +use strict; +use Module::Pluggable only => qr/MyTest::Plugin::Foo$/; + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +package MyTestSub; + +use strict; +use Module::Pluggable search_path => "MyTest::Plugin"; + + +sub new { + my $class = shift; + my $self = bless {}, $class; + + $self->only(qr/MyTest::Plugin::Foo$/); + + return $self; +} +1; + diff --git a/t/Module_Pluggable/13except.t b/t/Module_Pluggable/13except.t new file mode 100644 index 0000000000..0dbfb20392 --- /dev/null +++ b/t/Module_Pluggable/13except.t @@ -0,0 +1,68 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 10; + +{ + my $foo; + ok($foo = MyTest->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Quux::Foo); + ok(@plugins = sort $foo->plugins); + + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTest->plugins); + is_deeply(\@plugins, \@expected); +} + +{ + my $foo; + ok($foo = MyTestSub->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Quux::Foo); + ok(@plugins = sort $foo->plugins); + + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTestSub->plugins); + is_deeply(\@plugins, \@expected); +} + +package MyTest; + +use strict; +use Module::Pluggable except => "MyTest::Plugin::Foo"; + + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +package MyTestSub; + +use strict; +use Module::Pluggable search_path => "MyTest::Plugin"; + + +sub new { + my $class = shift; + my $self = bless {}, $class; + + $self->except("MyTest::Plugin::Foo"); + + return $self; +} +1; + diff --git a/t/Module_Pluggable/13exceptarray.t b/t/Module_Pluggable/13exceptarray.t new file mode 100644 index 0000000000..a6313bd12d --- /dev/null +++ b/t/Module_Pluggable/13exceptarray.t @@ -0,0 +1,68 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 10; + +{ + my $foo; + ok($foo = MyTest->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Quux::Foo); + ok(@plugins = sort $foo->plugins); + + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTest->plugins); + is_deeply(\@plugins, \@expected); +} + +{ + my $foo; + ok($foo = MyTestSub->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Quux::Foo); + ok(@plugins = sort $foo->plugins); + + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTestSub->plugins); + is_deeply(\@plugins, \@expected); +} + +package MyTest; + +use strict; +use Module::Pluggable except => [ "MyTest::Plugin::Foo" ]; + + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +package MyTestSub; + +use strict; +use Module::Pluggable search_path => "MyTest::Plugin"; + + +sub new { + my $class = shift; + my $self = bless {}, $class; + + $self->except(["MyTest::Plugin::Foo"]); + + return $self; +} +1; + diff --git a/t/Module_Pluggable/13exceptregex.t b/t/Module_Pluggable/13exceptregex.t new file mode 100644 index 0000000000..e3f2638953 --- /dev/null +++ b/t/Module_Pluggable/13exceptregex.t @@ -0,0 +1,68 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 10; + +{ + my $foo; + ok($foo = MyTest->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Quux::Foo); + ok(@plugins = sort $foo->plugins); + + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTest->plugins); + is_deeply(\@plugins, \@expected); +} + +{ + my $foo; + ok($foo = MyTestSub->new()); + + my @plugins; + my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Quux::Foo); + ok(@plugins = sort $foo->plugins); + + is_deeply(\@plugins, \@expected); + + @plugins = (); + + ok(@plugins = sort MyTestSub->plugins); + is_deeply(\@plugins, \@expected); +} + +package MyTest; + +use strict; +use Module::Pluggable except => qr/MyTest::Plugin::Foo/; + + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +package MyTestSub; + +use strict; +use Module::Pluggable search_path => "MyTest::Plugin"; + + +sub new { + my $class = shift; + my $self = bless {}, $class; + + $self->except(qr/MyTest::Plugin::Foo/); + + return $self; +} +1; + diff --git a/t/Module_Pluggable/14package.t b/t/Module_Pluggable/14package.t new file mode 100644 index 0000000000..3ba56edaf9 --- /dev/null +++ b/t/Module_Pluggable/14package.t @@ -0,0 +1,34 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 5; + +my $foo; +ok($foo = MyTest->new()); + +my @plugins; +my @expected = qw(MyTest::Plugin::Bar MyTest::Plugin::Foo MyTest::Plugin::Quux::Foo); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected); + +@plugins = (); + +ok(@plugins = sort MyTest->plugins); +is_deeply(\@plugins, \@expected); + + + +package MyTest; +use strict; +sub new { return bless {}, $_[0] } + +package MyOtherTest; +use strict; +use Module::Pluggable ( package => "MyTest" ); +sub new { return bless {}, $_[0] } + + +1; + diff --git a/t/Module_Pluggable/15topicsafe.t b/t/Module_Pluggable/15topicsafe.t new file mode 100644 index 0000000000..abc980fcc9 --- /dev/null +++ b/t/Module_Pluggable/15topicsafe.t @@ -0,0 +1,16 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More 'no_plan'; + +use Module::Pluggable search_path => 'Acme::MyTest'; + +my $topic = "topic"; + +for ($topic) { + main->plugins; +} + +is($topic, 'topic', "we've got the right topic"); diff --git a/t/Module_Pluggable/16different_extension.t b/t/Module_Pluggable/16different_extension.t new file mode 100644 index 0000000000..3f1a4da10c --- /dev/null +++ b/t/Module_Pluggable/16different_extension.t @@ -0,0 +1,42 @@ +#!perl -w + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 5; + +my $foo; +ok($foo = ExtTest->new()); + +my @plugins; +my @expected = qw(ExtTest::Plugin::Bar ExtTest::Plugin::Foo ExtTest::Plugin::Quux::Foo); +ok(@plugins = sort $foo->plugins); + + + +is_deeply(\@plugins, \@expected, "is deeply"); + +@plugins = (); + +ok(@plugins = sort ExtTest->plugins); + + + + +is_deeply(\@plugins, \@expected, "is deeply class"); + + + +package ExtTest; + +use strict; +use Module::Pluggable file_regex => qr/\.plugin$/; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + diff --git a/t/Module_Pluggable/17devel_inner_package.t b/t/Module_Pluggable/17devel_inner_package.t new file mode 100644 index 0000000000..5fabdbfa08 --- /dev/null +++ b/t/Module_Pluggable/17devel_inner_package.t @@ -0,0 +1,15 @@ +#!perl -w +use Test::More tests => 3; + +use Devel::InnerPackage qw(list_packages); +use FindBin; +use lib "$FindBin::Bin/lib"; + +my @packages; + +use_ok("TA::C::A::I"); +ok(@packages = list_packages("TA::C::A::I")); + +is_deeply([sort @packages], [qw(TA::C::A::I::A TA::C::A::I::A::B)]); + + diff --git a/t/Module_Pluggable/18skipped_package.t b/t/Module_Pluggable/18skipped_package.t new file mode 100644 index 0000000000..39917720e4 --- /dev/null +++ b/t/Module_Pluggable/18skipped_package.t @@ -0,0 +1,11 @@ +#!perl -w + +use Test::More tests => 1; +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Devel::InnerPackage qw(list_packages); +use No::Middle; + +my @p = list_packages("No::Middle"); +is_deeply([ sort @p ], [ qw(No::Middle::Package::A No::Middle::Package::B) ]); diff --git a/t/Module_Pluggable/19can_ok_clobber.t b/t/Module_Pluggable/19can_ok_clobber.t new file mode 100644 index 0000000000..78b03cbbe7 --- /dev/null +++ b/t/Module_Pluggable/19can_ok_clobber.t @@ -0,0 +1,50 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Data::Dumper; +use FindBin; +use lib "$FindBin::Bin/lib"; + +use Test::More tests=>5; + +#use_ok( 'MyTest' ); +#diag "Module::Pluggable::VERSION $Module::Pluggable::VERSION"; + +my @plugins = MyTest->plugins; +my @plugins_after; + +use_ok( 'MyTest::Plugin::Foo' ); +ok( my $foo = MyTest::Plugin::Foo->new() ); + +@plugins_after = MyTest->plugins; +is_deeply( + \@plugins_after, + \@plugins, + "plugins haven't been clobbered", +); + +can_ok ($foo, 'frobnitz'); + +@plugins_after = MyTest->plugins; +is_deeply( + \@plugins_after, + \@plugins, + "plugins haven't been clobbered", +) or diag Dumper ; + + + +package MyTest; + +use strict; +use Module::Pluggable; + + +sub new { + my $class = shift; + return bless {}, $class; + +} +1; + + diff --git a/t/Module_Pluggable/20dodgy_files.t b/t/Module_Pluggable/20dodgy_files.t new file mode 100644 index 0000000000..2486402b53 --- /dev/null +++ b/t/Module_Pluggable/20dodgy_files.t @@ -0,0 +1,74 @@ +#!perl -w + +BEGIN { + if ($^O eq 'VMS') { + print "1..0 # Skip: can't handle misspelled plugin names\n"; + exit; + } +} + +use strict; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Test::More tests => 5; + +my $foo; +ok($foo = OddTest->new()); + +my @plugins; +my @expected = ('OddTest::Plugin::-Dodgy', 'OddTest::Plugin::Foo'); +ok(@plugins = sort $foo->plugins); +is_deeply(\@plugins, \@expected, "is deeply"); + +my @odd_plugins; +my @odd_expected = qw(OddTest::Plugin::Foo); +ok(@odd_plugins = sort $foo->odd_plugins); +is_deeply(\@odd_plugins, \@odd_expected, "is deeply"); + + +package OddTest::Pluggable; + +use Data::Dumper; +use base qw(Module::Pluggable::Object); + + +sub find_files { + my $self = shift; + my @files = $self->SUPER::find_files(@_); + return grep { !/(^|\/)-/ } $self->SUPER::find_files(@_) ; +} + +package OddTest; + +use strict; +use Module::Pluggable; + + +sub new { + my $class = shift; + return bless {}, $class; + +} + +sub odd_plugins { + my $self = shift; + my %opts; + my ($pkg, $file) = caller; + # the default name for the method is 'plugins' + my $sub = $opts{'sub_name'} || 'plugins'; + # get our package + my ($package) = $opts{'package'} || "OddTest"; + $opts{filename} = $file; + $opts{package} = $package; + + + + my $op = OddTest::Pluggable->new( package => ref($self) ); + return $op->plugins(@_); + + +} + + +1; + diff --git a/t/Module_Pluggable/acme/Acme/MyTest/Plugin/Foo.pm b/t/Module_Pluggable/acme/Acme/MyTest/Plugin/Foo.pm new file mode 100644 index 0000000000..29c888baf7 --- /dev/null +++ b/t/Module_Pluggable/acme/Acme/MyTest/Plugin/Foo.pm @@ -0,0 +1,9 @@ +package Acme::MyTest::Plugin::Foo; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/Acme/MyTest/Plugin/Foo.pm b/t/Module_Pluggable/lib/Acme/MyTest/Plugin/Foo.pm new file mode 100644 index 0000000000..29c888baf7 --- /dev/null +++ b/t/Module_Pluggable/lib/Acme/MyTest/Plugin/Foo.pm @@ -0,0 +1,9 @@ +package Acme::MyTest::Plugin::Foo; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/ExtTest/Plugin/Bar.plugin b/t/Module_Pluggable/lib/ExtTest/Plugin/Bar.plugin new file mode 100644 index 0000000000..2f9b6db0b0 --- /dev/null +++ b/t/Module_Pluggable/lib/ExtTest/Plugin/Bar.plugin @@ -0,0 +1,9 @@ +package MyTest::Plugin::Bar; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/ExtTest/Plugin/Foo.plugin b/t/Module_Pluggable/lib/ExtTest/Plugin/Foo.plugin new file mode 100644 index 0000000000..5386ba5b80 --- /dev/null +++ b/t/Module_Pluggable/lib/ExtTest/Plugin/Foo.plugin @@ -0,0 +1,9 @@ +package MyTest::Plugin::Foo; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/ExtTest/Plugin/Quux/Foo.plugin b/t/Module_Pluggable/lib/ExtTest/Plugin/Quux/Foo.plugin new file mode 100644 index 0000000000..bb6e08667b --- /dev/null +++ b/t/Module_Pluggable/lib/ExtTest/Plugin/Quux/Foo.plugin @@ -0,0 +1,9 @@ +package MyTest::Plugin::Quux::Foo; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/InnerTest/Plugin/Foo.pm b/t/Module_Pluggable/lib/InnerTest/Plugin/Foo.pm new file mode 100644 index 0000000000..4f5825ea65 --- /dev/null +++ b/t/Module_Pluggable/lib/InnerTest/Plugin/Foo.pm @@ -0,0 +1,17 @@ +package InnerTest::Plugin::Foo; +use strict; + +our $FOO = 1; + +package InnerTest::Plugin::Bar; +use strict; + +sub bar {} + +package InnerTest::Plugin::Quux; +use strict; +use base qw(InnerTest::Plugin::Bar); + + + +1; diff --git a/t/Module_Pluggable/lib/MyOtherTest/Plugin/Bar.pm b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Bar.pm new file mode 100644 index 0000000000..3c5d79dc9b --- /dev/null +++ b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Bar.pm @@ -0,0 +1,5 @@ +package MyOtherTest::Plugin::Bar; +use strict; +1; + + diff --git a/t/Module_Pluggable/lib/MyOtherTest/Plugin/Foo.pm b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Foo.pm new file mode 100644 index 0000000000..14825724b3 --- /dev/null +++ b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Foo.pm @@ -0,0 +1,5 @@ +package MyOtherTest::Plugin::Foo; +use strict; +1; + + diff --git a/t/Module_Pluggable/lib/MyOtherTest/Plugin/Quux.pm b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Quux.pm new file mode 100644 index 0000000000..22fd55d3b9 --- /dev/null +++ b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Quux.pm @@ -0,0 +1,5 @@ +package MyOtherTest::Plugin::Quux; +use strict; +1; + + diff --git a/t/Module_Pluggable/lib/MyOtherTest/Plugin/Quux/Foo.pm b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Quux/Foo.pm new file mode 100644 index 0000000000..a8ecd69f11 --- /dev/null +++ b/t/Module_Pluggable/lib/MyOtherTest/Plugin/Quux/Foo.pm @@ -0,0 +1,5 @@ +package MyOtherTest::Plugin::Quux::Foo; +use strict; +1; + + diff --git a/t/Module_Pluggable/lib/MyTest/Extend/Plugin/Bar.pm b/t/Module_Pluggable/lib/MyTest/Extend/Plugin/Bar.pm new file mode 100644 index 0000000000..6d112cf39f --- /dev/null +++ b/t/Module_Pluggable/lib/MyTest/Extend/Plugin/Bar.pm @@ -0,0 +1,17 @@ +package MyTest::Extend::Plugin::Bar; +use strict; + +sub new { + my $class = shift; + my %self = @_; + + return bless \%self, $class; +} + + +sub nork { + return $_[0]->{'nork'}; +} +1; + + diff --git a/t/Module_Pluggable/lib/MyTest/Plugin/Bar.pm b/t/Module_Pluggable/lib/MyTest/Plugin/Bar.pm new file mode 100644 index 0000000000..2f9b6db0b0 --- /dev/null +++ b/t/Module_Pluggable/lib/MyTest/Plugin/Bar.pm @@ -0,0 +1,9 @@ +package MyTest::Plugin::Bar; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/MyTest/Plugin/Foo.pm b/t/Module_Pluggable/lib/MyTest/Plugin/Foo.pm new file mode 100644 index 0000000000..6ca8317507 --- /dev/null +++ b/t/Module_Pluggable/lib/MyTest/Plugin/Foo.pm @@ -0,0 +1,10 @@ +package MyTest::Plugin::Foo; + + +use strict; + +sub new { return bless {}, $_[0]; } +sub frobnitz {} +1; + + diff --git a/t/Module_Pluggable/lib/MyTest/Plugin/Quux/Foo.pm b/t/Module_Pluggable/lib/MyTest/Plugin/Quux/Foo.pm new file mode 100644 index 0000000000..bb6e08667b --- /dev/null +++ b/t/Module_Pluggable/lib/MyTest/Plugin/Quux/Foo.pm @@ -0,0 +1,9 @@ +package MyTest::Plugin::Quux::Foo; + + +use strict; + + +1; + + diff --git a/t/Module_Pluggable/lib/No/Middle.pm b/t/Module_Pluggable/lib/No/Middle.pm new file mode 100644 index 0000000000..9d0e31ac12 --- /dev/null +++ b/t/Module_Pluggable/lib/No/Middle.pm @@ -0,0 +1,14 @@ +package No::Middle; + +sub foo {} + +package No::Middle::Package::A; + +sub foo {} + + +package No::Middle::Package::B; + +sub foo {} + +1; diff --git a/t/Module_Pluggable/lib/OddTest/Plugin/-Dodgy.pm b/t/Module_Pluggable/lib/OddTest/Plugin/-Dodgy.pm new file mode 100644 index 0000000000..326e867f2e --- /dev/null +++ b/t/Module_Pluggable/lib/OddTest/Plugin/-Dodgy.pm @@ -0,0 +1,5 @@ +package OddFiles::Plugin::Dodgy; + +sub new {} + +1; diff --git a/t/Module_Pluggable/lib/OddTest/Plugin/Foo.pm b/t/Module_Pluggable/lib/OddTest/Plugin/Foo.pm new file mode 100644 index 0000000000..bcf37e34bf --- /dev/null +++ b/t/Module_Pluggable/lib/OddTest/Plugin/Foo.pm @@ -0,0 +1,5 @@ +package OddFiles/Plugin/Foo.pm + +sub new {} + +1; diff --git a/t/Module_Pluggable/lib/TA/C/A/I.pm b/t/Module_Pluggable/lib/TA/C/A/I.pm new file mode 100644 index 0000000000..35575dfdde --- /dev/null +++ b/t/Module_Pluggable/lib/TA/C/A/I.pm @@ -0,0 +1,13 @@ +package TA::C::A::I; + +sub foo { } + +package TA::C::A::I::A; + +sub foo { } + +package TA::C::A::I::A::B; + +sub foo { } + +1; |