File Coverage

lib/WWW/Mixi/Scraper/Plugin/ViewBBS.pm
Criterion Covered Total %
statement 12 50 24.0
branch 0 8 0.0
condition n/a
subroutine 4 9 44.4
pod 1 1 100.0
total 17 68 25.0


line stmt bran cond sub pod time code
1             package WWW::Mixi::Scraper::Plugin::ViewBBS;
2            
3 1     1   928 use strict;
  1         2  
  1         36  
4 1     1   5 use warnings;
  1         2  
  1         24  
5 1     1   5 use WWW::Mixi::Scraper::Plugin;
  1         2  
  1         8  
6 1     1   6 use WWW::Mixi::Scraper::Utils qw( _datetime _uri );
  1         1  
  1         637  
7            
8             validator {qw(
9             id is_number
10             comm_id is_number
11             comment_count is_number
12             page is_number_or_all
13             )};
14            
15             sub scrape {
16 0     0 1   my ($self, $html) = @_;
17            
18 0           my %scraper;
19             $scraper{images} = scraper {
20 0     0     process 'a',
21             link => '@onClick';
22 0           process 'a>img',
23             thumb_link => '@src';
24 0           result qw( link thumb_link );
25 0           };
26            
27             $scraper{topic} = scraper {
28 0     0     process 'dl[class="bbsList01 bbsDetail"]>dt>span.date',
29             time => 'TEXT';
30 0           process 'dl[class="bbsList01 bbsDetail"]>dt>span.titleSpan',
31             subject => 'TEXT';
32 0           process 'dd.bbsContent>dl>dt>a',
33             name => 'TEXT',
34             name_link => '@href';
35 0           process 'dd.bbsContent>dl>dd',
36             description => $self->html_or_text;
37 0           process 'dd.bbsContent>dl>dd>div.communityPhoto>table>tr>td',
38             'images[]' => $scraper{images};
39 0           result qw( time subject description name name_link images link );
40 0           };
41            
42             # bbs topic is not an array
43 0           my $stash = $self->post_process($scraper{topic}->scrape(\$html))->[0];
44            
45             # XXX: this fails when you test with local files.
46             # However, this link cannot be extracted from the html,
47             # at least as of writing this. ugh.
48 0           $stash->{link} = $self->{uri};
49            
50             $scraper{comments} = scraper {
51 0     0     process 'dt>a',
52             link => '@href',
53             name => 'TEXT';
54 0           process 'dd',
55             description => $self->html_or_text;
56 0           result qw( link name description );
57 0           };
58            
59             $scraper{list} = scraper {
60 0     0     process 'dl.commentList01>dt[class="commentDate clearfix"]>span.date',
61             'times[]' => 'TEXT';
62 0           process 'dl.commentList01>dt[class="commentDate clearfix"]>span.senderId',
63             'sender_ids[]' => 'TEXT';
64 0           process 'dl.commentList01>dd>dl.commentContent01',
65             'comments[]' => $scraper{comments};
66 0           result qw( times sender_ids comments );
67 0           };
68            
69 0           my $stash_c = $self->post_process($scraper{list}->scrape(\$html))->[0];
70            
71 0 0         my @comments = @{ $stash_c->{comments} || [] };
  0            
72 0 0         my @times = @{ $stash_c->{times} || [] };
  0            
73 0 0         my @sender_ids = @{ $stash_c->{sender_ids} || [] };
  0            
74 0           foreach my $comment ( @comments ) {
75 0           $comment->{time} = _datetime( shift @times );
76 0           $comment->{subject} = shift @sender_ids;
77            
78             # incompatible with WWW::Mixi to let comment links
79             # look more 'permanent' to make plagger/rss readers happier
80 0           $comment->{name_link} = _uri( $comment->{link} );
81 0 0         $comment->{link} = $stash->{link}
82             ? _uri( $stash->{link} . '#' . $comment->{subject} )
83             : undef;
84             }
85 0           $stash->{comments} = \@comments;
86            
87 0           return $stash;
88             }
89            
90             1;
91            
92             __END__