X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=8fe7043375a4765ff774b165ecbe94b0d975152c;hb=e7f1cf73b4e0e5863e901aaa0e6bda2e39bd0edc;hp=15e4a68118086600f2018e2e0e8eb3242aa8198f;hpb=37a3ac5c7c8a5b100365b570dd02fae770aab930;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 15e4a68..8fe7043 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -1,7 +1,6 @@ package Catalyst::Utils; use strict; -use attributes (); use Catalyst::Exception; use File::Spec; use HTTP::Request; @@ -22,13 +21,20 @@ See L. =over 4 -=item attrs($coderef) +=item appprefix($class) -Returns attributes for coderef in a arrayref +Returns the application prefix for the class. + + 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); @@ -83,7 +89,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 +133,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 +172,7 @@ sub home { { $home = $subdir; } + # clean up relative path: # MyApp/script/.. -> MyApp my ($lastdir) = $home->dir_list( -1, 1 ); @@ -192,37 +198,15 @@ sub prefix { return $name; } -=item reflect_actions($class); - -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); +=item request($request) -Returns an C 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 +214,9 @@ sub request { $request = URI->new( 'http://localhost' . $request )->canonical; } } - unless ( ref $request eq 'HTTP::Request' ) { $request = HTTP::Request->new( 'GET', $request ); } - return $request; }