| 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() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 11 | 0 | my $self = bless $args, $class; | |||||||||||||
| 12 | 0 | ▶ | croak "No account" unless $self->{account}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 13 | 0 | ▶ | croak "No domain" unless $self->{domain}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 14 | 0 | ▶ | croak "No (item) name" unless $self->{name}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 78 | 0 | ▶ | if (ref $attr eq 'HASH') { # put/delete params with values. | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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__ | ||||||||||||||