X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=15e4a68118086600f2018e2e0e8eb3242aa8198f;hb=822fe9544767709e6d75eda2b0cbcfb46bb494dd;hp=98abdb1c1d6ecf4370e4c1452e4566e13adcc831;hpb=3ad654e0c538876403f3e664f0d9f302ef470770;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 98abdb1..15e4a68 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; @@ -91,7 +92,7 @@ Returns the enviroment name for class. sub class2env { my $class = shift || ''; - my $class =~ s/\:\:/_/g; + $class =~ s/\:\:/_/g; return uc($class); } @@ -114,6 +115,36 @@ 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.