Data/Riak/Result/WithLinks.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 83 CC 6 SCAR 23.0
CC
6
Cov
0%
remove_link
20.0
create_link
6.0
add_link
6.0
CRAP 10.0
1 package Data::Riak::Result::WithLinks;
2 {
3 $Data::Riak::Result::WithLinks::VERSION = '2.0';
4 }
5 # ABSTRACT: Results with links
6  
7 use Moose::Role;
8 use Data::Riak::Link;
9 use namespace::autoclean;
10  
11 with 'MooseX::Clone';
12  
13  
14 has links => (
15 is => 'ro',
16 isa => 'ArrayRef[Data::Riak::Link]',
17 );
18  
19  
20 sub create_link {
21 my ($self, %opts) = @_;
22 return Data::Riak::Link->new({
23 bucket => $self->bucket_name,
24 key => $self->key,
25 riaktag => $opts{riaktag},
26 (exists $opts{params} ? (params => $opts{params}) : ())
27 });
28 }
29  
30  
31 sub add_link {
32 my ($self, $link) = @_;
33 confess 'No link to add provided'
34 unless blessed $link && $link->isa('Data::Riak::Link');
35 return $self->clone(links => [@{ $self->links }, $link]);
36 }
37  
38  
39 sub remove_link {
40 my ($self, $args) = @_;
41 my $key = $args->{key};
42 my $riaktag = $args->{riaktag};
43 my $bucket = $args->{bucket};
44 my $links = $self->links;
45 my $new_links;
46 foreach my $link (@{$links}) {
47 next if($bucket && ($bucket eq $link->bucket));
48 next if($key && $link->has_key && ($key eq $link->key));
49 next if($riaktag && $link->has_riaktag && ($riaktag eq $link->riaktag));
50 push @{$new_links}, $link;
51 }
52 return $self->clone(links => $new_links);
53 }
54  
55 1;
56  
57 __END__