| 1 | package Search::OpenSearch::Response::ExtJS; | ||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | extends 'Search::OpenSearch::Response::JSON'; | |||||||||||
| 5 | 2 | ▶ | use Types::Standard qw( HashRef Bool ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | ▶ | use JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 2 | ▶ | use Sort::SQL; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 2 | our $VERSION = '0.409'; | |||||||||||
| 10 | |||||||||||||
| 11 | 2 | has 'metaData' => ( is => 'rw', isa => HashRef ); | |||||||||||
| 12 | 2 | has 'success' => ( is => 'rw', isa => Bool ); | |||||||||||
| 13 | |||||||||||||
| 14 | 1 | ▶ | sub stringify { | ||||||||||
|
Subroutine
stringify: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||
| 15 | 1 | my $self = shift; | |||||||||||
| 16 | |||||||||||||
| 17 | 1 | my $resp = $self->as_hash; | |||||||||||
| 18 | |||||||||||||
| 19 | 1 | ▶ | if ( !defined $resp->{metaData} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | 1 | my $sort_info = delete $resp->{sort_info}; | |||||||||||
| 21 | 1 | ▶ | if ($sort_info) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 1 | my $sorted = Sort::SQL->parse($sort_info); | |||||||||||
| 23 | 1 | $sort_info = { | |||||||||||
| 24 | field => $sorted->[0]->[0], | ||||||||||||
| 25 | direction => $sorted->[0]->[1], | ||||||||||||
| 26 | }; | ||||||||||||
| 27 | } | ||||||||||||
| 28 | $resp->{metaData} = { | ||||||||||||
| 29 | idProperty => 'uri', | ||||||||||||
| 30 | root => 'results', | ||||||||||||
| 31 | totalProperty => 'total', | ||||||||||||
| 32 | successProperty => 'success', | ||||||||||||
| 33 | start => delete $resp->{offset}, | ||||||||||||
| 34 | limit => delete $resp->{page_size}, | ||||||||||||
| 35 | 1 | sortInfo => $sort_info, | |||||||||||
| 36 | }; | ||||||||||||
| 37 | my @fields = ( | ||||||||||||
| 38 | 1 | ▶ | @{ delete( $resp->{fields} ) || [] }, | ||||||||||
|
Condition50%1/2
delete $resp->{'fields'} || []
MC/DC0%0/1
delete $resp->{'fields'} || []
delete $resp->{'fields'}
Truth table50%1/2
A
A= delete $resp->{'fields'}
| |||||||||||||
| 39 | 1 | @{ $self->default_fields } | |||||||||||
| 40 | ); | ||||||||||||
| 41 | 1 | $resp->{metaData}->{fields} = \@fields; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 1 | ▶ | $resp->{success} = 1 unless defined $resp->{success}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | |||||||||||||
| 46 | # in devel mode use pretty() | ||||||||||||
| 47 | 1 | ▶ | return $self->debug | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | ? JSON->new->utf8->pretty(1)->encode($resp) | ||||||||||||
| 49 | : encode_json($resp); | ||||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 2 | 1; | |||||||||||
| 53 | |||||||||||||
| 54 | __END__ | ||||||||||||