use strict;
use attributes ();
use Catalyst::Exception;
+use File::Spec;
use HTTP::Request;
use Path::Class;
use URI;
sub class2env {
my $class = shift || '';
- my $class =~ s/\:\:/_/g;
+ $class =~ s/\:\:/_/g;
return uc($class);
}
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.