Blob Blame History Raw
From 7872bc27ac7f828a6b53d00717abdf83f2d1866d Mon Sep 17 00:00:00 2001
From: Simon Wistow <simon@fastly.com>
Date: Tue, 22 Oct 2013 09:32:27 -0700
Subject: [PATCH] Allow single letter package names
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 lib/Module/Pluggable/Object.pm |  2 +-
 t/25single_letter_package.t    | 42 ++++++++++++++++++++++++++++++++++++++++++
 t/lib/M/X.pm                   |  7 +++++++
 3 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100755 t/25single_letter_package.t
 create mode 100644 t/lib/M/X.pm

diff --git a/lib/Module/Pluggable/Object.pm b/lib/Module/Pluggable/Object.pm
index 6f7a051..46240a8 100755
--- a/lib/Module/Pluggable/Object.pm
+++ b/lib/Module/Pluggable/Object.pm
@@ -234,7 +234,7 @@ sub search_paths {
             }
             my $plugin = join '::', $searchpath, @dirs, $name;
 
-            next unless $plugin =~ m!(?:[a-z\d]+)[a-z\d]!i;
+            next unless $plugin =~ m!(?:[a-z\d]+)[a-z\d]*!i;
 
             $self->handle_finding_plugin($plugin, \@plugins)
         }
diff --git a/t/25single_letter_package.t b/t/25single_letter_package.t
new file mode 100755
index 0000000..dd55fff
--- /dev/null
+++ b/t/25single_letter_package.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 = M->new());
+
+my @plugins;
+my @expected = qw(M::X);
+ok(@plugins = sort $foo->plugins);
+
+
+
+is_deeply(\@plugins, \@expected, "is deeply");
+
+@plugins = ();
+
+ok(@plugins = sort M->plugins);
+
+
+
+
+is_deeply(\@plugins, \@expected, "is deeply class");
+
+
+
+package M;
+
+use strict;
+use Module::Pluggable search_path => "M";
+
+
+sub new {
+    my $class = shift;
+    return bless {}, $class;
+
+}
+1;
+
diff --git a/t/lib/M/X.pm b/t/lib/M/X.pm
new file mode 100644
index 0000000..77f8f58
--- /dev/null
+++ b/t/lib/M/X.pm
@@ -0,0 +1,7 @@
+package M::X;
+
+use strict;
+
+sub new { return bless {}, $_[0]; }
+sub frobnitz {}
+1;
-- 
1.8.3.1