package Catalyst::Utils;
use strict;
-use attributes ();
use Catalyst::Exception;
use File::Spec;
use HTTP::Request;
=over 4
-=item attrs($coderef)
+=item appprefix($class)
-Returns attributes for coderef in a arrayref
+ MyApp::Foo becomes myapp_foo
=cut
-sub attrs { attributes::get( $_[0] ) || [] }
+sub appprefix {
+ my $class = shift;
+ $class =~ s/\:\:/_/g;
+ $class = lc($class);
+ return $class;
+}
=item class2appclass($class);
-Returns the appclass for class.
-
MyApp::C::Foo::Bar becomes MyApp
My::App::C::Foo::Bar becomes My::App
=item class2classprefix($class);
-Returns the classprefix for class.
-
MyApp::C::Foo::Bar becomes MyApp::C
My::App::C::Foo::Bar becomes My::App::C
=item class2classsuffix($class);
-Returns the classsuffix for class.
-
MyApp::C::Foo::Bar becomes C::Foo::Bar
=cut
=item class2env($class);
-Returns the enviroment name for class.
+Returns the environment name for class.
MyApp becomes MYAPP
My::App becomes MY_APP
=item class2prefix( $class, $case );
-Returns the prefix for class.
+Returns the uri prefix for a class. If case is false the prefix is converted to lowercase.
- My::App::C::Foo::Bar becomes /foo/bar
+ My::App::C::Foo::Bar becomes foo/bar
=cut
=item class2tempdir( $class [, $create ] );
-Returns a tempdir for class. If create is true it will try to create the path.
+Returns a tempdir for a 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
Returns a prefixed action.
- MyApp::C::Foo::Bar, yada becomes /foo/bar/yada
+ MyApp::C::Foo::Bar, yada becomes foo/bar/yada
=cut
return $name;
}
-=item reflect_actions($class);
+=item request($uri)
-Returns an arrayref containing all actions of a component class.
-
-=cut
-
-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", "$@"/ );
- }
-
- return $actions;
-}
-
-=item request($string);
-
-Returns an C<HTTP::Request> from a string.
+Returns an L<HTTP::Request> object for a uri.
=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;
}