t/Module_Pluggable/10innerpack_inner.t Module::Pluggable tests
t/Module_Pluggable/10innerpack_noinner.t Module::Pluggable tests
t/Module_Pluggable/10innerpack_override.t Module::Pluggable tests
+t/Module_Pluggable/10innerpack_super.t Module::Pluggable tests
t/Module_Pluggable/10innerpack.t Module::Pluggable tests
t/Module_Pluggable/11usetwice.t Module::Pluggable tests
t/Module_Pluggable/12onlyarray.t Module::Pluggable tests
t/Module_Pluggable/18skipped_package.t Module::Pluggable tests
t/Module_Pluggable/19can_ok_clobber.t Module::Pluggable tests
t/Module_Pluggable/20dodgy_files.t Module::Pluggable tests
+t/Module_Pluggable/21editor_junk.t Module::Pluggable tests
t/Module_Pluggable/acme/Acme/MyTest/Plugin/Foo.pm Module::Pluggable tests
t/Module_Pluggable/lib/Acme/MyTest/Plugin/Foo.pm Module::Pluggable tests
+t/Module_Pluggable/lib/EditorJunk/Plugin/Foo.pm Module::Pluggable tests
+t/Module_Pluggable/lib/EditorJunk/Plugin/Bar.pm~ Module::Pluggable tests
+t/Module_Pluggable/lib/EditorJunk/Plugin/Bar.pm.swp Module::Pluggable tests
+t/Module_Pluggable/lib/EditorJunk/Plugin/Bar.pm Module::Pluggable tests
+t/Module_Pluggable/lib/EditorJunk/Plugin/Bar.pm.swo Module::Pluggable tests
t/Module_Pluggable/lib/ExtTest/Plugin/Bar.plugin Module::Pluggable tests
t/Module_Pluggable/lib/ExtTest/Plugin/Foo.plugin Module::Pluggable tests
t/Module_Pluggable/lib/ExtTest/Plugin/Quux/Foo.plugin Module::Pluggable tests
t/Module_Pluggable/lib/MyTest/Plugin/Foo.pm Module::Pluggable tests
t/Module_Pluggable/lib/MyTest/Plugin/Quux/Foo.pm Module::Pluggable tests
t/Module_Pluggable/lib/No/Middle.pm Module::Pluggable tests
-t/Module_Pluggable/lib/OddTest/Plugin/-Dodgy.pm Module::Pluggable tests
t/Module_Pluggable/lib/OddTest/Plugin/Foo.pm Module::Pluggable tests
t/Module_Pluggable/lib/TA/C/A/I.pm Module::Pluggable tests
t/mro/basic_01_c3.t mro tests
+# Note: this file was auto-generated by Module::Build::Compat version 0.03
use ExtUtils::MakeMaker;
+use FindBin;
+use File::Spec::Functions qw(catfile);
+
+# VOS and VMS can't handle dodgy plugin names
+# and VOS can't even unpack them so we create them on the
+# fly and only run the tests if they're present
+my %dodgy_files = (
+ catfile(qw(OddTest Plugin -Dodgy.pm)) => 'OddTest::Plugin::-Dodgy',
+ catfile(qw(EditorJunk Plugin #Bar.pm#)) => 'EditorJunk::Bar',
+ catfile(qw(EditorJunk Plugin .#Bar.pm)) => 'EditorJunk::Bar',
+);
+
+my $core = grep { $_ eq 'PERL_CORE=1' } @ARGV;
+my @path = $core ? (File::Spec->updir, File::Spec->updir, File::Spec->updir,
+ "t", "Module_Pluggable") : ($FindBin::Bin,"t");
+my @files;
+
+if ($^O ne 'VMS' && $^O ne 'VOS') {
+ foreach my $test (keys %dodgy_files) {
+ my ($file) = (catfile(@path, "lib", $test)=~/^(.*)$/);
+ if (open(my $fh, ">", $file)) {
+ my $name = $dodgy_files{$test};
+ print $fh "package $name;\nsub new {}\n1;";
+ close($fh);
+ push @files, $file;
+ }
+ }
+}
WriteMakefile
(
'NAME' => 'Module::Pluggable',
'VERSION_FROM' => 'lib/Module/Pluggable.pm',
- MAN3PODS => {}, # Pods will be built by installman.
'PREREQ_PM' => {
'File::Basename' => '0',
'File::Spec' => '3.00',
'Test::More' => '0.62'
},
+ 'INSTALLDIRS' => 'site',
'EXE_FILES' => [],
- 'PL_FILES' => {}
+ 'PL_FILES' => {},
+ 'realclean' => {FILES=> join ' ', @files},
+ # In the core pods will be built by installman.
+ $core ? (MAN3PODS => {}) : (),
)
;
=head1 SYNOPSIS
use Foo::Bar;
- use Devel::innerPackage qw(list_packages);
+ use Devel::InnerPackage qw(list_packages);
my @inner_packages = list_packages('Foo::Bar');
!__PACKAGE__->_loaded($pack.$cand); # or @children;
push @packs, @children;
}
- return grep {$_ !~ /::::ISA::CACHE/} @packs;
+ return grep {$_ !~ /::(::ISA::CACHE|SUPER)/} @packs;
}
### XXX this is an inlining of the Class-Inspector->loaded()
# Peter Gibbons: I wouldn't say I've been missing it, Bob!
-$VERSION = '3.6';
+$VERSION = '3.7';
sub import {
my $class = shift;
no strict 'refs';
- no warnings 'redefine';
- *{"$package\::$sub"} = $subroutine;
+ no warnings qw(redefine prototype);
+
+ *{"$package\::$sub"} = $subroutine;
*{"$package\::search_path"} = $searchsub;
*{"$package\::only"} = $onlysub;
*{"$package\::except"} = $exceptsub;
file_regex => qr/\.plugin$/
+=head2 include_editor_junk
+
+By default C<Module::Pluggable> ignores files that look like they were
+left behind by editors. Currently this means files ending in F<~> (~),
+the extensions F<.swp> or F<.swo>, or files beginning with F<.#>.
+
+Setting C<include_editor_junk> changes C<Module::Pluggable> so it does
+not ignore any files it finds.
=head1 METHODs
}
+### Eugggh, this code smells
+### This is what happens when you keep adding patches
+### *sigh*
+
sub plugins {
my $self = shift;
# check to see if we're running under test
- my @SEARCHDIR = exists $INC{"blib.pm"} && $filename =~ m!(^|/)blib/! ? grep {/blib/} @INC : @INC;
+ my @SEARCHDIR = exists $INC{"blib.pm"} && defined $filename && $filename =~ m!(^|/)blib/! ? grep {/blib/} @INC : @INC;
# add any search_dir params
unshift @SEARCHDIR, @{$self->{'search_dirs'}} if defined $self->{'search_dirs'};
# parse the file to get the name
my ($name, $directory, $suffix) = fileparse($file, $file_regex);
+ next if (!$self->{include_editor_junk} && $self->_is_editor_junk($name));
+
$directory = abs2rel($directory, $sp);
# If we have a mixed-case package name, assume case has been preserved
return @plugins;
}
+sub _is_editor_junk {
+ my $self = shift;
+ my $name = shift;
+
+ # Emacs (and other Unix-y editors) leave temp files ending in a
+ # tilde as a backup.
+ return 1 if $name =~ /~$/;
+ # Emacs makes these files while a buffer is edited but not yet
+ # saved.
+ return 1 if $name =~ /^\.#/;
+ # Vim can leave these files behind if it crashes.
+ return 1 if $name =~ /\.sw[po]$/;
+
+ return 0;
+}
+
sub handle_finding_plugin {
my $self = shift;
my $plugin = shift;
Optionally it instantiates those classes for you.
+This object is wrapped by C<Module::Pluggable>. If you want to do something
+odd or add non-general special features you're probably best to wrap this
+and produce your own subclass.
+
+=head1 OPTIONS
+
+See the C<Module::Pluggable> docs.
+
=head1 AUTHOR
Simon Wistow <simon@thegestalt.org>
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 5;
my $foo;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 5;
my $foo;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
my $foo;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 6;
my $foo;
use File::Spec::Functions qw(catdir);
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+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');
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 2;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 2;
my $t = MyTest->new();
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 4;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
--- /dev/null
+#!perl -wT
+
+use Test::More tests => 3;
+use strict;
+use_ok('Devel::InnerPackage');
+Bar->whee;
+is_deeply([Devel::InnerPackage::list_packages("Bar")],[], "Don't pick up ::SUPER pseudo stash");
+is_deeply([Devel::InnerPackage::list_packages("Foo")],['Foo::Bar'], "Still pick up other inner package");
+
+package Foo;
+
+sub whee {
+ 1;
+}
+
+package Foo::Bar;
+
+sub whee {}
+
+package Bar;
+use base 'Foo';
+
+sub whee {
+ shift->SUPER::whee;
+ 2;
+}
+
+
+1;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 3;
my $foo;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 10;
{
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 10;
{
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 10;
{
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 10;
{
-#!perl -w
+#!perl -wT
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 10;
{
-#!perl -w
+#!perl -wT
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 10;
{
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 5;
my $foo;
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More 'no_plan';
use Module::Pluggable search_path => 'Acme::MyTest';
use strict;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests => 5;
my $foo;
use Devel::InnerPackage qw(list_packages);
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
my @packages;
use Test::More tests => 1;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Devel::InnerPackage qw(list_packages);
use No::Middle;
use warnings;
use Data::Dumper;
use FindBin;
-use lib "$FindBin::Bin/lib";
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
use Test::More tests=>5;
#!perl -w
BEGIN {
- if ($^O eq 'VMS') {
+ if ($^O eq 'VMS' || $^O eq 'VOS') {
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;
+use Test::More;
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
+use File::Spec::Functions qw(catfile);
+
+
+my ($dodgy_file) = (catfile($FindBin::Bin, "lib", "OddTest", "Plugin", "-Dodgy.pm")=~/^(.*)$/);
+unless (-f $dodgy_file) {
+ plan skip_all => "Can't handle misspelled plugin names\n";
+} else {
+ plan tests => 5;
+}
+
my $foo;
ok($foo = OddTest->new());
--- /dev/null
+#!perl -w
+
+use Test::More;
+use FindBin;
+use lib (($FindBin::Bin."/lib")=~/^(.*)$/);
+use Module::Pluggable::Object;
+use File::Spec::Functions qw(catfile);
+
+my ($dodgy_file) = (catfile($FindBin::Bin,"lib", "EditorJunk", "Plugin", "#Bar.pm#")=~/^(.*)$/);
+unless (-f $dodgy_file) {
+ plan skip_all => "Can't handle plugin names with octothorpes\n";
+} else {
+ plan tests => 4;
+}
+
+
+
+my $foo;
+ok($foo = EditorJunk->new());
+
+my @plugins;
+my @expected = qw(EditorJunk::Plugin::Bar EditorJunk::Plugin::Foo);
+ok(@plugins = sort $foo->plugins);
+
+is_deeply(\@plugins, \@expected, "is deeply");
+
+
+my $mpo = Module::Pluggable::Object->new(
+ package => 'EditorJunk',
+ filename => __FILE__,
+ include_editor_junk => 1,
+);
+
+@expected = ('EditorJunk::Plugin::.#Bar', 'EditorJunk::Plugin::Bar', 'EditorJunk::Plugin::Foo');
+@plugins = sort $mpo->plugins();
+is_deeply(\@plugins, \@expected, "is deeply");
+
+
+
+package EditorJunk;
+
+use strict;
+use Module::Pluggable;
+
+
+sub new {
+ my $class = shift;
+ return bless {}, $class;
+
+}
+1;
+
+
--- /dev/null
+package EditorJunk::Bar;
+
+
+use strict;
+
+
+1;
+
+
--- /dev/null
+package EditorJunk::Bar;
+
+
+use strict;
+
+
+1;
+
+
--- /dev/null
+package EditorJunk::Bar;
+
+
+use strict;
+
+
+1;
+
+
--- /dev/null
+package EditorJunk::Bar;
+
+
+use strict;
+
+
+1;
+
+
--- /dev/null
+package EditorJunk::Foo;
+
+
+use strict;
+
+
+1;
+
+
+++ /dev/null
-package OddFiles::Plugin::Dodgy;
-
-sub new {}
-
-1;