X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=22675a9fbd519d875ff29d4bbe3f06ca40525579;hb=db575fe81b23c74267b50495a881796f6cee7795;hp=f47909d39fc8c874d61b971764fe5e6fcea08aff;hpb=b0ad47c12a21862b08d8e2942095065ac2f7edf2;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index f47909d..22675a9 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -8,6 +8,8 @@ use Path::Class; use URI; use Carp qw/croak/; use Cwd; +use String::RewritePrefix; +use Moose::Util qw/find_meta/; use namespace::clean; @@ -47,6 +49,19 @@ sub appprefix { sub class2appclass { my $class = shift || ''; + + # Special move to deal with components which are anon classes. + # Specifically, CX::Component::Traits c072fb2 + my $meta = find_meta($class); + if ($meta) { + while ($meta->is_anon_class) { + my @superclasses = $meta->superclasses; + return if scalar(@superclasses) > 1; # Fail silently, MI, can't deal.. + $class = $superclasses[0]; + $meta = find_meta($class); + } + } + my $appname = ''; if ( $class =~ /^(.+?)::([MVC]|Model|View|Controller)::.+$/ ) { $appname = $1; @@ -377,6 +392,33 @@ sub term_width { return $_term_width = $width; } + +=head2 resolve_namespace + +Method which adds the namespace for plugins and actions. + + __PACKAGE__->setup(qw(MyPlugin)); + + # will load Catalyst::Plugin::MyPlugin + +=cut + + +sub resolve_namespace { + my $appnamespace = shift; + my $namespace = shift; + my @classes = @_; + return String::RewritePrefix->rewrite({ + q[] => qq[${namespace}::], + q[+] => q[], + (defined $appnamespace + ? (q[~] => qq[${appnamespace}::]) + : () + ), + }, @classes); +} + + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm