DBIC/Resource/JSONAPI/Role/Item.pm

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 96.4% 27 / 28 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
__ANON__
1.0
to_json_as_jsonapi
1.0
CRAP 1.0
« DBIC/Resource/ActiveModel/Role/Item.pm ↑ Summary DBIC/Resource/GenericCore.pm »
1 package WebAPI::DBIC::Resource::JSONAPI::Role::Item;
2 25 $WebAPI::DBIC::Resource::JSONAPI::Role::Item::VERSION = '0.004002';
3  
4 25 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 25 requires '_build_content_types_provided';
8 25 requires 'render_item_as_jsonapi_hash';
9 25 requires 'encode_json';
10 25 requires 'item';
11  
12  
13 67 ▶around '_build_content_types_provided' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
14 67 my $orig = shift;
15 67 my $self = shift;
16 67 my $types = $self->$orig();
17 67 unshift @$types, { 'application/vnd.api+json' => 'to_json_as_jsonapi' };
18 67 return $types;
19 25 };
20  
21 #sub to_json_as_jsonapi { return $_[0]->encode_json($_[0]->render_item_as_jsonapi_hash($_[0]->item)) }
22 10 ▶sub to_json_as_jsonapi {
Subroutine to_json_as_jsonapi: called CC=1 SCAR=0.0
Pod undocumented
23 10 my $self = shift;
24  
25 # narrow the set to just contain the specified item
26 # XXX this narrowing ought to be moved elsewhere
27 # it's a bad idea to be a side effect of to_json_as_jsonapi
28 10 my @id_cols = $self->set->result_source->unique_constraint_columns( $self->id_unique_constraint_name );
29 10 @id_cols = map { $self->set->current_source_alias.".$_" } @id_cols;
30 10 my %id_search; @id_search{ @id_cols } = @{ $self->id };
31 10 $self->set( $self->set->search_rs(\%id_search) ); # narrow the set
32  
33 # set has been narrowed to the item, so we can render the item as if a set
34 # (which is what we need to do for JSON API, which doesn't really have an 'item')
35  
36 10 return $self->encode_json( $self->render_jsonapi_response() );
37 }
38  
39 25 1;
40  
41 __END__
« DBIC/Resource/ActiveModel/Role/Item.pm ↑ Summary DBIC/Resource/GenericCore.pm »