1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl 1.t'
3
4#########################
5
6# change 'tests => 1' to 'tests => last_test_to_print';
7
8use warnings;
9use strict;
10
11use Test::More qw(no_plan);
12BEGIN { use_ok('Net::Amazon') };
13
14#use Log::Log4perl qw(:easy);
15#Log::Log4perl->easy_init($INFO);
16
17use Net::Amazon::Request::ASIN;
18use Net::Amazon::Response::ASIN;
19use File::Spec;
20
21my $CANNED = "canned";
22$CANNED = File::Spec->catfile("t", "canned") unless -d $CANNED;
23
24if(! exists $ENV{NET_AMAZON_LIVE_TESTS}) {
25    for(map { File::Spec->catfile($CANNED, $_) }
26        qw(reviews.xml)) {
27        open FILE, "<$_" or die "Cannot open $_";
28        my $data = join '', <FILE>;
29        close FILE;
30        push @Net::Amazon::CANNED_RESPONSES, $data;
31    }
32}
33
34######################################################################
35# Successful ASIN fetch
36######################################################################
37my $ua = Net::Amazon->new(
38    associate_tag => 'YOUR_AMZN_ASSOCIATE_TAG',
39    token       => 'YOUR_AMZN_TOKEN',
40    secret_key  => 'YOUR_AMZN_SECRET_KEY',
41);
42
43my $req = Net::Amazon::Request::ASIN->new(
44    asin  => '0201360683'
45);
46
47my $resp = $ua->request($req);
48
49ok($resp->is_success(), "Successful ASIN fetch");
50
51my $result = "";
52
53for my $property ($resp->properties()) {
54    my $reviewset = $property->review_set();
55    $result .= "AVG=" . $reviewset->average_customer_rating() . "," .
56               "TOT=" . $reviewset->total_reviews() . ",";
57    for my $review ($reviewset->reviews()) {
58        $result .= "COM=" . $review->content() . "," .
59                   "SUM=" . $review->summary() . "," .
60                   "RAT=" . $review->rating() . "," .
61                   "LOC=" . $review->customer_location() . "," .
62                   "NAM=" . $review->customer_name();
63    }
64}
65
66# XXX: this information is no longer readily available.
67# like($result, qr/AVG=4.5,TOT=6,COM=From.*?RAT=4,LOC=Enschede.*?,NAM=C.\sHulshof
68#                                COM=Excellent.*?SUM=Perl.*?RAT=5.*?
69#                                COM=I\sbought.*?SUM=Don.*?RAT=2.*?
70#                 /sx, "customer reviews");
71__END__
72
73AVG=4.33,TOT=6,COM=From its corny title you might expect another one of those sleazy introductions to Perl (I can name a few), but I can happily say that this book is an exception. The overview of the language is excellent and very comprehensible. Even after reading Learning Perl and Programming Perl, I picked up some valuable tips. The chapters on Object Oriented Programming and Perl/Tk are also good. For the Perl/CGI part, you might consider reading additional material, however. All in all, a surprisingly good introduction and reference to Perl 5, both for the beginner and the more advanced programmer.,SUM=Good introduction to Perl, and great reference,RAT=4,COM=Excellent book that gets you started with lots of areas of perl. Most of the code I have tried works fine with Activestates's 523 build and with the perl development kit 1.2.4. Having code that work is rare with these books especially with Windows. I use 98 and NT and unix. This book is not a diffinitive guide to perl but it gives you a good summay in most of the important area's and enought code to get started quickly. It gave me lots of ideas on things I could use perl for. I also like "Perl 5 complete" for theory, but the code for that book is very buggy and hard to get to work. I like its detailed explanation of how things are suppose to work. "Perl Cookbook" is also excellent for how to solve problems various kinds of problems. These are the best of the perl books I have.,SUM=Perl power,RAT=5,COM=I bought this book based on the 5-star reviews - never do THAT again......long on abstract examples that don't mirror the real world, short on logical explanations for the common man(woman).. I have had several other PERL books from the local library that were much better (Castros book is good, don't believe the condescending reviews) - not for the CGI web programmer,SUM=Don't buy this book for CGI programming,RAT=2,
74
75