use strict;
use attributes ();
+use Catalyst::Exception;
+use File::Spec;
use HTTP::Request;
use Path::Class;
use URI;
=over 4
+=item appprefix($class)
+
+Returns the application prefix for the class
+
+=cut
+
+sub appprefix {
+ my $class = shift;
+ $class =~ s/\:\:/_/g;
+ $class = lc($class);
+ return $class;
+}
+
=item attrs($coderef)
Returns attributes for coderef in a arrayref
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.
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.
{
$home = $subdir;
}
+
# clean up relative path:
# MyApp/script/.. -> MyApp
my ($lastdir) = $home->dir_list( -1, 1 );
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;
}
-=item request($string);
+=item request($request)
-Returns an C<HTTP::Request> from a string.
+Returns a HTTP::Request object.
=cut
sub request {
my $request = shift;
-
unless ( ref $request ) {
-
if ( $request =~ m/http/i ) {
$request = URI->new($request)->canonical;
}
$request = URI->new( 'http://localhost' . $request )->canonical;
}
}
-
unless ( ref $request eq 'HTTP::Request' ) {
$request = HTTP::Request->new( 'GET', $request );
}
-
return $request;
}