X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=744b62e6a357f23e039b0e23bcd4770c1ad98c88;hp=dc401c150430446398ff53c76ca772a190fe61f3;hb=a24232f92b5ad336245f57a3901df13b975f67af;hpb=80172e7dd3ee0325d38c0e9b10b379af529e5790 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index dc401c1..744b62e 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -127,7 +127,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90077'; +our $VERSION = '5.90079'; sub import { my ( $class, @arguments ) = @_; @@ -518,6 +518,9 @@ Add a new error. $c->error('Something bad happened'); +Calling this will always return an arrayref (if there are no errors it +will be an empty arrayref. + =cut sub error { @@ -562,6 +565,29 @@ Returns true if you have errors sub has_errors { scalar(@{shift->error}) ? 1:0 } +=head2 $c->last_error + +Returns the most recent error in the stack (the one most recently added...) +or nothing if there are no errors. + +=cut + +sub last_error { my ($err, @errs) = @{shift->error}; return $err } + +=head2 shift_errors + +shifts the most recently added error off the error stack and returns if. Returns +nothing if there are nomore errors. + +=cut + +sub shift_errors { + my ($self) = @_; + my ($err, @errors) = @{$self->error}; + $self->{error} = \@errors; + return $err; +} + sub _comp_search_prefixes { my $c = shift; return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_); @@ -3415,9 +3441,15 @@ sub default_data_handlers { ->can('build_cgi_struct')->($params); }, 'application/json' => sub { - Class::Load::load_first_existing_class('JSON::MaybeXS', 'JSON') - ->can('decode_json')->(do { local $/; $_->getline }); - }, + my ($fh, $req) = @_; + my $parser = Class::Load::load_first_existing_class('JSON::MaybeXS', 'JSON'); + my $slurped; + return eval { + local $/; + $slurped = $fh->getline; + $parser->can("decode_json")->($slurped); + } || Catalyst::Exception->throw(sprintf "Error Parsing POST '%s', Error: %s", (defined($slurped) ? $slurped : 'undef') ,$@); + }, }; } @@ -4190,7 +4222,7 @@ Upasana =head1 COPYRIGHT -Copyright (c) 2005-2014, the above named PROJECT FOUNDER and CONTRIBUTORS. +Copyright (c) 2005-2015, the above named PROJECT FOUNDER and CONTRIBUTORS. =head1 LICENSE