X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI.pm;fp=lib%2FCatalyst%2FController%2FDBIC%2FAPI.pm;h=fc929cb37f483d48c1c45326604ebae9b88c9980;hp=058e790e85e37f4c06535c5378a4af6f72877e6f;hb=a5949bfde189427d34ccd19f15d8656156454936;hpb=257cb2149dd762b4f5af045a7340197296e3e50a diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 058e790..fc929cb 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -6,7 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; } use CGI::Expand (); use DBIx::Class::ResultClass::HashRefInflator; -use JSON (); +use JSON::MaybeXS (); use Test::Deep::NoTest('eq_deeply'); use MooseX::Types::Moose(':all'); use Moose::Util; @@ -17,14 +17,14 @@ use namespace::autoclean; has '_json' => ( is => 'ro', - isa => 'JSON', + isa => JSON::MaybeXS::JSON(), lazy_build => 1, ); sub _build__json { # no ->utf8 here because the request params get decoded by Catalyst - return JSON->new; + return JSON::MaybeXS->new; } with 'Catalyst::Controller::DBIC::API::StoredResultSource', @@ -721,7 +721,7 @@ sub validate_object { } # check for multiple values - if ( ref($value) && !( reftype($value) eq reftype(JSON::true) ) ) + if ( ref($value) && !( reftype($value) eq reftype(JSON::MaybeXS::true) ) ) { require Data::Dumper; die @@ -815,7 +815,7 @@ sub update_object_from_params { foreach my $key ( keys %$params ) { my $value = $params->{$key}; - if ( ref($value) && !( reftype($value) eq reftype(JSON::true) ) ) { + if ( ref($value) && !( reftype($value) eq reftype(JSON::MaybeXS::true) ) ) { $self->update_object_relation( $c, $object, delete $params->{$key}, $key ); } @@ -850,7 +850,7 @@ sub update_object_relation { if ($row) { foreach my $key ( keys %$related_params ) { my $value = $related_params->{$key}; - if ( ref($value) && !( reftype($value) eq reftype(JSON::true) ) ) + if ( ref($value) && !( reftype($value) eq reftype(JSON::MaybeXS::true) ) ) { $self->update_object_relation( $c, $row, delete $related_params->{$key}, $key ); @@ -888,7 +888,7 @@ sub insert_object_from_params { my %rels; while ( my ( $key, $value ) = each %{$params} ) { - if ( ref($value) && !( reftype($value) eq reftype(JSON::true) ) ) { + if ( ref($value) && !( reftype($value) eq reftype(JSON::MaybeXS::true) ) ) { $rels{$key} = $value; } @@ -963,7 +963,7 @@ sub end : Private { if ( $c->res->status == 200 ) { $c->stash->{ $self->stash_key }->{success} = - $self->use_json_boolean ? JSON::true : 'true'; + $self->use_json_boolean ? JSON::MaybeXS::true : 'true'; if ( $self->return_object && $c->req->has_objects && ! exists $c->stash->{ $self->stash_key }->{ $self->data_root } ) { @@ -978,7 +978,7 @@ sub end : Private { } else { $c->stash->{ $self->stash_key }->{success} = - $self->use_json_boolean ? JSON::false : 'false'; + $self->use_json_boolean ? JSON::MaybeXS::false : 'false'; $c->stash->{ $self->stash_key }->{messages} = $self->get_errors($c) if $self->has_errors($c); @@ -1157,8 +1157,9 @@ $c->stash->{$self->stash_key}->{$self->item_root} and item_root default to =head3 use_json_boolean By default, the response success status is set to a string value of "true" or -"false". If this attribute is true, JSON's true() and false() will be used -instead. Note, this does not effect other internal processing of boolean values. +"false". If this attribute is true, JSON::MaybeXS's true() and false() will be +used instead. Note, this does not effect other internal processing of boolean +values. =head3 count_arg, page_arg, select_arg, search_arg, grouped_by_arg, ordered_by_arg, prefetch_arg, as_arg, total_entries_arg @@ -1318,9 +1319,10 @@ status quo. The internals were revamped to use more modern tools such as Moose and its role system to refactor functionality out into self-contained roles. To this end, internally, this module now understands JSON boolean values (as -represented by the JSON module) and will Do The Right Thing in handling those -values. This means you can have ColumnInflators installed that can covert -between JSON booleans and whatever your database wants for boolean values. +represented by the JSON::MaybeXS module) and will Do The Right Thing in +handling those values. This means you can have ColumnInflators installed that +can covert between JSON booleans and whatever your database wants for boolean +values. Validation for various *_allows or *_exposes is now accomplished via Data::DPath::Validator with a lightly simplified, via a subclass of