X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=b85ac7f3e50e124540f2b81594942d0f56a98a2a;hp=3df8da8e3defd403c6b3e084a2dca5a30bf06e59;hb=80cdbbff8f7c6b6c341e367fc780d4982b1ee54e;hpb=189e2a51125327af68b68b3d3ab1c394d605c596 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 3df8da8..b85ac7f 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -38,14 +38,12 @@ our $DETACH = "catalyst_detach\n"; require Module::Pluggable::Fast; # Helper script generation -our $CATALYST_SCRIPT_GEN = 8; +our $CATALYST_SCRIPT_GEN = 10; __PACKAGE__->mk_classdata($_) for qw/components arguments dispatcher engine log/; -our $VERSION = '5.49_01'; - -sub version { return $Catalyst::VERSION } +our $VERSION = '5.49_02'; sub import { my ( $class, @arguments ) = @_; @@ -263,6 +261,23 @@ sub forward { my $c = shift; $c->dispatcher->forward( $c, @_ ) } Accessor to the namespace of the current action +=item $c->path_to(@path) + +Merges C<@path> with $c->config->{home} and returns a L object. + +For example: + + $c->path_to( 'db', 'sqlite.db' ); + +=cut + +sub path_to { + my ( $c, @path ) = @_; + my $path = dir( $c->config->{home}, @path ); + if ( -d $path ) { return $path } + else { return file( $c->config->{home}, @path ) } +} + =item $c->setup Setup. @@ -401,21 +416,24 @@ of the path. =cut sub uri_for { - my ( $c, $path , @args) = @_; + my ( $c, $path, @args ) = @_; my $base = $c->request->base->clone; my $basepath = $base->path; $basepath =~ s/\/$//; $basepath .= '/'; my $match = $c->request->match; + # massage match, empty if absolute path $match =~ s/^\///; $match .= '/' if $match; + $path ||= ''; $match = '' if $path =~ /^\//; $path =~ s/^\///; + # join args with '/', or a blank string - my $args=(scalar @args ? '/'.join('/',@args) : ''); - return URI->new_abs( URI->new_abs( "$path$args", "$basepath$match" ), $base ) - ->canonical; + my $args = ( scalar @args ? '/' . join( '/', @args ) : '' ); + return URI->new_abs( URI->new_abs( "$path$args", "$basepath$match" ), + $base )->canonical; } =item $c->error @@ -432,13 +450,20 @@ Add a new error. $c->error('Something bad happened'); +Clean errors. + + $c->error(0); + =cut sub error { my $c = shift; - my $error = ref $_[0] eq 'ARRAY' ? $_[0] : [@_]; - push @{ $c->{error} }, @$error; - return $c->{error}; + if ( $_[0] ) { + my $error = ref $_[0] eq 'ARRAY' ? $_[0] : [@_]; + push @{ $c->{error} }, @$error; + } + elsif ( defined $_[0] ) { $c->{error} = undef } + return $c->{error} || []; } =item $c->engine @@ -551,20 +576,24 @@ sub welcome_message { my $name = $c->config->{name}; my $logo = $c->uri_for('/static/images/catalyst_logo.png'); my $prefix = Catalyst::Utils::appprefix( ref $c ); + $c->response->content_type('text/html; charset=utf-8'); return <<"EOF"; - + + + + $name on Catalyst $VERSION