X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FUtils.pm;h=0598f535bd7f9ad8f1a9f33c8a63cf253b0a7e5c;hp=456497f89404ccee0461e1aa7c4090c4e2e4f199;hb=85d9fce671016c9040775c8b4458cf9c72ec2208;hpb=0ef447d8c6880fa4dda2648aa19a005245ef036a diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index 456497f..0598f53 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -7,6 +7,7 @@ use HTTP::Request; use Path::Class; use URI; use Class::Inspector; +use Carp qw/croak/; =head1 NAME @@ -22,7 +23,7 @@ See L. =head2 appprefix($class) - MyApp::Foo becomes myapp_foo + MyApp::Foo becomes myapp_foo =cut @@ -220,10 +221,10 @@ sub request { my $request = shift; unless ( ref $request ) { if ( $request =~ m/^http/i ) { - $request = URI->new($request)->canonical; + $request = URI->new($request); } else { - $request = URI->new( 'http://localhost' . $request )->canonical; + $request = URI->new( 'http://localhost' . $request ); } } unless ( ref $request eq 'HTTP::Request' ) { @@ -242,6 +243,9 @@ sub ensure_class_loaded { my $class = shift; my $opts = shift; + croak "Malformed class Name $class" + if $class =~ m/(?:\b\:\b|\:{3,})/; + return if !$opts->{ ignore_loaded } && Class::Inspector->loaded( $class ); # if a symbol entry exists we don't load again @@ -288,6 +292,28 @@ sub merge_hashes { return \%merged; } +=head2 env_value($class, $key) + +Checks for and returns an environment value. For instance, if $key is +'home', then this method will check for and return the first value it finds, +looking at $ENV{MYAPP_HOME} and $ENV{CATALYST_HOME}. + +=cut + +sub env_value { + my ( $class, $key ) = @_; + + $key = uc($key); + my @prefixes = ( class2env($class), 'CATALYST' ); + + for my $prefix (@prefixes) { + if ( defined( my $value = $ENV{"${prefix}_${key}"} ) ) { + return $value; + } + } + + return; +} =head1 AUTHOR