From: Christian Hansen Date: Mon, 20 Jun 2005 08:40:02 +0000 (+0000) Subject: Added $req->cookie X-Git-Tag: 5.7099_04~1306 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=3ad654e0c538876403f3e664f0d9f302ef470770 Added $req->cookie --- diff --git a/lib/Catalyst/Log.pm b/lib/Catalyst/Log.pm index d9d03b8..26c2fef 100644 --- a/lib/Catalyst/Log.pm +++ b/lib/Catalyst/Log.pm @@ -8,7 +8,7 @@ our %LEVELS = (); __PACKAGE__->mk_accessors('level'); -{ +BEGIN { my @levels = qw[ debug info warn error fatal ]; for ( my $i = 0 ; $i < @levels ; $i++ ) { diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 1d7a4b8..fe05db7 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -117,6 +117,34 @@ Shortcut to $req->headers->content_length Shortcut to $req->headers->content_type +=item $req->cookie + +A convenient method to $req->cookies. + + $cookie = $c->request->cookie('name'); + @cookies = $c->request->cookie; + +=cut + +sub cookie { + my $self = shift; + + if ( @_ == 0 ) { + return keys %{ $self->cookie }; + } + + if ( @_ == 1 ) { + + my $name = shift; + + unless ( exists $self->cookie->{$name} ) { + return undef; + } + + return $self->cookie->{$name}; + } +} + =item $req->cookies Returns a reference to a hash containing the cookies. diff --git a/lib/Catalyst/Utils.pm b/lib/Catalyst/Utils.pm index c842231..98abdb1 100644 --- a/lib/Catalyst/Utils.pm +++ b/lib/Catalyst/Utils.pm @@ -80,6 +80,21 @@ sub class2classsuffix { return $class; } +=item class2env($class); + +Returns the enviroment name for class. + + MyApp becomes MYAPP + My::App becomes MY_APP + +=cut + +sub class2env { + my $class = shift || ''; + my $class =~ s/\:\:/_/g; + return uc($class); +} + =item class2prefix( $class, $case ); Returns the prefix for class.