SimpleDB/Item.pm

filter: Statementstmt 22.0% 13 / 59 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 30.7% 4 / 13 Podpod 100% 8 / 8 totaltotal 24.7% 25 / 101 CC 14 SCAR 36.4
CC
14
Cov
16%
_process_attribute_params
90.0
new
30.0
get_attributes
6.0
CRAP 38.0
« SimpleDB/Response.pm ↑ Summary SimpleDB.pm »
1 package Amazon::SimpleDB::Item;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Amazon::SimpleDB::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
9 0 my $class = shift;
10 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
11 0 my $self = bless $args, $class;
12 0 ▶ croak "No account" unless $self->{account};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"account"} 0 0 0
13 0 ▶ croak "No domain" unless $self->{domain};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"domain"} 0 0 0
14 0 ▶ croak "No (item) name" unless $self->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"name"} 0 0 0
15 0 return $self;
16 }
17  
18 0 ▶sub account { return $_[0]->{account} }
Subroutine account: not called CC=1 SCAR=6.9
Pod documented
19 0 ▶sub name { return $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
20 0 ▶sub domain { return $_[0]->{domain} }
Subroutine domain: not called CC=1 SCAR=6.9
Pod documented
21  
22 0 ▶sub get_attributes {
Subroutine get_attributes: not called CC=2 SCAR=17.9
Pod documented
23 0 my ($self, $name) = @_;
24 0 my $params = {DomainName => $self->{domain}, ItemName => $self->{name}};
25 0 ▶ $params->{AttributeName} = $name
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 0 0 0
26 if defined $name; # specific attribute request
27 0 my $account = $self->{account};
28 return
29 Amazon::SimpleDB::Response->new(
30 http_response => $account->request('GetAttributes', $params),
31 domain => $self,
32 account => $self->{account},
33 0 );
34 }
35  
36 0 ▶sub put_attributes {
Subroutine put_attributes: not called CC=1 SCAR=6.9
Pod documented
37 0 my ($self, $attr) = @_;
38 0 my $params = _process_attribute_params($self, $attr);
39 0 my $account = $self->{account};
40 return
41 Amazon::SimpleDB::Response->new(
42 http_response => $account->request('PutAttributes', $params),
43 domain => $self,
44 account => $self->{account},
45 0 );
46 }
47  
48 0 ▶sub post_attributes {
Subroutine post_attributes: not called CC=1 SCAR=6.9
Pod documented
49 0 my ($self, $attr) = @_;
50 0 my $params = _process_attribute_params($self, $attr, 1);
51 0 my $account = $self->{account};
52 return
53 Amazon::SimpleDB::Response->new(
54 http_response => $account->request('PutAttributes', $params),
55 domain => $self,
56 account => $self->{account},
57 0 );
58 }
59  
60 0 ▶sub delete_attributes {
Subroutine delete_attributes: not called CC=1 SCAR=6.9
Pod documented
61 0 my ($self, $attr) = @_;
62 0 my $params = _process_attribute_params($self, $attr);
63 0 my $account = $self->{account};
64 return
65 Amazon::SimpleDB::Response->new(
66 http_response => $account->request('DeleteAttributes', $params),
67 domain => $self,
68 account => $self->{account},
69 0 );
70 }
71  
72 #--- utility
73  
74 0 ▶sub _process_attribute_params {
Subroutine _process_attribute_params: not called CC=9 SCAR=45.0
75 0 my ($self, $attr, $replace) = @_;
76 0 my $params = {DomainName => $self->{domain}, ItemName => $self->{name}};
77 0 ▶ return $params unless $attr; # no attributes means the entire item.
Branch: 1 branch
BranchTrueFalseTotal
unless $attr 0 0 0
78 0 ▶ if (ref $attr eq 'HASH') { # put/delete params with values.
Branch: 2 branches
BranchTrueFalseTotal
if (ref $attr eq 'HASH') { } 0 0 0
elsif (ref $attr eq 'ARRAY') { } 0 0 0
79 0 my $i = 0;
80 0 for my $name (keys %$attr) {
81 $attr->{$name} = [$attr->{$name}]
82 0 ▶ unless ref $attr->{$name} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attr->{$name} eq "ARRAY" 0 0 0
83 0 for (@{$attr->{$name}}) {
84 0 $params->{"Attribute.${i}.Name"} = $name;
85 0 $params->{"Attribute.${i}.Value"} = $_;
86 0 ▶ $params->{"Attribute.${i}.Replace"} = 'true'
Branch: 1 branch
BranchTrueFalseTotal
if $replace 0 0 0
87 if $replace;
88 0 $i++;
89 }
90 }
91 } elsif (ref $attr eq 'ARRAY') { # delete multiple attributes, all values
92 0 my $i = 0;
93 0 for (@$attr) {
94 0 $params->{"Attribute.${i}.Name"} = $_;
95 0 $i++;
96 }
97 } else { # delete single attribute, all values
98 0 $params->{AttributeName} = $attr;
99 }
100 0 return $params;
101 }
102  
103 2 1;
104  
105 __END__
« SimpleDB/Response.pm ↑ Summary SimpleDB.pm »