X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=c4d9ca8d1a6a94509dca1db0c3668dffe995ed9b;hb=749472d6839708f3c04912c0ed39ce6141d4d500;hp=50fb0c3dd574664c5f6cc4314d6387a1322d448e;hpb=e494bd6b47c5dc60ca4b822825f5d73a93c9b4e6;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 50fb0c3..c4d9ca8 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -2,6 +2,8 @@ package Catalyst::Utils; use strict; use attributes (); +use Catalyst::Exception; +use File::Spec; use HTTP::Request; use Path::Class; use URI; @@ -79,6 +81,21 @@ sub class2classsuffix { return $class; } +=item class2env($class); + +Returns the environment name for class. + + MyApp becomes MYAPP + My::App becomes MY_APP + +=cut + +sub class2env { + my $class = shift || ''; + $class =~ s/\:\:/_/g; + return uc($class); +} + =item class2prefix( $class, $case ); Returns the prefix for class. @@ -98,6 +115,35 @@ sub class2prefix { return $prefix; } +=item class2tempdir( $class [, $create ] ); + +Returns a tempdir for 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 + +=cut + +sub class2tempdir { + my $class = shift || ''; + my $create = shift || 0; + my @parts = split '::', lc $class; + + my $tmpdir = dir( File::Spec->tmpdir, @parts )->cleanup; + + if ( $create && !-e $tmpdir ) { + + eval { $tmpdir->mkpath }; + + if ($@) { + Catalyst::Exception->throw( + message => qq/Couldn't create tmpdir '$tmpdir', "$@"/ ); + } + } + + return $tmpdir->stringify; +} + =item home($class) Returns home directory for given class. @@ -120,6 +166,7 @@ sub home { { $home = $subdir; } + # clean up relative path: # MyApp/script/.. -> MyApp my ($lastdir) = $home->dir_list( -1, 1 ); @@ -155,7 +202,12 @@ sub reflect_actions { my $class = shift; my $actions = []; eval '$actions = $class->_action_cache'; - die qq/Couldn't reflect actions of component "$class", "$@"/ if $@; + + if ($@) { + Catalyst::Exception->throw( message => + qq/Couldn't reflect actions of component "$class", "$@"/ ); + } + return $actions; }