1###################################################################### 2package Net::Amazon::Response::Exchange; 3###################################################################### 4use warnings; 5use strict; 6use base qw(Net::Amazon::Response); 7 8use Net::Amazon::Property; 9use Net::Amazon::Result::Seller::Listing; 10use Log::Log4perl qw(:easy); 11 12__PACKAGE__->make_array_accessor($_) for qw(listings); 13 14################################################## 15sub new { 16################################################## 17 my($class, %options) = @_; 18 19 my $self = $class->SUPER::new(%options); 20 21 bless $self, $class; # reconsecrate 22} 23 24################################################## 25sub result { 26################################################## 27 my($self) = @_; 28 29 if($self->is_success()) { 30 return Net::Amazon::Result::Seller::Listing->new( 31 xmlref => $self->{xmlref}->{SellerListings}->[0], 32 ); 33 } 34 35 return undef; 36} 37 38################################################## 39sub as_string { 40################################################## 41 my($self) = @_; 42 43 return "TODO: as_string not defined yet in ", __PACKAGE__; 44} 45 46################################################## 47sub xmlref_add { 48################################################## 49 my($self, $xmlref) = @_; 50 51 my $nof_items_added = 0; 52 53 DEBUG("xmlref_add (before):", Data::Dumper::Dumper($xmlref)); 54 55 unless(ref($self->{xmlref}) eq "HASH" && 56 ref($self->{xmlref}->{SellerListings}) eq "ARRAY") { 57 $self->{xmlref}->{SellerListings} = []; 58 } 59 60 if(ref($xmlref->{SellerListings}->{SellerListing}) eq "ARRAY") { 61 # Is it an array of items? 62 push @{$self->{xmlref}->{SellerListings}}, 63 $_ for @{$xmlref->{SellerListings}->{SellerListing}}; 64 65 $nof_items_added = scalar @{$xmlref->{SellerListings}->{SellerListing}}; 66 } else { 67 # It is a single item 68 push @{$self->{xmlref}->{SellerListings}}, 69 $xmlref->{SellerListings}->{SellerListing}; 70 $nof_items_added = 1; 71 } 72 73 #DEBUG("(Seller) xmlref_add (after):", Data::Dumper::Dumper($self)); 74 return $nof_items_added; 75} 76 77################################################## 78sub properties { 79################################################## 80 my($self) = @_; 81 82 die "properties() not defined in ", __PACKAGE__, ". Use result() instead"; 83} 84 851; 86