Document/Builder.pm

filter: Statementstmt 100% 19 / 19 Branchbran n/a Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 100% 28 / 28 CC 2 SCAR 3.4
CC
2
Cov
100%
build_relationship
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Document/Builder/Role/Type.pm ↑ Summary Document/Builder/Role/Parameters.pm »
1 package JSONAPI::Document::Builder;
2 6 $JSONAPI::Document::Builder::VERSION = '2.0';
3 =head1 NAME
4  
5 JSONAPI::Document::Builder - Resource Document builder
6  
7 =head1 VERSION
8  
9 version 2.0
10  
11 =head1 DESCRIPTION
12  
13 Builds a resource document.
14  
15 =cut
16  
17 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 with 'JSONAPI::Document::Builder::Role::Parameters',
19 'JSONAPI::Document::Builder::Role::Attributes',
20 'JSONAPI::Document::Builder::Role::Type';
21  
22 6 ▶use JSONAPI::Document::Builder::Relationships;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 6 has row => (
25 is => 'ro',
26 required => 1,
27 );
28  
29 =head2 build : HashRef
30  
31 Main caller method; Builds the resource document for C<row>.
32  
33 =cut
34  
35 sub build {
36 19 ▶ my ($self) = @_;
Subroutine build: called CC=1 SCAR=0.0
Pod documented
37 19 my $row = $self->row;
38 19 my $type = lc($row->result_source->source_name());
39  
40 19 my %document = (
41 id => $row->id(),
42 type => $self->document_type($type),
43 attributes => $self->get_attributes());
44  
45 19 return \%document;
46 }
47  
48 =head2 build_relationship(Str $relationship, ArrayRef $fields, HashRef $options?) : HashRef
49  
50 Builds the related resource document for the given relationship.
51  
52 =cut
53  
54 sub build_relationship {
55 18 ▶ my ($self, $relationship, $fields, $options) = @_;
Subroutine build_relationship: called CC=2 SCAR=6.9
Pod documented
56 18 ▶ $options //= {};
Condition100%2/2
$options //= {}
l!l
126
MC/DC100%1/1
$options //= {}
$options
Truth table100%2/2
A
A= $options
Aresult
11
00
57 my $builder = JSONAPI::Document::Builder::Relationships->new(
58 api_url => $self->api_url,
59 chi => $self->chi,
60 segmenter => $self->segmenter,
61 fields => $fields,
62 kebab_case_attrs => $self->kebab_case_attrs,
63 row => $self->row,
64 relationship => $relationship,
65 with_attributes => $options->{with_attributes},
66 18 );
67 18 return $builder->build();
68 }
69  
70 6 1;
« Document/Builder/Role/Type.pm ↑ Summary Document/Builder/Role/Parameters.pm »