| 1 | package WWW::Metalgate::Column; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use MooseX::Types::URI qw(Uri FileUri DataUri); | ||
| 8 | use Web::Scraper; | ||
| 9 | use WWW::Metalgate::Year; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | WWW::Metalgate::Column | ||
| 14 | |||
| 15 | =head1 VERSION | ||
| 16 | |||
| 17 | Version 0.02 | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | our $VERSION = '0.02'; | ||
| 22 | |||
| 23 | =head1 SYNOPSIS | ||
| 24 | |||
| 25 | use WWW::Metalgate::Column; | ||
| 26 | use XXX; | ||
| 27 | |||
| 28 | my @years = WWW::Metalgate::Column->new->years; | ||
| 29 | warn 0+@years; # 16 | ||
| 30 | YYY @years; | ||
| 31 | #--- !!perl/hash:WWW::Metalgate::Year | ||
| 32 | #uri: !!perl/scalar:URI::http http://www.metalgate.jp/best1992.htm | ||
| 33 | #year: 1992 | ||
| 34 | #--- !!perl/hash:WWW::Metalgate::Year | ||
| 35 | #uri: !!perl/scalar:URI::http http://www.metalgate.jp/best1993.htm | ||
| 36 | #year: 1993 | ||
| 37 | #... snip ... | ||
| 38 | |||
| 39 | =head1 FUNCTIONS | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | =head2 uri | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | has 'uri' => (is => 'rw', isa => Uri, coerce => 1, default => "http://www.metalgate.jp/column.htm"); | ||
| 48 | |||
| 49 | with 'WWW::Metalgate::Role::Html'; | ||
| 50 | |||
| 51 | =head2 years | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | sub years { | ||
| 56 | my $self = shift; | ||
| 57 | |||
| 58 | my $year = scraper { | ||
| 59 | process 'a', | ||
| 60 | url => '@href'; | ||
| 61 | }; | ||
| 62 | |||
| 63 | my $years = scraper { | ||
| 64 | process 'td>a', | ||
| 65 | 'years[]' => $year; | ||
| 66 | }; | ||
| 67 | |||
| 68 | my $data = $years->scrape( $self->html ); | ||
| 69 | my @years = map { $_->{url} =~ m/best(\d{4})/ } (@{$data->{years}}); | ||
| 70 | my @objs = map { WWW::Metalgate::Year->new( year => $_ ) } sort @years; | ||
| 71 | |||
| 72 | return @objs; | ||
| 73 | } | ||
| 74 | |||
| 75 | =head1 AUTHOR | ||
| 76 | |||
| 77 | Tomohiro Hosaka, C<< <bokutin at cpan.org> >> | ||
| 78 | |||
| 79 | =head1 COPYRIGHT & LICENSE | ||
| 80 | |||
| 81 | Copyright 2008 Tomohiro Hosaka, all rights reserved. | ||
| 82 | |||
| 83 | This program is free software; you can redistribute it and/or modify it | ||
| 84 | under the same terms as Perl itself. | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | 1; |