| 1 | package Amazon::SimpleDB; | ||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 3 | ▶ | use Digest::HMAC_SHA1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 3 | ▶ | use Amazon::SimpleDB::Domain; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 3 | ▶ | use Amazon::SimpleDB::Response; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 3 | ▶ | use constant SERVICE_URI => 'http://sdb.amazonaws.com/'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 3 | ▶ | use constant KEEP_ALIVE_CACHESIZE => 10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 20 | 0 | my $class = shift; | |||||||||||||||||||
| 21 | 0 | ▶ | my $args = shift || {}; | ||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 22 | 0 | my $self = bless $args, $class; | |||||||||||||||||||
| 23 | 0 | ▶ | croak "No aws_access_key_id" unless $self->{aws_access_key_id}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 0 | ▶ | croak "No aws_secret_access_key" unless $self->{aws_secret_access_key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 0 | ▶ | unless ($self->{agent}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | my $agent = LWP::UserAgent->new(keep_alive => KEEP_ALIVE_CACHESIZE); | |||||||||||||||||||
| 27 | 0 | $agent->timeout(10); | |||||||||||||||||||
| 28 | 0 | $agent->env_proxy; | |||||||||||||||||||
| 29 | 0 | $self->{agent} = $agent; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | 0 | return $self; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 0 | ▶ | sub domains { | ||||||||||||||||||
|
Subroutine
domains: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||
| 36 | 0 | ▶ | my $args = shift || {}; | ||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 37 | 0 | my $params = {}; | |||||||||||||||||||
| 38 | 0 | ▶ | $params->{MaxNumberOfDomains} = $args->{'limit'} if $args->{'limit'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | ▶ | $params->{NextToken} = $args->{'next'} if $args->{'next'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | my $res = $self->request('ListDomains', $params); | |||||||||||||||||||
| 41 | return | ||||||||||||||||||||
| 42 | 0 | Amazon::SimpleDB::Response->new( | |||||||||||||||||||
| 43 | { | ||||||||||||||||||||
| 44 | http_response => $res, | ||||||||||||||||||||
| 45 | account => $self | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | sub domain { | ||||||||||||||||||
|
Subroutine
domain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 51 | 0 | return Amazon::SimpleDB::Domain->new({name => $_[1], account => $_[0]}); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | sub create_domain { # note no more than 100 per account. | ||||||||||||||||||
|
Subroutine
create_domain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 55 | 0 | my ($self, $name) = @_; | |||||||||||||||||||
| 56 | 0 | my $res = $self->request('CreateDomain', {DomainName => $name}); | |||||||||||||||||||
| 57 | return | ||||||||||||||||||||
| 58 | 0 | Amazon::SimpleDB::Response->new( | |||||||||||||||||||
| 59 | { | ||||||||||||||||||||
| 60 | http_response => $res, | ||||||||||||||||||||
| 61 | account => $self | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | sub delete_domain { | ||||||||||||||||||
|
Subroutine
delete_domain: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 67 | 0 | my ($self, $name) = @_; | |||||||||||||||||||
| 68 | 0 | my $res = $self->request('DeleteDomain', {DomainName => $name}); | |||||||||||||||||||
| 69 | return | ||||||||||||||||||||
| 70 | 0 | Amazon::SimpleDB::Response->new( | |||||||||||||||||||
| 71 | { | ||||||||||||||||||||
| 72 | http_response => $res, | ||||||||||||||||||||
| 73 | account => $self | ||||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | #--- utility methods | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | sub request { # returns "raw" HTTP Response from SimpleDB | ||||||||||||||||||
|
Subroutine
request: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 81 | 0 | my ($self, $action, $params) = @_; | |||||||||||||||||||
| 82 | 0 | ▶ | croak "No Action parameter" unless $action; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | ▶ | $params ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
| |||||||||||||||||||||
| 84 | 0 | $params->{Action} = $action; | |||||||||||||||||||
| 85 | 0 | $params->{AWSAccessKeyId} = $self->{aws_access_key_id}; | |||||||||||||||||||
| 86 | 0 | $params->{Version} = '2007-11-07'; | |||||||||||||||||||
| 87 | 0 | ▶ | $params->{SignatureVersion} = 1 unless defined $params->{SignatureVersion}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | ▶ | $params->{Timestamp} = timestamp() unless $params->{Expires}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 0 | ▶ | my $time = $params->{Expires} || $params->{Timestamp}; | ||||||||||||||||||
|
Condition0%0/3
$params->{'Expires'} || $params->{'Timestamp'}
MC/DC0%0/2
$params->{'Expires'} || $params->{'Timestamp'}
$params->{'Expires'}
$params->{'Timestamp'}
Truth table0%0/3
A || B
A= $params->{'Expires'}B= $params->{'Timestamp'}
| |||||||||||||||||||||
| 90 | 0 | my $sig = ''; | |||||||||||||||||||
| 91 | 0 | ▶ | if ($params->{SignatureVersion} == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | $sig .= $_ . $params->{$_} | ||||||||||||||||||||
| 93 | 0 | for (sort { lc($a) cmp lc($b) } keys %$params) | |||||||||||||||||||
| 94 | ; # Must be alphabetical in a case-insensitive manner. | ||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||
| 96 | 0 | $sig = $params->{Action} . $time; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | 0 | my $hash = Digest::HMAC_SHA1->new($self->{aws_secret_access_key}); | |||||||||||||||||||
| 99 | 0 | $hash->add($sig); | |||||||||||||||||||
| 100 | 0 | $params->{Signature} = encode_base64($hash->digest, ''); | |||||||||||||||||||
| 101 | 0 | my $uri = URI->new(SERVICE_URI); | |||||||||||||||||||
| 102 | 0 | $uri->query_form($params); | |||||||||||||||||||
| 103 | 0 | return $self->{agent}->get($uri->as_string); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | sub timestamp { | ||||||||||||||||||
|
Subroutine
timestamp: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 107 | 0 | my $t = shift; | |||||||||||||||||||
| 108 | 0 | ▶ | $t = time unless defined $t; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 0 | my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = | |||||||||||||||||||
| 110 | gmtime($t); | ||||||||||||||||||||
| 111 | return | ||||||||||||||||||||
| 112 | 0 | sprintf("%4i-%02i-%02iT%02i:%02i:%02iZ", | |||||||||||||||||||
| 113 | ($year + 1900), | ||||||||||||||||||||
| 114 | ($mon + 1), | ||||||||||||||||||||
| 115 | $mday, $hour, $min, $sec); | ||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 3 | 1; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||