From: Tomas Doran Date: Sat, 2 Oct 2010 23:35:30 +0000 (+0100) Subject: Allow traits in external namespaces X-Git-Tag: 0.28~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=be50e6efef21894f1b09b9890e99eb75faffb89d;p=gitmo%2FMooseX-Storage.git Allow traits in external namespaces --- diff --git a/lib/MooseX/Storage/Basic.pm b/lib/MooseX/Storage/Basic.pm index 12eb936..b9a2960 100644 --- a/lib/MooseX/Storage/Basic.pm +++ b/lib/MooseX/Storage/Basic.pm @@ -2,6 +2,7 @@ package MooseX::Storage::Basic; use Moose::Role; use MooseX::Storage::Engine; +use String::RewritePrefix; our $VERSION = '0.27'; our $AUTHORITY = 'cpan:STEVAN'; @@ -25,20 +26,23 @@ sub unpack { sub _storage_get_engine_class { my ($self, %args) = @_; - my $default = 'MooseX::Storage::Engine'; - - return $default + return 'MooseX::Storage::Engine' unless ( exists $args{engine_traits} && ref($args{engine_traits}) eq 'ARRAY' && scalar(@{$args{engine_traits}}) ); - my @roles = map { sprintf("%s::Trait::%s", $default, $_) } - @{$args{engine_traits}}; + my @roles = String::RewritePrefix->rewrite( + { + '' => 'MooseX::Storage::Engine::Trait::', + '+' => '', + }, + @{$args{engine_traits}} + ); Moose::Meta::Class->create_anon_class( - superclasses => [$default], + superclasses => ['MooseX::Storage::Engine'], roles => [ @roles ], cache => 1, )->name;