| 1 | ###################################################################### | ||||||||||
| 2 | package Net::Amazon::Attribute::ReviewSet; | ||||||||||
| 3 | ###################################################################### | ||||||||||
| 4 | 24 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 24 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 24 | ▶ | use Log::Log4perl qw(:easy); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 24 | ▶ | use Net::Amazon::Attribute::Review; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 24 | ▶ | use base qw(Net::Amazon); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 24 | __PACKAGE__->make_accessor($_) for qw(average_customer_rating total_reviews | |||||||||
| 11 | total_review_pages); | ||||||||||
| 12 | |||||||||||
| 13 | ################################################## | ||||||||||
| 14 | 329 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 15 | ################################################## | ||||||||||
| 16 | 329 | my($class, %options) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 329 | my $self = { | |||||||||
| 19 | reviews => [], # list of reviews | ||||||||||
| 20 | }; | ||||||||||
| 21 | |||||||||||
| 22 | 329 | bless $self, $class; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | ########################################### | ||||||||||
| 26 | 0 | ▶ | sub add_review { | ||||||||
|
Subroutine
add_review: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 27 | ########################################### | ||||||||||
| 28 | 0 | my($self, $review) = @_; | |||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | if(ref $review ne "Net::Amazon::Attribute::Review") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | warn "add_review called with type ", ref $review; | |||||||||
| 32 | 0 | return undef; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | push @{$self->{reviews}}, $review; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | ########################################### | ||||||||||
| 39 | 1 | ▶ | sub reviews { | ||||||||
|
Subroutine
reviews: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | ########################################### | ||||||||||
| 41 | 1 | my($self) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 1 | return @{$self->{reviews}}; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | ################################################## | ||||||||||
| 47 | 1 | ▶ | sub init_via_xmlref { | ||||||||
|
Subroutine
init_via_xmlref: called CC=4 SCAR=16.8
Pod
undocumented
| |||||||||||
| 48 | ################################################## | ||||||||||
| 49 | 1 | my($self, $xmlref) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 1 | my @pairs = qw(AverageRating average_customer_rating | |||||||||
| 52 | TotalReviews total_reviews | ||||||||||
| 53 | TotalReviewPages total_review_pages); | ||||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | while(my($field, $method) = splice @pairs, 0, 2) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | |||||||||||
| 57 | 3 | ▶ | if(exists $xmlref->{$field}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | DEBUG "Setting $field via $method to $xmlref->{$field}"; | |||||||||
| 59 | 0 | $self->$method($xmlref->{$field}); | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 1 | for my $review_xmlref (@{$xmlref->{Review}}) { | |||||||||
| 64 | 0 | my $review = Net::Amazon::Attribute::Review->new(); | |||||||||
| 65 | 0 | $review->init_via_xmlref($review_xmlref); | |||||||||
| 66 | 0 | DEBUG "Adding review ", $review->summary(); | |||||||||
| 67 | 0 | $self->add_review($review); | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 24 | 1; | |||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||