Example for Catalyst::Utils::apprefix
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Utils.pm
index 15e4a68..c0eeefe 100644 (file)
@@ -22,6 +22,21 @@ See L<Catalyst>.
 
 =over 4
 
+=item appprefix($class)
+
+Returns the application prefix for the class.
+
+       MyApp::Foo becomes myapp_foo
+
+=cut
+
+sub appprefix {
+    my $class = shift;
+    $class =~ s/\:\:/_/g;
+    $class = lc($class);
+    return $class;
+}
+
 =item attrs($coderef)
 
 Returns attributes for coderef in a arrayref
@@ -83,7 +98,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
@@ -127,18 +142,17 @@ Returns a tempdir for class. If create is true it will try to create the path.
 sub class2tempdir {
     my $class  = shift || '';
     my $create = shift || 0;
-    my @parts  = split '::', lc $class;
+    my @parts = split '::', lc $class;
 
     my $tmpdir = dir( File::Spec->tmpdir, @parts )->cleanup;
 
-    if ( $create && ! -e $tmpdir ) {
+    if ( $create && !-e $tmpdir ) {
 
         eval { $tmpdir->mkpath };
 
-        if ( $@ ) {
+        if ($@) {
             Catalyst::Exception->throw(
-                message => qq/Couldn't create tmpdir '$tmpdir', "$@"/
-            );
+                message => qq/Couldn't create tmpdir '$tmpdir', "$@"/ );
         }
     }
 
@@ -167,6 +181,7 @@ sub home {
         {
             $home = $subdir;
         }
+
         # clean up relative path:
         # MyApp/script/.. -> MyApp
         my ($lastdir) = $home->dir_list( -1, 1 );
@@ -202,27 +217,24 @@ 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;
 }
 
-=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;
         }
@@ -230,11 +242,9 @@ sub request {
             $request = URI->new( 'http://localhost' . $request )->canonical;
         }
     }
-
     unless ( ref $request eq 'HTTP::Request' ) {
         $request = HTTP::Request->new( 'GET', $request );
     }
-
     return $request;
 }