Changeset 13820
- Timestamp:
- 06/13/08 18:30:47 (5 years ago)
- Location:
- lang/perl/autobox-URI-Fetch/trunk
- Files:
-
- 2 modified
-
lib/autobox/URI/Fetch.pm (modified) (2 diffs)
-
t/01_fetch.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/autobox-URI-Fetch/trunk/lib/autobox/URI/Fetch.pm
r4910 r13820 2 2 3 3 use strict; 4 use 5.8.1; 5 our $VERSION = '0.01'; 4 use warnings; 5 use 5.8.8; 6 our $VERSION = '0.02'; 6 7 7 use autobox; 8 use base qw(autobox); 9 10 sub import { 11 shift->SUPER::import(STRING => 'autobox::URI::Fetch::Impl'); 12 } 13 14 package # hide from pause 15 autobox::URI::Fetch::Impl; 16 8 17 use Carp; 9 use Regexp::Common qw(URI);10 18 use URI; 11 19 use URI::Fetch; 12 20 13 sub SCALAR::fetch { 21 my $ua = LWP::UserAgent->new; 22 $ua->env_proxy; 23 24 sub fetch { 14 25 my $uri = URI->new(shift); 26 my $res = URI::Fetch::fetch('URI::Fetch', $uri, UserAgent => $ua) 27 or croak(URI::Fetch->errstr); 15 28 16 return URI::Fetch::fetch('URI::Fetch', $uri);29 return $res; 17 30 } 18 31 19 sub SCALAR::content {32 sub content { 20 33 my $uri = URI->new(shift); 21 my $res = URI::Fetch::fetch('URI::Fetch', $uri); 34 my $res = URI::Fetch::fetch('URI::Fetch', $uri, UserAgent => $ua) 35 or croak(URI::Fetch->errstr); 22 36 23 37 return $res->content; … … 33 47 =head1 SYNOPSIS 34 48 35 use autobox;36 49 use autobox::URI::Fetch; 37 50 -
lang/perl/autobox-URI-Fetch/trunk/t/01_fetch.t
r4910 r13820 2 2 use warnings; 3 3 4 use autobox; 4 use Test::More tests => 4; 5 use Test::Exception; 6 5 7 use autobox::URI::Fetch; 6 7 use URI::Fetch;8 use Readonly;9 use Test::More tests => 2;10 8 11 9 isa_ok('http://d.hatena.ne.jp'->fetch, 'URI::Fetch::Response'); 12 10 like( 13 11 'http://d.hatena.ne.jp'->content, 14 qr{^<!DOCTYPE\ HTML\ PUBLIC\ "-//W3C//DTD\ HTML\ 4\.01\ Transitional//EN">}xms, 15 'content' 12 qr{^<!DOCTYPE\ HTML\ PUBLIC\ "-//W3C//DTD\ HTML\ 4\.01\ Transitional//EN">}xms 16 13 ); 17 14 15 dies_ok { 'http://dummy'->fetch }; 16 dies_ok { 'http://dummy'->content };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)