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 });
#--------#---------#---------#---------#---------#---------#---------#---------#
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;
--- /dev/null
+#!/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');