| 1 | package WWW::Mixi::Scraper::Plugin::ShowFriend; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use WWW::Mixi::Scraper::Plugin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use WWW::Mixi::Scraper::Utils qw( _uri ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | validator {qw( id is_number )}; | |||||||||||
| 10 | |||||||||||||
| 11 | 0 | ▶ | sub scrape { | ||||||||||
|
Subroutine
scrape: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 12 | 0 | my ($self, $html) = @_; | |||||||||||
| 13 | |||||||||||||
| 14 | return { | ||||||||||||
| 15 | 0 | profile => $self->_scrape_profile($html), | |||||||||||
| 16 | outline => $self->_scrape_outline($html), | ||||||||||||
| 17 | }; | ||||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | 0 | ▶ | sub _scrape_profile { | ||||||||||
|
Subroutine
_scrape_profile: not called CC=3 SCAR=24.8
| |||||||||||||
| 21 | 0 | my ($self, $html) = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | 0 | my %scraper; | |||||||||||
| 24 | 0 | ▶ | $scraper{items} = scraper { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 25 | 0 | process 'th', | |||||||||||
| 26 | key => 'TEXT'; | ||||||||||||
| 27 | 0 | process 'td', | |||||||||||
| 28 | value => $self->html_or_text; | ||||||||||||
| 29 | 0 | result qw( key value ); | |||||||||||
| 30 | 0 | }; | |||||||||||
| 31 | |||||||||||||
| 32 | 0 | ▶ | $scraper{profile} = scraper { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 33 | process 'div.profileListTable>div>table>tr', | ||||||||||||
| 34 | 0 | 'items[]' => $scraper{items}; | |||||||||||
| 35 | 0 | result qw( items ); | |||||||||||
| 36 | 0 | }; | |||||||||||
| 37 | |||||||||||||
| 38 | 0 | my $stash = $self->post_process($scraper{profile}->scrape(\$html)); | |||||||||||
| 39 | |||||||||||||
| 40 | 0 | my $profile = {}; | |||||||||||
| 41 | 0 | foreach my $item ( @{ $stash } ) { | |||||||||||
| 42 | 0 | ▶ | next unless $item->{key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | $profile->{$item->{key}} = $item->{value}; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | return $profile; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | sub _scrape_outline { | ||||||||||
|
Subroutine
_scrape_outline: not called CC=4 SCAR=30.0
| |||||||||||||
| 50 | 0 | my ($self, $html) = @_; | |||||||||||
| 51 | |||||||||||||
| 52 | 0 | my %scraper; | |||||||||||
| 53 | 0 | ▶ | $scraper{outline} = scraper { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 54 | 0 | process 'div#myArea>div.profilePhoto>div.contents>p.name', | |||||||||||
| 55 | 'string' => 'TEXT'; | ||||||||||||
| 56 | 0 | process 'div#myArea>div.profilePhoto>div.contents>p.name>span.loginTime', | |||||||||||
| 57 | 'description' => 'TEXT'; | ||||||||||||
| 58 | 0 | process 'div#myArea>div.profilePhoto>div.contents>p.photo>a>img', | |||||||||||
| 59 | image => '@src'; | ||||||||||||
| 60 | 0 | process 'div.personalNavigation>ul>li.profile>a', | |||||||||||
| 61 | link => '@href'; | ||||||||||||
| 62 | 0 | result qw( image string description link ); | |||||||||||
| 63 | 0 | }; | |||||||||||
| 64 | |||||||||||||
| 65 | 0 | my $stash = $self->post_process($scraper{outline}->scrape(\$html))->[0]; | |||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | my $string = delete $stash->{string} || ''; | ||||||||||
|
Condition0%0/2
delete $stash->{'string'} || ''
MC/DC0%0/1
delete $stash->{'string'} || ''
delete $stash->{'string'}
Truth table0%0/2
A
A= delete $stash->{'string'}
| |||||||||||||
| 68 | 0 | ▶ | if ( $string =~ s/さん\((\d+)\)\s.+// ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 0 | $stash->{name} = $string; | |||||||||||
| 70 | 0 | $stash->{count} = $1; | |||||||||||
| 71 | } | ||||||||||||
| 72 | 0 | ▶ | if ( $stash->{description} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 0 | $stash->{description} =~ s/^(//; | |||||||||||
| 74 | 0 | $stash->{description} =~ s/)$//; | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | 0 | return $stash; | |||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | 1 | 1; | |||||||||||
| 81 | |||||||||||||
| 82 | __END__ | ||||||||||||