| 1 | package WWW::Metalgate::Role::Html; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | |||
| 6 | use Moose::Role; | ||
| 7 | |||
| 8 | #requires_attr 'uri'; | ||
| 9 | |||
| 10 | use Encode; | ||
| 11 | use File::Spec; | ||
| 12 | use Cache::File; | ||
| 13 | use URI::Fetch; | ||
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | WWW::Metalgate::Role::Html | ||
| 18 | |||
| 19 | =head1 VERSION | ||
| 20 | |||
| 21 | Version 0.01 | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | our $VERSION = '0.01'; | ||
| 26 | |||
| 27 | =head1 FUNCTIONS | ||
| 28 | |||
| 29 | =head2 html | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | sub html { | ||
| 34 | my $self = shift; | ||
| 35 | |||
| 36 | $self->{_html} ||= do { | ||
| 37 | my $tmpdir = File::Spec->tmpdir(); | ||
| 38 | my $cache = Cache::File->new( cache_root => $tmpdir ); | ||
| 39 | #my $res = URI::Fetch->fetch($self->uri->canonical, Cache => $cache) or die URI::Fetch->errstr; | ||
| 40 | my $res = URI::Fetch->fetch($self->uri->canonical, Cache => $cache, NoNetwork => 60) or die URI::Fetch->errstr; | ||
| 41 | decode("cp932", $res->content); | ||
| 42 | }; | ||
| 43 | |||
| 44 | return $self->{_html}; | ||
| 45 | } | ||
| 46 | |||
| 47 | =head1 AUTHOR | ||
| 48 | |||
| 49 | Tomohiro Hosaka, C<< <bokutin at cpan.org> >> | ||
| 50 | |||
| 51 | =head1 COPYRIGHT & LICENSE | ||
| 52 | |||
| 53 | Copyright 2008 Tomohiro Hosaka, all rights reserved. | ||
| 54 | |||
| 55 | This program is free software; you can redistribute it and/or modify it | ||
| 56 | under the same terms as Perl itself. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | 1; |