Riak/Role/REST/Object.pm

filter: Statementstmt 33.7% 31 / 92 Branchbran 28.5% 12 / 42 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 42.8% 3 / 7 Podpod 20.0% 1 / 5 totaltotal 29.8% 48 / 161 CC 27 SCAR 42.8
CC
27
Cov
31%
store_object
132.0
populate_object
54.7
load_object
2.0
CRAP 72.4
↑ Summary Riak/Object.pm »
1 package Net::Riak::Role::REST::Object;
2 {
3 4 $Net::Riak::Role::REST::Object::VERSION = '0.1702';
4 }
5  
6 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub store_object {
Subroutine store_object: not called CC=11 SCAR=48.8
Pod undocumented
10 0 my ($self, $w, $dw, $object) = @_;
11  
12 0 my $params = {returnbody => 'true', w => $w, dw => $dw};
13  
14 0 ▶ $params->{returnbody} = 'false'
Branch: 1 branch
BranchTrueFalseTotal
if $self->disable_return_body 0 0 0
15 if $self->disable_return_body;
16  
17  
18 0 my $request;
19 0 ▶ if ( defined $object->key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object->key) { } 0 0 0
20 0 $request = $self->new_request('PUT',
21 [$self->prefix, $object->bucket->name, $object->key], $params);
22 } else {
23 0 $request = $self->new_request('POST',
24 [$self->prefix, $object->bucket->name ], $params);
25 }
26  
27 0 $request->header('X-Riak-ClientID' => $self->client_id);
28 0 $request->header('Content-Type' => $object->content_type);
29  
30 0 ▶ if ($object->has_vclock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->has_vclock) 0 0 0
31 0 $request->header('X-Riak-Vclock' => $object->vclock);
32 }
33  
34 0 ▶ if ($object->has_links) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->has_links) 0 0 0
35 0 $request->header('link' => $self->_links_to_header($object));
36 }
37  
38 0 ▶ if ($object->has_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->has_meta) 0 0 0
39 0 ▶ while ( my ( $k, $v ) = each %{ $object->metadata } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$object->metadata;}) 0 0 0
40 0 $request->header('x-riak-meta-' . lc($k) => $v );
41 }
42 }
43  
44 0 ▶ if ($object->i2indexes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->i2indexes) 0 0 0
45 0 foreach (keys %{$object->i2indexes}) {
46 0 $request->header(':x-riak-index-' . lc($_) => $object->i2indexes->{$_});
47 }
48 }
49  
50 0 ▶ if (ref $object->data && $object->content_type eq 'application/json') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object->data and $object->content_type eq 'application/json') { } 0 0 0
Condition0%0/3
ref $object->data and $object->content_type eq "application/json"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $object->data and $object->content_type eq "application/json"
ref $object->data $object->content_type eq "application/json"
Truth table0%0/3
A and B
A= ref $object->dataB= $object->content_type eq "application/json"
ABresult
0X0
100
111
51 0 $request->content(JSON::encode_json($object->data));
52 }
53 else {
54 0 $request->content($object->data);
55 }
56  
57 0 my $response = $self->send_request($request);
58 0 $self->populate_object($object, $response, [200, 201, 204, 300]);
59 0 return $object;
60 }
61  
62 0 ▶sub load_object {
Subroutine load_object: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my ( $self, $params, $object ) = @_;
64  
65 0 my $request =
66 $self->new_request( 'GET',
67 [ $self->prefix, $object->bucket->name, $object->key ], $params );
68  
69 0 my $response = $self->send_request($request);
70 0 $self->populate_object($object, $response, [ 200, 300, 404 ] );
71 0 $object;
72 }
73  
74 0 ▶sub delete_object {
Subroutine delete_object: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my ( $self, $params, $object ) = @_;
76  
77 0 my $request =
78 $self->new_request( 'DELETE',
79 [ $self->prefix, $object->bucket->name, $object->key ], $params );
80  
81 0 my $response = $self->send_request($request);
82 0 $self->populate_object($object, $response, [ 204, 404 ] );
83 0 $object;
84 }
85  
86 2 ▶sub populate_object {
Subroutine populate_object: called CC=17 SCAR=40.0
Pod documented
87 2 my ($self, $obj, $http_response, $expected) = @_;
88  
89 2 $obj->_clear_links;
90 2 $obj->exists(0);
91  
92 2 ▶ return if (!$http_response);
Branch: 1 branch
BranchTrueFalseTotal
unless $http_response 0 2 2
93  
94  
95 2 my $status = $http_response->code;
96  
97 2 ▶ $obj->data($http_response->content)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->disable_return_body 2 0 2
98 unless $self->disable_return_body;
99  
100 2 ▶ if ( $http_response->header('location') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_response->header("location")) 0 2 2
101 0 $obj->key( $http_response->header('location') );
102 0 $obj->location( $http_response->header('location') );
103 }
104  
105 2 ▶ if (!grep { $status == $_ } @$expected) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$status == $_;} @$expected) 1 1 2
106 1 confess "Expected status "
107 . (join(', ', @$expected))
108 . ", received: ".$http_response->status_line
109 }
110  
111 1 $HTTP::Headers::TRANSLATE_UNDERSCORE = 0;
112 1 foreach ($http_response->header_field_names) {
113  
114 0 ▶ if ( /^X-Riak-Index-(.+_bin)$/ || /^X-Riak-Index-(.+_int)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^X-Riak-Index-(.+_bin)$/ or /^X-Riak-Index-(.+_int)$/) { } 0 0 0
elsif (/^X-Riak-Meta-(.+)$/) { } 0 0 0
Condition0%0/3
/^X-Riak-Index-(.+_bin)$/ or /^X-Riak-Index-(.+_int)$/
l!l&&r!l&&!r
000
MC/DC0%0/2
/^X-Riak-Index-(.+_bin)$/ or /^X-Riak-Index-(.+_int)$/
/^X-Riak-Index-(.+_bin)$/ /^X-Riak-Index-(.+_int)$/
Truth table0%0/3
A or B
A= /^X-Riak-Index-(.+_bin)$/B= /^X-Riak-Index-(.+_int)$/
ABresult
1X1
011
000
115 0 $obj->add_index(lc($1), $http_response->header($_))
116 }
117 elsif ( /^X-Riak-Meta-(.+)$/ ) {
118 0 $obj->set_meta(lc($1), $http_response->header($_));
119 }
120 }
121 1 $HTTP::Headers::TRANSLATE_UNDERSCORE = 1;
122  
123 1 ▶ if ($status == 404) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 404) 0 1 1
124 0 $obj->clear;
125 0 return;
126 }
127  
128 1 $obj->exists(1);
129  
130 1 ▶ if ($http_response->header('link')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_response->header("link")) 0 1 1
131 0 $self->_populate_links($obj, $http_response->header('link'));
132 }
133  
134 1 ▶ if ($status == 300) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 300) 0 1 1
135 0 my @siblings = split("\n", $obj->data);
136 0 shift @siblings;
137 0 my %seen; @siblings = grep { !$seen{$_}++ } @siblings;
138 0 $obj->siblings(\@siblings);
139 }
140  
141 1 ▶ if ($status == 201) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 201) 0 1 1
142 0 my $location = $http_response->header('location');
143 0 my ($key) = ($location =~ m!/([^/]+)$!);
144 0 $obj->key($key);
145 }
146  
147  
148 1 ▶ if ($status == 200 || $status == 201) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 200 or $status == 201) 1 0 1
Condition33%1/3
$status == 200 or $status == 201
l!l&&r!l&&!r
100
MC/DC0%0/2
$status == 200 or $status == 201
$status == 200 $status == 201
Truth table33%1/3
A or B
A= $status == 200B= $status == 201
ABresult
1X1
011
000
149 1 ▶ $obj->content_type($http_response->content_type)
Branch: 1 branch
BranchTrueFalseTotal
if $http_response->content_type 0 1 1
150 if $http_response->content_type;
151 1 ▶ $obj->data(JSON::decode_json($obj->data))
Branch: 1 branch
BranchTrueFalseTotal
if $obj->content_type eq "application/json" 1 0 1
152 if $obj->content_type eq 'application/json';
153 1 $obj->vclock($http_response->header('X-Riak-Vclock'));
154 }
155 }
156  
157 0 ▶sub retrieve_sibling {
Subroutine retrieve_sibling: not called CC=1 SCAR=6.9
Pod undocumented
158 0 my ($self, $object, $params) = @_;
159  
160 0 my $request = $self->new_request(
161 'GET',
162 [$self->prefix, $object->bucket->name, $object->key],
163 $params
164 );
165  
166 0 my $response = $self->send_request($request);
167  
168 0 my $sibling = Net::Riak::Object->new(
169 client => $self,
170 bucket => $object->bucket,
171 key => $object->key
172 );
173  
174 0 $sibling->_jsonize($object->_jsonize);
175 0 $self->populate_object($sibling, $response, [200]);
176 0 $sibling;
177 }
178  
179  
180  
181  
182 4 1;
183  
184 __END__
↑ Summary Riak/Object.pm »