X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=d72441ea6951430a3d646e16697deb8225d3e798;hp=f47909d39fc8c874d61b971764fe5e6fcea08aff;hb=41a8bf1f4e417f1439866c09c08a3998ae81528a;hpb=b0ad47c12a21862b08d8e2942095065ac2f7edf2 diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index f47909d..d72441e 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -1,7 +1,6 @@ package Catalyst::Utils; use strict; -use Catalyst::Exception; use File::Spec; use HTTP::Request; use Path::Class; @@ -9,6 +8,8 @@ use URI; use Carp qw/croak/; use Cwd; +use String::RewritePrefix; + use namespace::clean; =head1 NAME @@ -122,7 +123,7 @@ sub class2prefix { Returns a tempdir for a class. If create is true it will try to create the path. My::App becomes /tmp/my/app - My::App::C::Foo::Bar becomes /tmp/my/app/c/foo/bar + My::App::Controller::Foo::Bar becomes /tmp/my/app/c/foo/bar =cut @@ -138,6 +139,13 @@ sub class2tempdir { eval { $tmpdir->mkpath }; if ($@) { + # don't load Catalyst::Exception as a BEGIN in Utils, + # because Utils often gets loaded before MyApp.pm, and if + # Catalyst::Exception is loaded before MyApp.pm, it does + # not honor setting + # $Catalyst::Exception::CATALYST_EXCEPTION_CLASS in + # MyApp.pm + require Catalyst::Exception; Catalyst::Exception->throw( message => qq/Couldn't create tmpdir '$tmpdir', "$@"/ ); } @@ -170,8 +178,9 @@ sub home { # pop off /lib and /blib if they're there $home = $home->parent while $home =~ /b?lib$/; - # only return the dir if it has a Makefile.PL or Build.PL - if (-f $home->file("Makefile.PL") or -f $home->file("Build.PL")) { + # only return the dir if it has a Makefile.PL or Build.PL or dist.ini + if (-f $home->file("Makefile.PL") or -f $home->file("Build.PL") + or -f $home->file("dist.ini")) { # clean up relative path: # MyApp/script/.. -> MyApp @@ -377,6 +386,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