X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=c4d9ca8d1a6a94509dca1db0c3668dffe995ed9b;hb=ab2374d3a68f4d44601813f351b38222822b7c39;hp=e329648d632882966bfee3479f0024e2a4ffa592;hpb=5d9a6d472d46896c9f878011e34485de7508c326;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index e329648..c4d9ca8 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -3,6 +3,7 @@ package Catalyst::Utils; use strict; use attributes (); use Catalyst::Exception; +use File::Spec; use HTTP::Request; use Path::Class; use URI; @@ -82,7 +83,7 @@ sub class2classsuffix { =item class2env($class); -Returns the enviroment name for class. +Returns the environment name for class. MyApp becomes MYAPP My::App becomes MY_APP @@ -114,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. @@ -136,6 +166,7 @@ sub home { { $home = $subdir; } + # clean up relative path: # MyApp/script/.. -> MyApp my ($lastdir) = $home->dir_list( -1, 1 ); @@ -171,13 +202,12 @@ sub reflect_actions { my $class = shift; my $actions = []; eval '$actions = $class->_action_cache'; - - if ( $@ ) { - Catalyst::Exception->throw( - message => qq/Couldn't reflect actions of component "$class", "$@"/ - ); + + if ($@) { + Catalyst::Exception->throw( message => + qq/Couldn't reflect actions of component "$class", "$@"/ ); } - + return $actions; }