Changeset 33468 for lang/perl/WWW-Allcinema
- Timestamp:
- 05/21/09 08:15:53 (4 years ago)
- Location:
- lang/perl/WWW-Allcinema/trunk
- Files:
-
- 3 modified
-
lib/WWW/Allcinema.pm (modified) (8 diffs)
-
t/01_search.t (modified) (4 diffs)
-
t/03_process_page.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/WWW-Allcinema/trunk/lib/WWW/Allcinema.pm
r33466 r33468 4 4 use warnings; 5 5 use LWP::UserAgent; 6 use HTTP::Request::Common qw(POST);7 6 use HTML::TokeParser; 8 7 use Encode; … … 38 37 my $self = shift; 39 38 $self->_get_page() unless $self->error; 40 return $self->{ matched};39 return $self->{_likely}; 41 40 } 42 41 … … 162 161 if ( $_->{title} =~ /^$title$/ ) { 163 162 $self->id( $_->{id} ); 164 $self->{matched} = [ { id => $_->{id}, title => $title } ]; 165 last; 163 $self->{_likely} = { id => $_->{id}, title => $title }; 166 164 } 167 165 } … … 169 167 unless ( $self->id ) { 170 168 $self->id( $matched->[0]->{id} ); 171 } 172 $self->_get_page(); 169 $self->{_likely} = 170 { id => $matched->[0]->{id}, title => $matched->[0]->{title} }; 171 } 173 172 } 174 173 else { … … 290 289 use WWW::Allcinema; 291 290 my $ac = WWW::Allcinema->new('ゆれる'); 292 print $ac->director; # 西川美和 291 my $result = $ac->search(); 292 $ac->get(); 293 print $ac->director(); # 西川美和 293 294 294 295 =head1 DESCRIPTION … … 304 305 =item new() 305 306 306 Give a film title or allcinema ID . If you give a title, it will search first, and then access to the page of most likely page while it directly goes to the movie information page when given ID.307 Give a film title or allcinema ID or country. If you give a ID, it can directly goes to the movie information page when given ID while it will search first, and then access to the page of most likely page when given other parameters. 307 308 308 309 my $ac = WWW::Allcinema->new('GOEMON'); 309 310 310 or311 312 311 my $ac = WWW::Allcinema->new({id => 330507}); 313 312 313 my $ac = WWW::Allcinema->new({title=>'大捜査線',country=>'香港'}); 314 314 315 =back 315 316 … … 318 319 =over 4 319 320 320 =item title() 321 322 returns title 323 324 =item id() 325 326 returns allcinema ID 327 328 =item year() 329 330 returns year 331 332 =item time() 333 334 returns time by minute 335 336 =item country() 337 338 returns country 339 340 =item genre() 341 342 returns genre arrayref 343 344 =item director() 345 346 returns director 347 348 =item producers() 349 350 returns producers arrayref 351 352 =item screenplay() 353 354 returns screenplay arrayref 355 356 =item cast() 357 358 returns cast arrayref ([{'cast'=>'role'},...,]) 359 360 =item error() 361 362 returns error message. 363 364 if($ac->error){ 365 print "error: $ac->error"; 366 } 321 =item search() 322 323 searches by given constructor parameters and returns most likely result. 324 325 my $result = $ac->search(); 326 print "id: $result->{id}, title: $result->{title}"; 367 327 368 328 =item matched() 369 329 370 returns id and title of search result 371 330 returns all search results 331 332 $ac->search(); 372 333 my $matched = $ac->matched; 373 334 if($matched){ … … 377 338 } 378 339 340 =item title() 341 342 returns title 343 344 =item id() 345 346 returns allcinema ID 347 348 =item year() 349 350 returns year 351 352 =item time() 353 354 returns time by minute 355 356 =item country() 357 358 returns country 359 360 =item genre() 361 362 returns genre arrayref 363 364 =item director() 365 366 returns director 367 368 =item producers() 369 370 returns producers arrayref 371 372 =item screenplay() 373 374 returns screenplay arrayref 375 376 =item cast() 377 378 returns cast arrayref ([{'cast'=>'role'},...,]) 379 380 =item error() 381 382 returns error message. 383 384 if($ac->error){ 385 print "error: $ac->error"; 386 } 387 388 379 389 =back 380 390 -
lang/perl/WWW-Allcinema/trunk/t/01_search.t
r33466 r33468 10 10 my $result = $ac->search(); 11 11 is_deeply( $result, 12 [ { id => 51832, title => 'トレインスポッティング' } ],12 { id => 51832, title => 'トレインスポッティング' }, 13 13 'title scalar' ); 14 14 … … 17 17 is_deeply( 18 18 $result, 19 [ 20 { 21 id => 150405, 22 title => '機動戦士ガンダム 逆襲のシャア' 23 } 24 ], 19 { 20 id => 150405, 21 title => '機動戦士ガンダム 逆襲のシャア', 22 }, 25 23 'title hash' 26 24 ); … … 30 28 $result = $ac->search(); 31 29 is_deeply( 32 $result ->[0],30 $result, 33 31 { id => 4998, title => 'ガンジー' }, 34 32 'title and country' … … 38 36 { 'country' => [ ( 'スウェーデン', '日本' ) ] } ); 39 37 $result = $ac->search(); 40 is_deeply( $result->[0], { id => 12977, title => '戦争の顔' }, 41 'countries' ); 38 is_deeply( $result, { id => 12977, title => '戦争の顔' }, 'countries' ); 42 39 43 40 $ac = WWW::Allcinema->new('ゆれる'); 44 41 $result = $ac->search(); 45 is_deeply( 46 $result, 47 [ { id => 324256, title => 'ゆれる' } ], 48 'some candidates' 49 ); 42 is_deeply( $result, { id => 324256, title => 'ゆれる' }, 'some candidates' ); 50 43 -
lang/perl/WWW-Allcinema/trunk/t/03_process_page.t
r33466 r33468 83 83 84 84 $ac = WWW::Allcinema->new('崖の上のポニョ'); 85 $ac->search(); 85 86 $ac->get(); 86 87 87 is( $ac->title, '崖の上のポニョ', 'title' ); 88 88 is( $ac->year, 2008, 'year' ); … … 96 96 is_deeply( $ac->music, [qw(久石譲)], 'music' ); 97 97 98 # $ac = WWW::Allcinema->new('ダイハード'); 99 # $ac->get(); 100 # is( $ac->title, 'ダイ・ハード', 'more than two candidates not matched' ); 101 102 # $ac = WWW::Allcinema->new( { id => 766 } ); 103 # $ac->get(); 104 # is_deeply( 105 # $ac->country, 106 # [qw(アメリカ ニュージーランド)], 107 # 'multi countries' 108 # ); 98 $ac = WWW::Allcinema->new( { id => 766 } ); 99 $ac->get(); 100 is_deeply( 101 $ac->country, 102 [qw(アメリカ ニュージーランド)], 103 'multi countries' 104 );
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)