| 1 | # $Id: JASRAC.pm 1 2006-03-14 18:30:19Z daisuke $ | ||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 2006 Daisuke Maki <dmaki@cpan.org> | ||||||||||||||||||||||||||||||||
| 4 | # All rights reserved. | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | package WWW::JASRAC; | ||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Encode qw(encode decode); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use HTML::TreeBuilder; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use WWW::JASRAC::Result; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 2 | $VERSION = '0.01' | |||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use constant O_NAIGAI => 'naigai'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use constant O_DOMESTIC => 'naikoku'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use constant O_INTL => 'gaikoku'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use constant O_ZENPOU => 'zenpou'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use constant O_BUBUN => 'bubun'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use constant O_KOHO => 'koho'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use constant O_KANZEN => 'kanzen'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use constant DEFAULT_OE => 'euc-jp'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use constant DEFAULT_IE => 'euc-jp'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | sub new | ||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 30 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 31 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 32 | my $self = bless { | ||||||||||||||||||||||||||||||||
| 33 | ie => $args{ie} || DEFAULT_OE, | ||||||||||||||||||||||||||||||||
| 34 | oe => $args{oe} || DEFAULT_IE, | ||||||||||||||||||||||||||||||||
| 35 | ua => LWP::UserAgent->new, | ||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | uri => $args{uri} || 'http://www2.jasrac.or.jp/cgi-bin/db2www/jwid040.d2w/report', | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$args{'ie'} || 'euc-jp'
$args{'oe'} || 'euc-jp'
$args{'uri'} || 'http://www2.jasrac.or.jp/cgi-bin/db2www/jwid040.d2w/report'
MC/DC0%0/1
$args{'ie'} || 'euc-jp'
$args{'ie'}
MC/DC0%0/1
$args{'oe'} || 'euc-jp'
$args{'oe'}
MC/DC0%0/1
$args{'uri'} || 'http://www2.jasrac.or.jp/cgi-bin/db2www/jwid040.d2w/report'
$args{'uri'}
Truth table0%0/2
A
A= $args{'ie'}
Truth table0%0/2
A
A= $args{'oe'}
Truth table0%0/2
A
A= $args{'uri'}
| |||||||||||||||||||||||||||||||||
| 37 | }, $class; | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | sub search | ||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=35 SCAR=71.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 46 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $ie = $args{ie} || $self->{ie}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'ie'} || $self->{'ie'}
MC/DC0%0/2
$args{'ie'} || $self->{'ie'}
$args{'ie'}
$self->{'ie'}
Truth table0%0/3
A || B
A= $args{'ie'}B= $self->{'ie'}
| |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $oe = $args{oe} || $self->{oe}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'oe'} || $self->{'oe'}
MC/DC0%0/2
$args{'oe'} || $self->{'oe'}
$args{'oe'}
$self->{'oe'}
Truth table0%0/3
A || B
A= $args{'oe'}B= $self->{'oe'}
| |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | my $ua = $self->{ua}; | |||||||||||||||||||||||||||||||
| 52 | 0 | my %form = ( | |||||||||||||||||||||||||||||||
| 53 | Naigai => 'naigai', | ||||||||||||||||||||||||||||||||
| 54 | Kensu => 110, | ||||||||||||||||||||||||||||||||
| 55 | # ºîÉÊ̾ | ||||||||||||||||||||||||||||||||
| 56 | L_SakJ => undef, | ||||||||||||||||||||||||||||||||
| 57 | K_SakJ => undef, # Á°Êý¡¿Éôʬ¡¿¸åÊý¡¿´°Á´°ìÃ× | ||||||||||||||||||||||||||||||||
| 58 | L_SakK => undef, | ||||||||||||||||||||||||||||||||
| 59 | K_SakK => undef, # Á°Êý¡¿Éôʬ¡¿¸åÊý¡¿´°Á´°ìÃ× | ||||||||||||||||||||||||||||||||
| 60 | # ¸¢Íø¼Ô̾ | ||||||||||||||||||||||||||||||||
| 61 | L_KenJ => undef, | ||||||||||||||||||||||||||||||||
| 62 | K_KenJ => undef, | ||||||||||||||||||||||||||||||||
| 63 | L_KenK => undef, | ||||||||||||||||||||||||||||||||
| 64 | K_KenK => undef, | ||||||||||||||||||||||||||||||||
| 65 | # ¥¢¡¼¥Æ¥£¥¹¥È̾ | ||||||||||||||||||||||||||||||||
| 66 | L_KasJ => undef, | ||||||||||||||||||||||||||||||||
| 67 | K_KasJ => undef, | ||||||||||||||||||||||||||||||||
| 68 | L_KasK => undef, | ||||||||||||||||||||||||||||||||
| 69 | K_KasK => undef, | ||||||||||||||||||||||||||||||||
| 70 | # ºîÉÊ¥³¡¼¥É | ||||||||||||||||||||||||||||||||
| 71 | L_SakC => undef, | ||||||||||||||||||||||||||||||||
| 72 | K_SakC => undef, | ||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($args{code}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | my $f = ref($args{code}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $args{code} : { text => $args{code} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 0 | $form{L_SakC} = $f->{text}; | |||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $form{K_SakC} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ($args{title}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | my $f = ref($args{title}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $args{title} : { text => $args{title} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 0 | $form{L_SakJ} = $f->{text}; | |||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $form{K_SakJ} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($args{title_yomi}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | my $f = ref($args{title_yomi}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $args{title_yomi} : { text => $args{title_yomi} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 0 | $form{L_SakK} = $f->{text}; | |||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $form{K_SakK} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($args{rights_holder}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | my $f = ref($args{rights_holder}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $args{rights_holder} : { text => $args{rights_holder} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | 0 | $form{L_KenJ} = $f->{text}; | |||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $form{K_KenJ} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($args{rights_holder_yomi}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | my $f = ref($args{rights_holder_yomi}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $args{rights_holder_yomi} : { text => $args{rights_holder_yomi} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | 0 | $form{L_KenK} = $f->{text}; | |||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $form{K_KenK} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($args{artist}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | my $f = ref($args{artist}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | $args{artist} : { text => $args{artist} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 0 | $form{L_KasJ} = $f->{text}; | |||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $form{K_KasJ} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($args{artist_yomi}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | my $f = ref($args{artist_yomi}) eq 'HASH' ? | ||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $args{artist_yomi} : { text => $args{artist_yomi} }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | 0 | $form{L_KasK} = $f->{text}; | |||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $form{K_KasK} = $f->{option} || O_KANZEN; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$f->{'option'} || 'kanzen'
MC/DC0%0/1
$f->{'option'} || 'kanzen'
$f->{'option'}
Truth table0%0/2
A
A= $f->{'option'}
| |||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 0 | foreach my $key (keys %form) { | |||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless ($form{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | 0 | delete $form{$key} ; | |||||||||||||||||||||||||||||||
| 127 | 0 | next ; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | 0 | $form{$key} = encode('sjis', decode($ie, $form{$key})); | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | 0 | my $response = $ua->post($self->{uri}, \%form); | |||||||||||||||||||||||||||||||
| 133 | 0 | my $content = $response->content; | |||||||||||||||||||||||||||||||
| 134 | 0 | my $original_encoding; | |||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($response->header('Content-Type') =~ /charset=([\w-]+)/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | 0 | $original_encoding = $1; | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $original_encoding ||= 'sjis'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$original_encoding ||= "sjis"
MC/DC0%0/1
$original_encoding ||= "sjis"
$original_encoding
Truth table0%0/2
A
A= $original_encoding
| |||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | $content = encode($oe, decode($original_encoding, $content)); | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ($content =~ /³ºÅö¤¹¤ë¥Ç¡¼¥¿¤Ï¸ºß¤·¤Þ¤»¤ó¤Ç¤·¤¿/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 0 | my @ret; | |||||||||||||||||||||||||||||||
| 147 | 0 | my $tree = HTML::TreeBuilder->new_from_content($content); | |||||||||||||||||||||||||||||||
| 148 | 0 | foreach my $row ($tree->look_down(_tag => 'tr')) { | |||||||||||||||||||||||||||||||
| 149 | 0 | my @list = $row->content_list; | |||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | next unless ref $list[0]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | next unless $list[0]->as_text =~ /^([\d-]+)<\d+>$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 0 | my $title = ($list[1]->look_down(_tag => 'a')); | |||||||||||||||||||||||||||||||
| 154 | push @ret, WWW::JASRAC::Result->new( | ||||||||||||||||||||||||||||||||
| 155 | code => $1, | ||||||||||||||||||||||||||||||||
| 156 | link => $title->attr('href'), | ||||||||||||||||||||||||||||||||
| 157 | text => encode($self->{oe}, decode('euc-jp', $title->as_text)), | ||||||||||||||||||||||||||||||||
| 158 | rights => [ | ||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | grep { length($_) && !/^\s+$/ } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
length $_ && !/^\s+$/
MC/DC0%0/2
length $_ && !/^\s+$/
length $_
!/^\s+$/
Truth table0%0/3
A && not(B)
A= length $_B= !/^\s+$/
| |||||||||||||||||||||||||||||||||
| 160 | 0 | map { s/¡¡/ /g; s/\s$//; s/^\s+//; s/\s+/ /g; | |||||||||||||||||||||||||||||||
| 161 | 0 | encode($self->{oe}, decode('euc-jp', $_)) } | |||||||||||||||||||||||||||||||
| 162 | 0 | grep { !ref($_) } | |||||||||||||||||||||||||||||||
| 163 | $list[2]->content_list ], | ||||||||||||||||||||||||||||||||
| 164 | artists => [ | ||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | grep { length($_) && !/^\s+$/ } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
length $_ && !/^\s+$/
MC/DC0%0/2
length $_ && !/^\s+$/
length $_
!/^\s+$/
Truth table0%0/3
A && not(B)
A= length $_B= !/^\s+$/
| |||||||||||||||||||||||||||||||||
| 166 | 0 | map { s/¡¡/ /g; s/\s$//; s/^\s+//; s/\s+/ /g; | |||||||||||||||||||||||||||||||
| 167 | 0 | encode($self->{oe}, decode('euc-jp', $_)) } | |||||||||||||||||||||||||||||||
| 168 | 0 | grep { !ref($_) } | |||||||||||||||||||||||||||||||
| 169 | $list[3]->content_list ], | ||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | 0 | $tree->delete; | |||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return wantarray ? @ret : \@ret; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | 2 | 1; | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | __END__ | ||||||||||||||||||||||||||||||||