more tests, a missing file, bug fix 0.0005
Guillermo Roditi [Sat, 14 Apr 2007 20:43:12 +0000 (20:43 +0000)]
Changes
MANIFEST
lib/MooseX/Object/Pluggable.pm
t/03-custom-ns.t [new file with mode: 0644]
t/lib/CustomNS/Plugin/Foo.pm [new file with mode: 0644]
t/lib/CustomNS/Plugin/Foo/ExtensionFor/Bar.pm [new file with mode: 0644]
t/lib/CustomNS/Plugin/Foo/ExtensionFor/Baz.pm [new file with mode: 0644]
t/lib/TestApp2.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 5bf16c8..a77ba34 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@ Revision history for MooseX-Object-Pluggable
           Goodbye Class::Inspector, hello Module::Object::Pluggable
           More Tests
          App namespaces functionality.
+          Test for app namespaces functionality
 0.0004    Jan 23, 2007
          PODFixes
 0.0003    Jan 19, 2007
index 6761dbf..f5d0b0e 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -18,7 +18,11 @@ README
 t/00-load.t
 t/01-basic.t
 t/02-basic2.t
+t/03-custom-ns.t
 t/boilerplate.t
+t/lib/CustomNS/Plugin/Foo.pm
+t/lib/CustomNS/Plugin/Foo/ExtensionFor/Bar.pm
+t/lib/CustomNS/Plugin/Foo/ExtensionFor/Baz.pm
 t/lib/TestApp.pm
 t/lib/TestApp/Plugin/Bar.pm
 t/lib/TestApp/Plugin/Baz.pm
index f4d6013..fc62d80 100644 (file)
@@ -123,10 +123,15 @@ has _plugin_loaded  => (is => 'rw', required => 1, isa => 'HashRef',
                        default => sub{ {} });
 has _plugin_app_ns  => (is => 'rw', required => 1, isa => 'ArrayRef', lazy => 1, 
                         auto_deref => 1, 
-                        default => sub{ shift->_build_plugin_app_ns });
+                        default => sub{ shift->_build_plugin_app_ns },
+                        trigger => sub{ $_[0]->_clear_plugin_locator 
+                                         if $_[0]->_has_plugin_locator; },
+                       );
 has _plugin_locator => (is => 'rw', required => 1, lazy => 1, 
-                        isa => 'Module::Pluggable::Object', 
-                       default => sub{ shift->_build_plugin_locator });
+                        isa       => 'Module::Pluggable::Object', 
+                       clearer   => '_clear_plugin_locator',
+                        predicate => '_has_plugin_locator',
+                        default   => sub{ shift->_build_plugin_locator });
 
 #--------#---------#---------#---------#---------#---------#---------#---------#
 
@@ -234,9 +239,8 @@ sub _role_from_plugin{
     die("Unable to locate plugin") unless @roles;
     return $roles[0] if @roles == 1;
     
-    my @names = (grep {$_ !~ /^Moose::/} $self->meta->class_precedence_list);
     my $i = 0;
-    my %presedence_list = map{ $i++; "${_}::${o}", $i } @names;
+    my %presedence_list = map{ $i++; "${_}::${o}", $i } $self->_plugin_app_ns;
     
     @roles = sort{ $presedence_list{$a} <=> $presedence_list{$b}} @roles;
 
diff --git a/t/03-custom-ns.t b/t/03-custom-ns.t
new file mode 100644 (file)
index 0000000..5e4272f
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use lib 't/lib';
+
+plan tests => 22;
+
+use_ok('TestApp2');
+
+my $app = TestApp2->new;
+
+is($app->_role_from_plugin('+'.$_), $_)
+    for(qw/MyPrettyPlugin My::Pretty::Plugin/);
+
+is($app->_role_from_plugin($_), 'TestApp2::Plugin::'.$_)
+    for(qw/Foo/);
+
+is($app->_role_from_plugin($_), 'TestApp::Plugin::'.$_)
+    for(qw/Bar/);
+
+$app->_plugin_app_ns(['CustomNS', $app->_plugin_app_ns]);
+
+is($app->_role_from_plugin($_), 'CustomNS::Plugin::'.$_)
+    for(qw/Foo/);
+
+is($app->_role_from_plugin($_), 'TestApp::Plugin::'.$_)
+    for(qw/Bar/);
+
+is( $app->foo, "original foo", 'original foo value');
+is( $app->bar, "original bar", 'original bar value');
+is( $app->bor, "original bor", 'original bor value');
+
+ok($app->load_plugin('Bar'), "Loaded Bar");
+is( $app->bar, "override bar", 'overridden bar via plugin');
+
+ok($app->load_plugin('Baz'), "Loaded Baz");
+is( $app->baz, "plugin baz", 'added baz via plugin');
+is( $app->bar, "baz'd bar  override bar", 'baz extension for bar using around');
+
+ok($app->load_plugin('Foo'), "Loaded Foo");
+is( $app->foo, "around foo CNS", 'around foo via plugin');
+is( $app->bar, "foo'd bar CNS baz'd bar  override bar", 'foo extension around baz extension for bar');
+is( $app->baz, "foo'd baz CNS plugin baz", 'foo extension override for baz');
+
+ok($app->load_plugin('+TestApp::Plugin::Bor'), "Loaded Bor");
+is( $app->foo, "bor'd foo  around foo CNS", 'bor extension override for foo');
+is( $app->bor, "plugin bor", 'override bor via plugin');
diff --git a/t/lib/CustomNS/Plugin/Foo.pm b/t/lib/CustomNS/Plugin/Foo.pm
new file mode 100644 (file)
index 0000000..f38afb5
--- /dev/null
@@ -0,0 +1,9 @@
+package CustomNS::Plugin::Foo;
+
+use strict;
+use warnings;
+use Moose::Role;
+
+around foo => sub{ 'around foo CNS' };
+
+1;
diff --git a/t/lib/CustomNS/Plugin/Foo/ExtensionFor/Bar.pm b/t/lib/CustomNS/Plugin/Foo/ExtensionFor/Bar.pm
new file mode 100644 (file)
index 0000000..1c49561
--- /dev/null
@@ -0,0 +1,12 @@
+package CustomNS::Plugin::Foo::ExtensionFor::Bar;
+
+use strict;
+use warnings;
+use Moose::Role;
+
+around bar => sub {
+    my ($super, $self) = @_;
+    "foo'd bar CNS " . $super->($self);
+};
+
+1;
diff --git a/t/lib/CustomNS/Plugin/Foo/ExtensionFor/Baz.pm b/t/lib/CustomNS/Plugin/Foo/ExtensionFor/Baz.pm
new file mode 100644 (file)
index 0000000..aa14429
--- /dev/null
@@ -0,0 +1,13 @@
+package CustomNS::Plugin::Foo::ExtensionFor::Baz;
+
+use strict;
+use warnings;
+use Moose::Role;
+
+around baz => sub{ 
+    my $super = shift;
+    my $self = shift;
+    "foo'd baz CNS " . $super->($self);
+};
+
+1;
diff --git a/t/lib/TestApp2.pm b/t/lib/TestApp2.pm
new file mode 100644 (file)
index 0000000..8dec9ba
--- /dev/null
@@ -0,0 +1,10 @@
+package TestApp2;
+
+use strict;
+use warnings;
+use Moose;
+
+extends 'TestApp';
+
+
+1;