File: Review.pm

package info (click to toggle)
libnet-amazon-perl 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,400 kB
  • ctags: 2,271
  • sloc: xml: 20,530; perl: 19,997; makefile: 9
file content (164 lines) | stat: -rw-r--r-- 3,880 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
######################################################################
package Net::Amazon::Attribute::Review;
######################################################################
use warnings;
use strict;
use Log::Log4perl qw(:easy);
use base qw(Net::Amazon);

__PACKAGE__->make_accessor($_) for qw(date asin rating summary content 
                                      total_votes helpful_votes customer_id
				      customer_name customer_location);

use constant ELEMENT_TO_METHOD_MAP => {
    # XXX: should ASIN be Asin, ASIN, or asin?
    'ASIN'         => 'asin',
    'Content'      => 'content',
    'CustomerId'   => 'customer_id',
    'CustomerLocation' => 'customer_location',
    'CustomerName' => 'customer_name',
    'Date'         => 'date',
    'HelpfulVotes' => 'helpful_votes',
    'Rating'       => 'rating',
    'Summary'      => 'summary',
    'TotalVotes'   => 'total_votes',
};

##################################################
sub new {
##################################################
    my($class, %options) = @_;

    my $self = {
        rating  => "",
        summary => "",
        content => "",
        helpful_votes => "",
        customer_id => "",
        customer_name => "",
        customer_location => "",
        asin => "",
        date => "",
        total_votes => "",
        %options,
    };

    bless $self, $class;
}

##################################################
sub init_via_xmlref {
##################################################
    my($self, $xmlref) = @_;

    my $href = (ELEMENT_TO_METHOD_MAP);

    for(keys %$href) {
        my $method = lc($href->{$_});
        if(defined $xmlref->{$_}) {
            $self->$method($xmlref->{$_});
        } 
    }

    $self->customer_location($xmlref->{Reviewer}{Location});
    $self->customer_name($xmlref->{Reviewer}{Name});
}

1;

__END__

=head1 NAME

Net::Amazon::Attribute::Review - Customer Review Class

=head1 SYNOPSIS

    use Net::Amazon::Attribute::Review;
    my $rev = Net::Amazon::Attribute::Review->new(
                 'rating'        => $rating,
                 'summary'       => $summary,
                 'content'       => $content,
                 'asin'          => $asin,
                 'customer_id'   => $customer_id,
                 'date'          => $date,
                 'helpful_votes' => $helpful_votes,
                 'total_votes'   => $total_votes,
    );

=head1 DESCRIPTION

C<Net::Amazon::Attribute::Review> holds customer reviews.

=head2 METHODS

=over 4

=item rating()

Accessor for the numeric value of the rating.

=item summary()

Accessor for the string value of the summary.

=item content()

Accessor for the string value of the content.

=item asin()

Accessor for the string value of ASIN.

=item customer_id()

Accessor for the string value of the customer ID.

=item customer_location()

Accessor for the string value of the customer location.

=item customer_name()

Accessor for the string value of the customer name.

=item helpful_votes()

Accessor for the numeric value of the helpful votes.

=item total_votes()

Accessor for the numeric value of the total votes.

=back

=head1 AUTHOR

Mike Schilli, E<lt>m@perlmeister.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright 2003 by Mike Schilli E<lt>m@perlmeister.comE<gt>

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. 

=cut

__END__
<Review>
  <ASIN>0201360683</ASIN>
  <Rating>4</Rating>
  <HelpfulVotes>2</HelpfulVotes>
  <CustomerId>YYYYYYYXXYYYY</CustomerId>
  <Reviewer>
    <CustomerId>YYYYYYYXXYYYY</CustomerId>
    <Name>John Doe</Name>
    <Nickname>JD</Nickname>
    <Location>New York, NY USA</Location>
  </Reviewer>
  <TotalVotes>2</TotalVotes>
  <Date>2000-03-09</Date>
  <Summary>Wicked Pisser!</Summary>
  <Content>I found this book to be very good</Content>
</Review>