Riak/Object.pm

filter: Statementstmt 27.9% 31 / 111 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 18.1% 4 / 22 Podpod 72.7% 8 / 11 totaltotal 18.2% 43 / 236 CC 27 SCAR 39.0
CC
27
Cov
18%
add_index
110.0
remove_index
110.0
_build_link
20.0
CRAP 49.5
« Riak/Role/REST/Object.pm ↑ Summary Riak/MapReduce.pm »
1 package Net::Riak::Object;
2 {
3 21 $Net::Riak::Object::VERSION = '0.1702';
4 }
5  
6 # ABSTRACT: holds meta information about a Riak object
7  
8 21 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use Net::Riak::Link;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 21 with 'Net::Riak::Role::Replica' => {keys => [qw/r w dw/]};
13 21 with 'Net::Riak::Role::Base' => {classes =>
14 [{name => 'bucket', required => 1}]};
15 21 ▶use Net::Riak::Types Client => {-as => 'Client_T'};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 21 has client => (
18 is => 'rw',
19 isa => Client_T,
20 required => 1,
21 );
22 21 has key => (is => 'rw', isa => 'Str', required => 0);
23 21 has exists => (is => 'rw', isa => 'Bool', default => 0,);
24 21 has data => (is => 'rw', isa => 'Any', clearer => '_clear_data');
25 21 has vclock => (is => 'rw', isa => 'Str', predicate => 'has_vclock');
26 21 has vtag => (is => 'rw', isa => 'Str');
27 21 has content_type => (is => 'rw', isa => 'Str', default => 'application/json');
28 21 has location => (is => 'rw', isa => 'Str');
29 21 has _jsonize => (is => 'rw', isa => 'Bool', lazy => 1, default => 1);
30 21 has i2indexes => (is => 'rw', isa => 'HashRef');
31  
32 has links => (
33 traits => ['Array'],
34 is => 'rw',
35 isa => 'ArrayRef[Net::Riak::Link]',
36 auto_deref => 1,
37 lazy => 1,
38 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 21 handles => {
40 append_link => 'push',
41 has_links => 'count',
42 all_links => 'elements',
43 },
44 clearer => '_clear_links',
45 );
46  
47 has metadata => (
48 traits => ['Hash'],
49 is => 'rw',
50 isa => 'HashRef[Str]',
51 auto_deref => 1,
52 lazy => 1,
53 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 21 handles => {
55 set_meta => 'set',
56 get_meta => 'get',
57 remove_meta => 'delete',
58 has_meta => 'count',
59 all_meta => 'elements',
60 },
61 clearer => '_clear_meta',
62 );
63  
64 has siblings => (
65 traits => ['Array'],
66 is => 'rw',
67 isa => 'ArrayRef[Str]',
68 auto_deref => 1,
69 lazy => 1,
70 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 21 handles => {
72 get_siblings => 'elements',
73 add_sibling => 'push',
74 count_siblings => 'count',
75 get_sibling => 'get',
76 has_siblings => 'count',
77 has_no_siblings => 'is_empty',
78 },
79 clearer => '_clear_siblings',
80 );
81  
82 0 ▶sub store {
Subroutine store: not called CC=3 SCAR=24.8
Pod documented
83 0 my ($self, $w, $dw) = @_;
84  
85 0 ▶ $w ||= $self->w;
Condition0%0/3
$w ||= $self->w
l!l&&r!l&&!r
000
MC/DC0%0/2
$w ||= $self->w
$w $self->w
Truth table0%0/3
A ||= B
A= $wB= $self->w
ABresult
1X1
011
000
86 0 ▶ $dw ||= $self->dw;
Condition0%0/3
$dw ||= $self->dw
l!l&&r!l&&!r
000
MC/DC0%0/2
$dw ||= $self->dw
$dw $self->dw
Truth table0%0/3
A ||= B
A= $dwB= $self->dw
ABresult
1X1
011
000
87  
88 0 $self->client->store_object($w, $dw, $self);
89 }
90  
91 0 ▶sub add_index {
Subroutine add_index: not called CC=10 SCAR=47.0
Pod undocumented
92 0 my ($self, $index, $data) = @_;
93  
94 0 ▶ if (defined $index && defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index and defined $data) 0 0 0
Condition0%0/3
defined $index and defined $data
!ll&&!rl&&r
000
MC/DC0%0/2
defined $index and defined $data
defined $index defined $data
Truth table0%0/3
A and B
A= defined $indexB= defined $data
ABresult
0X0
100
111
95 0 my $ref = undef;
96 0 ▶ $ref = $self->i2indexes
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->i2indexes 0 0 0
97 if (defined $self->i2indexes);
98  
99 0 ▶ $ref->{$index} = $data
Branch: 1 branch
BranchTrueFalseTotal
if length $index > 4 and $index =~ /^.+_bin$/ and length $data > 0 0 0 0
Condition0%0/6
length $index > 4 and $index =~ /^.+_bin$/ and length $data > 0
!ll&&!rl&&r
000
length $index > 4 and $index =~ /^.+_bin$/
!ll&&!rl&&r
000
MC/DC0%0/3
length $index > 4 and $index =~ /^.+_bin$/ and length $data > 0
length $index > 4 $index =~ /^.+_bin$/ length $data > 0
Truth table0%0/4
A and B and C
A= length $index > 4B= $index =~ /^.+_bin$/C= length $data > 0
ABCresult
0XX0
10X0
1100
1111
100 if (length($index) > 4 && $index =~ /^.+_bin$/ && length($data) > 0 );
101  
102 0 ▶ $ref->{$index} = $data
Branch: 1 branch
BranchTrueFalseTotal
if length $index > 4 and $index =~ /^.+_int$/ and $data =~ /^\d+$/ 0 0 0
Condition0%0/6
length $index > 4 and $index =~ /^.+_int$/ and $data =~ /^\d+$/
!ll&&!rl&&r
000
length $index > 4 and $index =~ /^.+_int$/
!ll&&!rl&&r
000
MC/DC0%0/3
length $index > 4 and $index =~ /^.+_int$/ and $data =~ /^\d+$/
length $index > 4 $index =~ /^.+_int$/ $data =~ /^\d+$/
Truth table0%0/4
A and B and C
A= length $index > 4B= $index =~ /^.+_int$/C= $data =~ /^\d+$/
ABCresult
0XX0
10X0
1100
1111
103  
104 if (length($index) > 4 && $index =~ /^.+_int$/ && $data =~ /^\d+$/ );
105 0 $self->i2indexes($ref);
106 }
107 0 return $self->i2indexes;
108 }
109  
110 0 ▶sub remove_index {
Subroutine remove_index: not called CC=10 SCAR=47.0
Pod undocumented
111 0 my ($self, $index, $data) = @_;
112 0 ▶ if (defined $index && defined $data && defined $self->i2indexes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index and defined $data and defined $self->i2indexes) 0 0 0
Condition0%0/6
defined $index and defined $data and defined $self->i2indexes
!ll&&!rl&&r
000
defined $index and defined $data
!ll&&!rl&&r
000
MC/DC0%0/3
defined $index and defined $data and defined $self->i2indexes
defined $index defined $data defined $self->i2indexes
Truth table0%0/4
A and B and C
A= defined $indexB= defined $dataC= defined $self->i2indexes
ABCresult
0XX0
10X0
1100
1111
113 0 my $ref = $self->i2indexes;
114  
115 0 ▶ if ($index =~ /^.+_bin$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index =~ /^.+_bin$/) 0 0 0
116 0 delete ${$ref}{$index}
117 0 ▶ if (defined($ref->{$index}) && $ref->{$index} eq $data);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref->{$index} and $ref->{$index} eq $data 0 0 0
Condition0%0/3
defined $ref->{$index} and $ref->{$index} eq $data
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ref->{$index} and $ref->{$index} eq $data
defined $ref->{$index} $ref->{$index} eq $data
Truth table0%0/3
A and B
A= defined $ref->{$index}B= $ref->{$index} eq $data
ABresult
0X0
100
111
118 0 $self->i2indexes($ref);
119 }
120 0 ▶ if ( $index =~ /^.+_int$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index =~ /^.+_int$/) 0 0 0
121 0 delete(${$ref}{$index})
122 0 ▶ if (defined($ref->{$index}) && $ref->{$index} == $data);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref->{$index} and $ref->{$index} == $data 0 0 0
Condition0%0/3
defined $ref->{$index} and $ref->{$index} == $data
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ref->{$index} and $ref->{$index} == $data
defined $ref->{$index} $ref->{$index} == $data
Truth table0%0/3
A and B
A= defined $ref->{$index}B= $ref->{$index} == $data
ABresult
0X0
100
111
123 0 $self->i2indexes($ref);
124 }
125 }
126 0 return $self->i2indexes;
127 }
128  
129 0 ▶sub load {
Subroutine load: not called CC=1 SCAR=6.9
Pod documented
130 0 my $self = shift;
131  
132 0 my $params = {r => $self->r};
133  
134 0 $self->client->load_object($params, $self);
135 }
136  
137 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
138 0 my ($self, $dw) = @_;
139  
140 0 ▶ $dw ||= $self->bucket->dw;
Condition0%0/3
$dw ||= $self->bucket->dw
l!l&&r!l&&!r
000
MC/DC0%0/2
$dw ||= $self->bucket->dw
$dw $self->bucket->dw
Truth table0%0/3
A ||= B
A= $dwB= $self->bucket->dw
ABresult
1X1
011
000
141 0 my $params = {dw => $dw};
142  
143 0 $self->client->delete_object($params, $self);
144 }
145  
146 0 ▶sub clear {
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
147 0 my $self = shift;
148 0 $self->_clear_data;
149 0 $self->_clear_links;
150 0 $self->_clear_meta;
151 0 $self->exists(0);
152 0 $self;
153 }
154  
155 0 ▶sub sibling {
Subroutine sibling: not called CC=2 SCAR=17.9
Pod undocumented
156 0 my ($self, $id, $r) = @_;
157 0 ▶ $r ||= $self->bucket->r;
Condition0%0/3
$r ||= $self->bucket->r
l!l&&r!l&&!r
000
MC/DC0%0/2
$r ||= $self->bucket->r
$r $self->bucket->r
Truth table0%0/3
A ||= B
A= $rB= $self->bucket->r
ABresult
1X1
011
000
158  
159 0 my $vtag = $self->get_sibling($id);
160  
161 0 return $self->client->retrieve_sibling(
162 $self, {r => $r, vtag => $vtag}
163 );
164 }
165  
166 0 ▶sub _build_link {
Subroutine _build_link: not called CC=4 SCAR=30.0
167 0 my ($self,$obj,$tag) = @_;
168 0 ▶ blessed $obj && $obj->isa('Net::Riak::Link')
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($obj) && $obj->isa('Net::Riak::Link') ? : 0 0 0
Condition0%0/6
builtin::blessed($obj) and $obj->isa("Net::Riak::Link")
!ll&&!rl&&r
000
$tag || $self->bucket->name
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($obj) and $obj->isa("Net::Riak::Link")
builtin::blessed($obj) $obj->isa("Net::Riak::Link")
MC/DC0%0/2
$tag || $self->bucket->name
$tag $self->bucket->name
Truth table0%0/3
A and B
A= builtin::blessed($obj)B= $obj->isa("Net::Riak::Link")
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= $tagB= $self->bucket->name
ABresult
1X1
011
000
169 ? $obj
170 : Net::Riak::Link->new(
171 bucket => $obj->bucket,
172 key => $obj->key,
173 tag => $tag || $self->bucket->name,
174 );
175 }
176  
177 0 ▶around [qw{append_link remove_link add_link}] => sub{
Subroutine __ANON__: not called CC=1 SCAR=6.9
178 0 my $next = shift;
179 0 my $self = shift;
180 0 $self->$next($self->_build_link(@_));
181 21 };
182  
183 0 ▶sub add_link {
Subroutine add_link: not called CC=1 SCAR=6.9
184 0 my ($self, $link) = @_;
185 0 $self->remove_link($link);
186 0 $self->append_link($link);
187 0 $self;
188 }
189  
190 0 ▶sub remove_link {
Subroutine remove_link: not called CC=2 SCAR=17.9
191 0 my ($self, $link) = @_;
192 0 my @links = grep { $_->key ne $link->key } @{$self->links};
193 0 $self->_clear_links;
194 0 $self->append_link($_) for @links;
195 0 $self;
196 }
197  
198 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
199 0 my ($self, @args) = @_;
200 0 my $map_reduce = Net::Riak::MapReduce->new(client => $self->client);
201 0 $map_reduce->add($self->bucket->name, $self->key);
202 0 $map_reduce->add(@args);
203 0 $map_reduce;
204 }
205  
206 0 ▶sub link {
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
207 0 my ($self, @args) = @_;
208 0 my $map_reduce = Net::Riak::MapReduce->new(client => $self->client);
209 0 $map_reduce->add($self->bucket->name, $self->key);
210 0 $map_reduce->link(@args);
211 0 $map_reduce;
212 }
213  
214 0 ▶sub map {
Subroutine map: not called CC=1 SCAR=6.9
Pod documented
215 0 my ($self, @args) = @_;
216 0 my $map_reduce = Net::Riak::MapReduce->new(client => $self->client);
217 0 $map_reduce->add($self->bucket->name, $self->key);
218 0 $map_reduce->map(@args);
219 0 $map_reduce;
220 }
221  
222 0 ▶sub reduce {
Subroutine reduce: not called CC=1 SCAR=6.9
Pod documented
223 0 my ($self, @args) = @_;
224 0 my $map_reduce = Net::Riak::MapReduce->new(client => $self->client);
225 0 $map_reduce->add($self->bucket->name, $self->key);
226 0 $map_reduce->reduce(@args);
227 0 $map_reduce;
228 }
229  
230 21 1;
231  
232 __END__
« Riak/Role/REST/Object.pm ↑ Summary Riak/MapReduce.pm »