| 1 | package WebService::SyoboiCalendar::API::Search; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Smart::Args; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Web::Query; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | Readonly my $API_SEARCH => "http://cal.syoboi.jp/find"; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | has api => ( | |||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has mode => ( | |||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my %field_to_param = ( | |||||||||||||||||||||||||||
| 21 | title => 'kw', | ||||||||||||||||||||||||||||
| 22 | channel => 'ch', | ||||||||||||||||||||||||||||
| 23 | subtitle => 'st', | ||||||||||||||||||||||||||||
| 24 | comment => 'cm', | ||||||||||||||||||||||||||||
| 25 | fresh => 'pfn', # 新番組 | ||||||||||||||||||||||||||||
| 26 | final => 'pfl', # 最終回 | ||||||||||||||||||||||||||||
| 27 | special => 'pfs', # 特番 | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | for my $field (keys %field_to_param) { | |||||||||||||||||||||||||||
| 31 | 14 | has $field => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | has range => ( is => 'rw'); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | args my $self; | |||||||||||||||||||||||||||
| 38 | 0 | my $content = $self->api->get( $self->request_url )->content; | |||||||||||||||||||||||||||
| 39 | 0 | my $scraper = 'scrape_search_' . $self->mode; | |||||||||||||||||||||||||||
| 40 | 0 | $self->$scraper($content); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub request_url { | ||||||||||||||||||||||||||
|
Subroutine
request_url: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | args my $self; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | my $url = URI->new( $API_SEARCH ); | |||||||||||||||||||||||||||
| 47 | my %params = ( | ||||||||||||||||||||||||||||
| 48 | sd => { | ||||||||||||||||||||||||||||
| 49 | title => 0, | ||||||||||||||||||||||||||||
| 50 | program => 2, | ||||||||||||||||||||||||||||
| 51 | 0 | }->{$self->mode}, | |||||||||||||||||||||||||||
| 52 | uuc => 1, # ユーザ設定を使う | ||||||||||||||||||||||||||||
| 53 | v => 0, # リスト | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | for my $key (keys %field_to_param) { | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | next unless $self->$key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $params{$field_to_param{$key}} = $self->$key; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $range = $self->range || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->range || ''
MC/DC0%0/1
$self->range || ''
$self->range
Truth table0%0/2
A
A= $self->range
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($range eq 'all') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 63 | 0 | $params{r} = 0; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | elsif ($range eq 'past') { | ||||||||||||||||||||||||||||
| 66 | 0 | $params{r} = 1; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | elsif ($range eq 'future') { | ||||||||||||||||||||||||||||
| 69 | 0 | $params{r} = 2; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||
| 72 | 0 | $params{r} = 3; | |||||||||||||||||||||||||||
| 73 | 0 | $params{rd} = $range; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | $url->query_form( \%params ); | |||||||||||||||||||||||||||
| 76 | 0 | return $url; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub _scrape { | ||||||||||||||||||||||||||
|
Subroutine
_scrape: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 80 | 0 | args_pos my $self, my $content, my $query; | |||||||||||||||||||||||||||
| 81 | 0 | my $results = []; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | wq($content)->find($query)->each( sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 83 | 0 | my ($i, $elem) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | my $href = $elem->attr('href'); | |||||||||||||||||||||||||||
| 85 | 0 | my ($tid, $pid) = $href =~ m!^/tid/(\d+)(?:/time\#(\d+))?$!xms; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | push @$results, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tid or $pid
MC/DC0%0/2
$tid or $pid
$tid
$pid
Truth table0%0/3
A or B
A= $tidB= $pid
| |||||||||||||||||||||||||||||
| 87 | TID => $tid, | ||||||||||||||||||||||||||||
| 88 | PID => $pid, | ||||||||||||||||||||||||||||
| 89 | } if ($tid || $pid); | ||||||||||||||||||||||||||||
| 90 | 0 | }); | |||||||||||||||||||||||||||
| 91 | 0 | $results; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub scrape_search_title { | ||||||||||||||||||||||||||
|
Subroutine
scrape_search_title: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 0 | args_pos my $self, my $content; | |||||||||||||||||||||||||||
| 96 | 0 | $self->_scrape($content, '.tframe tr td:nth-child(1) a'); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub scrape_search_program { | ||||||||||||||||||||||||||
|
Subroutine
scrape_search_program: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | args_pos my $self, my $content; | |||||||||||||||||||||||||||
| 101 | 0 | $self->_scrape($content, '.tframe tr td:nth-child(2) a'); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | 1; | |||||||||||||||||||||||||||