Metalgate/Review.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 65 CC 3 SCAR 16.1
CC
3
Cov
0%
albums
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.0
1 package WWW::Metalgate::Review;
2  
3 use warnings;
4 use strict;
5  
6 use Moose;
7 use Moose::Util::TypeConstraints;
8 use Web::Scraper;
9 use WWW::Metalgate::Artist;
10 use Text::Trim;
11  
12 =head1 NAME
13  
14 WWW::Metalgate::Review
15  
16 =head1 VERSION
17  
18 Version 0.01
19  
20 =cut
21  
22 our $VERSION = '0.01';
23  
24 subtype 'Artist'
25 => as 'Object'
26 => where { $_->isa('WWW::Metalgate::Artist') };
27  
28 coerce 'Artist'
29 => from 'Str'
30 => via { WWW::Metalgate::Artist->new( name => $_ ) };
31  
32 =head1 FUNCTIONS
33  
34 =head2 artist
35  
36 =cut
37  
38 has 'artist' => (is => 'rw', isa => 'Artist', coerce => 1, required => 1);
39  
40 =head2 albums
41  
42 =cut
43  
44 sub albums {
45 my $self = shift;
46  
47 my $album = sub {
48 my $node = shift;
49 return () unless $node->content_list == 4;
50  
51 my @children = $node->content_list;
52 return {
53 artist => trim($children[0]->as_text),
54 album => trim($children[1]->address(".0")->as_text),
55 point => trim($children[1]->address(".1")->as_text),
56 album_kana => trim($children[2]->as_text),
57 };
58 };
59 my $albums = scraper {
60 process 'table',
61 'albums[]', $album;
62 };
63 my $data_albums = $albums->scrape( $self->artist->html );
64  
65 my $body = sub {
66 my $node = shift;
67 if ($node->find_by_attribute(class => 'line20')) {
68 return $node->as_text;
69 }
70 eles {
71 return ();
72 }
73 };
74 my $bodies = scraper {
75 process 'table',
76 'bodies[]', $body;
77 };
78 my $data_bodies = $bodies->scrape( $self->artist->html );
79  
80 my @albums;
81 for (0 .. $#{ $data_albums->{albums} }) {
82 push @albums, {
83 %{$data_albums->{albums}[$_]},
84 body => $data_bodies->{bodies}[$_],
85 };
86 }
87  
88 return @albums;
89 }
90  
91 =head1 AUTHOR
92  
93 Tomohiro Hosaka, C<< <bokutin at cpan.org> >>
94  
95 =head1 COPYRIGHT & LICENSE
96  
97 Copyright 2008 Tomohiro Hosaka, all rights reserved.
98  
99 This program is free software; you can redistribute it and/or modify it
100 under the same terms as Perl itself.
101  
102 =cut
103  
104 1;