Amazon-SimpleDB

 view release on metacpan or  search on metacpan

lib/Amazon/SimpleDB/Item.pm  view on Meta::CPAN

package Amazon::SimpleDB::Item;
use strict;
use warnings;

use Amazon::SimpleDB::Response;
use Carp qw( croak );

sub new {
    my $class = shift;
    my $args  = shift || {};
    my $self  = bless $args, $class;
    croak "No account"     unless $self->{account};
    croak "No domain"      unless $self->{domain};
    croak "No (item) name" unless $self->{name};
    return $self;
}

sub account { return $_[0]->{account} }
sub name    { return $_[0]->{name} }
sub domain  { return $_[0]->{domain} }

sub get_attributes {
    my ($self, $name) = @_;
    my $params = {DomainName => $self->{domain}, ItemName => $self->{name}};
    $params->{AttributeName} = $name
      if defined $name;    # specific attribute request
    my $account = $self->{account};
    return
      Amazon::SimpleDB::Response->new(
                   http_response => $account->request('GetAttributes', $params),
                   domain        => $self,
                   account       => $self->{account},
      );
}

sub put_attributes {
    my ($self, $attr) = @_;
    my $params = _process_attribute_params($self, $attr);
    my $account = $self->{account};
    return
      Amazon::SimpleDB::Response->new(
                   http_response => $account->request('PutAttributes', $params),
                   domain        => $self,
                   account       => $self->{account},
      );
}

sub post_attributes {
    my ($self, $attr) = @_;
    my $params = _process_attribute_params($self, $attr, 1);
    my $account = $self->{account};
    return
      Amazon::SimpleDB::Response->new(
                   http_response => $account->request('PutAttributes', $params),
                   domain        => $self,
                   account       => $self->{account},
      );
}

sub delete_attributes {
    my ($self, $attr) = @_;
    my $params = _process_attribute_params($self, $attr);
    my $account = $self->{account};
    return
      Amazon::SimpleDB::Response->new(
                http_response => $account->request('DeleteAttributes', $params),
                domain        => $self,
                account       => $self->{account},
      );
}



( run in 1.388 second using v1.01-cache-2.11-cpan-39bf76dae61 )