Data/Riak/Fast/Result.pm

filter: Statementstmt 33.3% 24 / 72 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 29.4% 5 / 17 Podpod 14.2% 1 / 7 totaltotal 21.7% 30 / 138 CC 16 SCAR 36.3
CC
16
Cov
23%
remove_link
110.0
__ANON__
12.0
__ANON__
6.0
CRAP 37.5
« Data/Riak/Fast/MapReduce/Phase/Map.pm ↑ Summary Data/Riak/Fast/Bucket.pm »
1 package Data::Riak::Fast::Result;
2  
3 22 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 22 ▶use Data::Riak::Fast::Link;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use HTTP::Headers::ActionPack;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 22 with 'Data::Riak::Fast::Role::HasRiak';
11  
12 has bucket => (
13 is => 'ro',
14 isa => 'Data::Riak::Fast::Bucket',
15 lazy => 1,
16 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 my $self = shift;
18 0 $self->riak->bucket( $self->bucket_name )
19 }
20 22 );
21  
22 has location => (
23 is => 'ro',
24 isa => 'URI',
25 lazy => 1,
26 clearer => '_clear_location',
27 0 ▶ default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
28 0 my $self = shift;
29 0 ▶ return $self->http_message->request->uri if $self->http_message->can('request');
Branch: 1 branch
BranchTrueFalseTotal
if $self->http_message->can("request") 0 0 0
30 0 ▶ return URI->new( $self->http_message->header('location') || die "Cannot determine location from " . $self->http_message );
Condition0%0/2
$self->http_message->header('location') || die('Cannot determine location from ' . $self->http_message)
l!l
00
MC/DC0%0/1
$self->http_message->header('location') || die('Cannot determine location from ' . $self->http_message)
$self->http_message->header('location')
Truth table0%0/2
A
A= $self->http_message->header('location')
Aresult
11
00
31 }
32 22 );
33  
34 has bucket_name => (
35 is => 'ro',
36 isa => 'Str',
37 lazy => 1,
38 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 my $self = shift;
40 0 my @uri_parts = split /\//, $self->location->path;
41 0 return $uri_parts[$#uri_parts - 2];
42 }
43 22 );
44  
45 has key => (
46 is => 'ro',
47 isa => 'Str',
48 lazy => 1,
49 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 my $self = shift;
51 0 my @uri_parts = split /\//, $self->location->path;
52 0 return $uri_parts[$#uri_parts];
53 }
54 22 );
55  
56 has links => (
57 is => 'rw',
58 isa => 'ArrayRef[Data::Riak::Fast::Link]',
59 lazy => 1,
60 clearer => '_clear_links',
61 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
62 0 my $self = shift;
63 0 my $links = $self->http_message->header('link');
64 0 ▶ return [] unless $links;
Branch: 1 branch
BranchTrueFalseTotal
unless $links 0 0 0
65 return [ map {
66 0 Data::Riak::Fast::Link->from_link_header( $_ )
67 } $links->iterable ];
68 }
69 22 );
70  
71 22 has http_message => (
72 is => 'rw',
73 isa => 'HTTP::Message',
74 required => 1,
75 handles => {
76 'status_code' => 'code',
77 'value' => 'content',
78 'header' => 'header',
79 'headers' => 'headers',
80 # curried delegation
81 'etag' => [ 'header' => 'etag' ],
82 'content_type' => [ 'header' => 'content-type' ],
83 'vector_clock' => [ 'header' => 'x-riak-vclock' ],
84 'last_modified' => [ 'header' => 'last_modified' ]
85 }
86 );
87  
88 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod documented
89 0 my $self = shift;
90 0 HTTP::Headers::ActionPack->new->inflate( $self->http_message->headers );
91 }
92  
93 0 ▶sub create_link {
Subroutine create_link: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my ($self, %opts) = @_;
95 return Data::Riak::Fast::Link->new({
96 bucket => $self->bucket_name,
97 key => $self->key,
98 riaktag => $opts{riaktag},
99 0 ▶ (exists $opts{params} ? (params => $opts{params}) : ())
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'params'} ? : 0 0 0
100 });
101 }
102  
103 # if it's been changed on the server, discard those changes and update the object
104 0 ▶sub sync {
Subroutine sync: not called CC=1 SCAR=6.9
Pod undocumented
105 0 $_[0] = $_[0]->bucket->get($_[0]->key)
106 }
107  
108 # if it's been changed locally, save those changes to the server
109 0 ▶sub save {
Subroutine save: not called CC=1 SCAR=6.9
Pod undocumented
110 0 my $self = shift;
111 0 return $self->bucket->add($self->key, $self->value, { links => $self->links });
112 }
113  
114 0 ▶sub linkwalk {
Subroutine linkwalk: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my ($self, $params) = @_;
116 0 ▶ return unless $params;
Branch: 1 branch
BranchTrueFalseTotal
unless $params 0 0 0
117 0 return $self->riak->linkwalk({
118 bucket => $self->bucket_name,
119 object => $self->key,
120 params => $params
121 });
122 }
123  
124 0 ▶sub add_link {
Subroutine add_link: not called CC=2 SCAR=17.9
Pod undocumented
125 0 my ($self, $link) = @_;
126 0 ▶ return unless $link;
Branch: 1 branch
BranchTrueFalseTotal
unless $link 0 0 0
127 0 my $links = $self->links;
128 0 push @{$links}, $link;
129 0 $self->links($links);
130 0 return $self;
131 }
132  
133 0 ▶sub remove_link {
Subroutine remove_link: not called CC=10 SCAR=47.0
Pod undocumented
134 0 my ($self, $args) = @_;
135 0 my $key = $args->{key};
136 0 my $riaktag = $args->{riaktag};
137 0 my $bucket = $args->{bucket};
138 0 my $links = $self->links;
139 0 my $new_links;
140 0 foreach my $link (@{$links}) {
141 0 ▶ next if($bucket && ($bucket eq $link->bucket));
Branch: 1 branch
BranchTrueFalseTotal
if $bucket and $bucket eq $link->bucket 0 0 0
Condition0%0/3
$bucket and $bucket eq $link->bucket
!ll&&!rl&&r
000
MC/DC0%0/2
$bucket and $bucket eq $link->bucket
$bucket $bucket eq $link->bucket
Truth table0%0/3
A and B
A= $bucketB= $bucket eq $link->bucket
ABresult
0X0
100
111
142 0 ▶ next if($key && $link->has_key && ($key eq $link->key));
Branch: 1 branch
BranchTrueFalseTotal
if $key and $link->has_key and $key eq $link->key 0 0 0
Condition0%0/6
$key and $link->has_key and $key eq $link->key
!ll&&!rl&&r
000
$key and $link->has_key
!ll&&!rl&&r
000
MC/DC0%0/3
$key and $link->has_key and $key eq $link->key
$key $link->has_key $key eq $link->key
Truth table0%0/4
A and B and C
A= $keyB= $link->has_keyC= $key eq $link->key
ABCresult
0XX0
10X0
1100
1111
143 0 ▶ next if($riaktag && $link->has_riaktag && ($riaktag eq $link->riaktag));
Branch: 1 branch
BranchTrueFalseTotal
if $riaktag and $link->has_riaktag and $riaktag eq $link->riaktag 0 0 0
Condition0%0/6
$riaktag and $link->has_riaktag and $riaktag eq $link->riaktag
!ll&&!rl&&r
000
$riaktag and $link->has_riaktag
!ll&&!rl&&r
000
MC/DC0%0/3
$riaktag and $link->has_riaktag and $riaktag eq $link->riaktag
$riaktag $link->has_riaktag $riaktag eq $link->riaktag
Truth table0%0/4
A and B and C
A= $riaktagB= $link->has_riaktagC= $riaktag eq $link->riaktag
ABCresult
0XX0
10X0
1100
1111
144 0 push @{$new_links}, $link;
145 }
146 0 $self->links($new_links);
147 0 return $self;
148 }
149  
150  
151 22 __PACKAGE__->meta->make_immutable;
152 22 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
153  
154 22 1;
155  
156 __END__
« Data/Riak/Fast/MapReduce/Phase/Map.pm ↑ Summary Data/Riak/Fast/Bucket.pm »