1######################################################################
2package Net::Amazon::Property::Book;
3######################################################################
4use warnings;
5use strict;
6use base qw(Net::Amazon::Property);
7
8__PACKAGE__->make_accessor($_) for qw(publisher binding isbn
9    dewey_decimal numpages edition ean publication_date);
10__PACKAGE__->make_array_accessor($_) for qw(authors);
11
12##################################################
13sub new {
14##################################################
15    my($class, %options) = @_;
16
17    my $self = $class->SUPER::new(%options);
18    bless $self, $class; # Bless into this class
19
20    if(exists $options{xmlref}) {
21        $self->init_via_xmlref($options{xmlref});
22    }
23
24    return $self;
25}
26
27##################################################
28sub init_via_xmlref {
29##################################################
30    my($self, $xmlref) = @_;
31
32    $self->SUPER::init_via_xmlref($xmlref);
33
34    my $ref = $xmlref->{ItemAttributes};
35
36    $self->authors($ref->{Author});
37    $self->binding($ref->{Binding});
38    $self->dewey_decimal($ref->{DeweyDecimalNumber});
39    $self->numpages($ref->{NumberOfPages});
40    $self->publisher($ref->{Publisher});
41    $self->isbn($ref->{ISBN});
42    $self->edition($ref->{Edition});
43    $self->ean($ref->{EAN});
44
45    my $year = 0;
46    if (defined $ref->{PublicationDate}) {
47        $year =  (split(/\-/, $ref->{PublicationDate}))[0];
48    }
49    $self->year($year);
50
51    $self->publication_date($ref->{PublicationDate});
52}
53
54##################################################
55sub author {
56##################################################
57    my($self, $nameref) = @_;
58
59    # Only return the first author
60    return ($self->authors($nameref))[0];
61}
62
63##################################################
64sub as_string {
65##################################################
66    my($self) = @_;
67
68    my @a = (defined $self->authors) ? $self->authors : qw();
69
70    return join('/', @a) . ", " .
71      '"' . $self->title . '"' . ", " .
72      $self->year . ", " .
73      $self->_best_effort_price() . ", " .
74      $self->ASIN;
75}
76
771;
78
79__END__
80
81=head1 NAME
82
83Net::Amazon::Property::Book - Class for books on amazon.com
84
85=head1 SYNOPSIS
86
87  use Net::Amazon;
88
89  # ...
90
91  if($resp->is_success()) {
92      for my $prop ($resp->properties) {
93          print join("/", $prop->authors()), " ",
94                $prop->title(), " ",
95                $prop->publisher(), " ",
96                $prop->year(), "\n";
97  }
98
99=head1 DESCRIPTION
100
101C<Net::Amazon::Property::Book> is derived from
102C<Net::Amazon::Property> and on top of the all-purpose
103methods the base class provides, it offers specialized accessors for
104book parameters.
105
106=head2 METHODS
107
108=over 4
109
110=item authors()
111
112Returns a list of the book's authors. There's also a C<author()> method
113which just returns the I<first> author.
114
115=item publisher()
116
117Returns the book's publishing company as a string.
118
119=item title()
120
121Returns the book's title as a string.
122
123=item isbn()
124
125Returns the book's ISBN number.
126
127=item edition()
128
129Returns the book's edition.
130
131=item ean()
132
133Returns the book's EAN number.
134
135=item numpages()
136
137Returns the number of pages.
138
139=item dewey_decimal()
140
141Returns the Dewey decimal number, this is for non-fiction only.
142
143This method is deprecated (2011-10-28) as it does not appear to be returned by
144Amazon any more.
145
146=item publication_date()
147
148Returns the publication date.
149
150=item ReleaseDate()
151
152Returns the release date.
153
154For historical reasons, this method used to return the publication date.
155However, as of version Net::Amazon 0.44 the release date is returned, and
156a separate L</publication_date()> method is available.
157
158=item new(xmlref => $xmlref)
159
160Initializes an object by passing a hash of hashes structure containing
161the XML data returned from the service. Usually, this is just used by
162C<Net::Amazon> internally to initialize objects for on backcoming
163data.
164
165=back
166
167Check out L<Net::Amazon::Property> for all-purpose accessors, like
168C<year>, C<OurPrice>, C<ListPrice>, etc.
169
170=head1 AUTHOR
171
172Mike Schilli, E<lt>m@perlmeister.comE<gt>
173
174=head1 COPYRIGHT AND LICENSE
175
176Copyright 2003 by Mike Schilli E<lt>m@perlmeister.comE<gt>
177
178This library is free software; you can redistribute it and/or modify
179it under the same terms as Perl itself.
180
181=cut
182