�ɲɾ�����ӯ�����һ��ˣ��������С���˴��ͣ�������P���ҹ��ñ˽��ά�Բ��������˸߸ԣ�������ơ��ҹ��ñ�����ά�Բ���ˡ���˳^�ӣ������ӡ� ���ͯj�ӣ��ƺ���ӣ� ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!LWP/UserAgent/DNS/Hosts.pm000044400000011706152526336440011202 0ustar00package LWP::UserAgent::DNS::Hosts; use 5.008001; use strict; use warnings; use Carp; use LWP::Protocol; use Scope::Guard qw(guard); our $VERSION = '0.14'; $VERSION = eval $VERSION; our @Protocols = qw(http https); our %Implementors; our %Hosts; sub register_host { my ($class, $host, $peer_addr) = @_; $Hosts{$host} = $peer_addr; } sub register_hosts { my ($class, %pairs) = @_; while (my ($host, $peer_addr) = each %pairs) { $class->register_host($host, $peer_addr); } } sub clear_hosts { %Hosts = (); } sub read_hosts { my ($class, $source) = @_; if (ref $source eq 'GLOB') { $class->_read_hosts_from_handle($source); } elsif ($source !~ /[\x0D\x0A]/ && -f $source) { $class->_read_hosts_from_file($source); } else { $class->_read_hosts_from_string($source); } } sub _read_hosts_from_handle { my ($class, $handle) = @_; while (<$handle>) { chomp; s/^\s+//g; s/\s+$//g; next if !$_ || /^#/; my ($addr, @hosts) = split /\s+/; for my $host (@hosts) { $class->register_host($host, $addr); } } } sub _read_hosts_from_file { my ($class, $file) = @_; open my $fh, '<', $file or croak $!; $class->_read_hosts_from_handle($fh); close $fh; } sub _read_hosts_from_string { my ($class, $string) = @_; open my $fh, '<', \$string or croak $!; $class->_read_hosts_from_handle($fh); close $fh; } sub _registered_peer_addr { my ($class, $host) = @_; return $Hosts{$host}; } sub _implementor { my ($class, $proto) = @_; return sprintf 'LWP::Protocol::%s::hosts' => $proto; } sub enable_override { my $class = shift; for my $proto (@Protocols) { if (my $orig = LWP::Protocol::implementor($proto)) { my $impl = $class->_implementor($proto); if (eval "require $impl; 1") { LWP::Protocol::implementor($proto => $impl); $Implementors{$proto} = $orig; } } else { carp("LWP::Protocol::$proto is unavailable. Skip overriding it."); } } if (defined wantarray) { return guard { $class->disable_override }; } } sub disable_override { my $class = shift; for my $proto (@Protocols) { if (my $impl = $Implementors{$proto}) { LWP::Protocol::implementor($proto, $impl); } } } 1; =encoding utf-8 =for stopwords =head1 NAME LWP::UserAgent::DNS::Hosts - Override LWP HTTP/HTTPS request's host like /etc/hosts =head1 SYNOPSIS use LWP::UserAgent; use LWP::UserAgent::DNS::Hosts; # add entry LWP::UserAgent::DNS::Hosts->register_host( 'www.cpan.org' => '127.0.0.1', ); # add entries LWP::UserAgent::DNS::Hosts->register_hosts( 'search.cpan.org' => '192.168.0.100', 'pause.perl.org' => '192.168.0.101', ); # read hosts file LWP::UserAgent::DNS::Hosts->read_hosts('/path/to/my/hosts'); LWP::UserAgent::DNS::Hosts->enable_override; # override request hosts with peer addr defined above my $ua = LWP::UserAgent->new; my $res = $ua->get("http://www.cpan.org/"); print $res->content; # is same as "http://127.0.0.1/" content =head1 DESCRIPTION LWP::UserAgent::DNS::Hosts is a module to override HTTP/HTTPS request peer addresses that uses LWP::UserAgent. This module concept was got from L. =head1 METHODS =over 4 =item register_host($host, $peer_addr) LWP::UserAgent::DNS::Hosts->register_host($host, $peer_addr); Registers a pair of hostname and peer ip address. # /etc/hosts 127.0.0.1 example.com equals to: LWP::UserAgent::DNS::Hosts->register_hosts('example.com', '127.0.0.1'); =item register_hosts(%host_addr_pairs) LWP::UserAgent::DNS::Hosts->register_hosts( 'example.com' => '192.168.0.1', 'example.org' => '192.168.0.2', ... ); Registers pairs of hostname and peer ip address. =item read_hosts($file_or_string) LWP::UserAgent::DNS::Hosts->read_hosts('hosts.my'); LWP::UserAgent::DNS::Hosts->read_hosts(<<'__HOST__'); 127.0.0.1 example.com 192.168.0.1 example.net example.org __HOST__ Registers "/etc/hosts" syntax entries. =item clear_hosts Clears registered pairs. =item enable_override LWP::UserAgent::DNS::Hosts->enable_override; my $guard = LWP::UserAgent::DNS::Hosts->enable_override; Enables to override hook. If called in a non-void context, returns a L object that automatically resets the override when it goes out of context. =item disable_override LWP::UserAgent::DNS::Hosts->disable_override; Disables to override hook. If you use the guard interface described above, it will be automatically called for you. =back =head1 AUTHOR NAKAGAWA Masaki Emasaki@cpan.orgE =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L =cut LWP/Protocol/http/hosts.pm000044400000000747152526336440011504 0ustar00package LWP::Protocol::http::hosts; use strict; use warnings; use parent 'LWP::Protocol::http'; use LWP::UserAgent::DNS::Hosts; sub _extra_sock_opts { my ($self, $host, $port) = @_; my @opts = $self->SUPER::_extra_sock_opts($host, $port); if (my $peer_addr = LWP::UserAgent::DNS::Hosts->_registered_peer_addr($host)) { push @opts, (PeerAddr => $peer_addr, Host => $host); } return @opts; } sub socket_class { 'LWP::Protocol::http::Socket' } 1; __END__ LWP/Protocol/https/hosts.pm000044400000001175152526336440011663 0ustar00package LWP::Protocol::https::hosts; use strict; use warnings; use parent 'LWP::Protocol::https'; use LWP::UserAgent::DNS::Hosts; sub _extra_sock_opts { my ($self, $host, $port) = @_; my @opts = $self->SUPER::_extra_sock_opts($host, $port); if (my $peer_addr = LWP::UserAgent::DNS::Hosts->_registered_peer_addr($host)) { push @opts, ( PeerAddr => $peer_addr, Host => $host, SSL_verifycn_name => $host, SSL_hostname => $host, # for SNI ); } return @opts; } sub socket_class { 'LWP::Protocol::https::Socket' } 1; __END__ x86_64-linux/.meta/Test-Fake-HTTPD-0.09/install.json000044400000000361152526336440015244 0ustar00{"dist":"Test-Fake-HTTPD-0.09","version":"0.09","pathname":"M/MA/MASAKI/Test-Fake-HTTPD-0.09.tar.gz","name":"Test::Fake::HTTPD","target":"Test::Fake::HTTPD","provides":{"Test::Fake::HTTPD":{"file":"lib/Test/Fake/HTTPD.pm","version":"0.09"}}}x86_64-linux/.meta/Test-Fake-HTTPD-0.09/MYMETA.json000044400000004765152526336440014606 0ustar00{ "abstract" : "a fake HTTP server", "author" : [ "NAKAGAWA Masaki " ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.1.10, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-Fake-HTTPD", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.035" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.07", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "HTTP::Daemon" : "0", "HTTP::Message::PSGI" : "0", "Scalar::Util" : "1.14", "Test::SharedFork" : "0.29", "Test::TCP" : "0", "Time::HiRes" : "0", "URI" : "0", "perl" : "5.008001" } }, "test" : { "requires" : { "ExtUtils::MakeMaker" : "6.59", "LWP::UserAgent" : "0", "Test::Exception" : "0", "Test::More" : "0.98", "Test::TCP" : "0", "Test::UseAllModules" : "0" } } }, "provides" : { "Test::Fake::HTTPD" : { "file" : "lib/Test/Fake/HTTPD.pm", "version" : "0.09" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/masaki/Test-Fake-HTTPD/issues" }, "homepage" : "https://github.com/masaki/Test-Fake-HTTPD", "repository" : { "type" : "git", "url" : "git://github.com/masaki/Test-Fake-HTTPD.git", "web" : "https://github.com/masaki/Test-Fake-HTTPD" } }, "version" : "0.09", "x_authority" : "cpan:MASAKI", "x_contributors" : [ "Olivier Mengué ", "Petr Písař ", "Richard Hansen ", "ikasam_a " ], "x_serialization_backend" : "JSON::PP version 4.07", "x_static_install" : 1 } x86_64-linux/.meta/LWP-UserAgent-DNS-Hosts-0.14/install.json000044400000000664152526336440016657 0ustar00{"dist":"LWP-UserAgent-DNS-Hosts-0.14","name":"LWP::UserAgent::DNS::Hosts","target":"LWP::UserAgent::DNS::Hosts","provides":{"LWP::Protocol::https::hosts":{"file":"lib/LWP/Protocol/https/hosts.pm"},"LWP::UserAgent::DNS::Hosts":{"version":"0.14","file":"lib/LWP/UserAgent/DNS/Hosts.pm"},"LWP::Protocol::http::hosts":{"file":"lib/LWP/Protocol/http/hosts.pm"}},"version":"0.14","pathname":"M/MA/MASAKI/LWP-UserAgent-DNS-Hosts-0.14.tar.gz"}x86_64-linux/.meta/LWP-UserAgent-DNS-Hosts-0.14/MYMETA.json000044400000006017152526336440016203 0ustar00{ "abstract" : "Override LWP HTTP/HTTPS request's host like /etc/hosts", "author" : [ "NAKAGAWA Masaki " ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.1.10, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "LWP-UserAgent-DNS-Hosts", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "optional_features" : { "https" : { "description" : "SSL support", "prereqs" : { "runtime" : { "recommends" : { "LWP::Protocol::https" : "0" } }, "test" : { "requires" : { "HTTP::Daemon::SSL" : "0" } } } } }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.035" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.07", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "LWP::Protocol" : "0", "LWP::Protocol::http" : "0", "Scope::Guard" : "0", "parent" : "0", "perl" : "5.008001" } }, "test" : { "requires" : { "File::Temp" : "0", "LWP::UserAgent" : "0", "Test::Fake::HTTPD" : "0.08", "Test::More" : "0.98", "Test::UseAllModules" : "0" } } }, "provides" : { "LWP::Protocol::http::hosts" : { "file" : "lib/LWP/Protocol/http/hosts.pm" }, "LWP::Protocol::https::hosts" : { "file" : "lib/LWP/Protocol/https/hosts.pm" }, "LWP::UserAgent::DNS::Hosts" : { "file" : "lib/LWP/UserAgent/DNS/Hosts.pm", "version" : "0.14" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/masaki/p5-LWP-UserAgent-DNS-Hosts/issues" }, "homepage" : "https://github.com/masaki/p5-LWP-UserAgent-DNS-Hosts", "repository" : { "type" : "git", "url" : "git://github.com/masaki/p5-LWP-UserAgent-DNS-Hosts.git", "web" : "https://github.com/masaki/p5-LWP-UserAgent-DNS-Hosts" } }, "version" : "0.14", "x_authority" : "cpan:MASAKI", "x_contributors" : [ "Anirvan Chatterjee ", "Masaki Nakagawa ", "Petr Písař ", "Tatsuhiko Miyagawa " ], "x_serialization_backend" : "JSON::PP version 4.07", "x_static_install" : 1 } x86_64-linux/.meta/Test-UseAllModules-0.17/install.json000044400000000402152526336440016226 0ustar00{"pathname":"I/IS/ISHIGAKI/Test-UseAllModules-0.17.tar.gz","version":"0.17","provides":{"Test::UseAllModules":{"version":"0.17","file":"lib/Test/UseAllModules.pm"}},"name":"Test::UseAllModules","target":"Test::UseAllModules","dist":"Test-UseAllModules-0.17"}x86_64-linux/.meta/Test-UseAllModules-0.17/MYMETA.json000044400000002313152526336440015557 0ustar00{ "abstract" : "do use_ok() for all the MANIFESTed modules", "author" : [ "Kenichi Ishigaki " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142060, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-UseAllModules", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Exporter" : "0", "ExtUtils::Manifest" : "0", "Test::Builder" : "0.30", "Test::More" : "0.60" } } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "https://github.com/charsbar/test-useallmodules" } }, "version" : "0.17", "x_serialization_backend" : "JSON::PP version 4.07" } x86_64-linux/auto/LWP/UserAgent/DNS/Hosts/.packlist000064400000000257152526336440015523 0ustar00/opt/cpanel/perl5/536/site_lib/LWP/Protocol/http/hosts.pm /opt/cpanel/perl5/536/site_lib/LWP/Protocol/https/hosts.pm /opt/cpanel/perl5/536/site_lib/LWP/UserAgent/DNS/Hosts.pm x86_64-linux/auto/Test/Fake/HTTPD/.packlist000064400000000062152526336440014102 0ustar00/opt/cpanel/perl5/536/site_lib/Test/Fake/HTTPD.pm x86_64-linux/auto/Test/UseAllModules/.packlist000064400000000065152526336440015072 0ustar00/opt/cpanel/perl5/536/site_lib/Test/UseAllModules.pm Test/UseAllModules.pm000044400000010306152526336440010547 0ustar00package Test::UseAllModules; use strict; use warnings; use ExtUtils::Manifest qw( maniread ); our $VERSION = '0.17'; use Exporter; our @ISA = qw/Exporter/; our @EXPORT = qw/all_uses_ok/; use Test::More; my $RULE = qr{^lib/(.+)\.pm$}; sub import { shift->export_to_level(1); shift if @_ && $_[0] eq 'under'; my @dirs = ('lib', @_); my %seen; @dirs = grep { !$seen{$_}++ } map { s|/+$||; $_ } @dirs; $RULE = '^(?:'.(join '|', @dirs).')/(.+)\.pm\s*$'; unshift @INC, @dirs; } sub _get_module_list { shift if @_ && $_[0] eq 'except'; my @exceptions = @_; my @modules; my $manifest = maniread(); READ: foreach my $file (keys %{ $manifest }) { if (my ($module) = $file =~ m|$RULE|) { $module =~ s|/|::|g; foreach my $rule (@exceptions) { next READ if $module eq $rule || $module =~ /$rule/; } push @modules, $module; } } return @modules; } sub _planned { Test::More->builder->has_plan; } sub all_uses_ok { unless (-f 'MANIFEST') { plan skip_all => 'no MANIFEST' unless _planned(); return; } my @modules = _get_module_list(@_); unless (@modules) { plan skip_all => 'no .pm files are found under the lib directory' unless _planned(); return; } plan tests => scalar @modules unless _planned(); my @failed; foreach my $module (@modules) { use_ok($module) or push @failed, $module; } BAIL_OUT( 'failed: ' . (join ',', @failed) ) if @failed; } 1; __END__ =head1 NAME Test::UseAllModules - do use_ok() for all the MANIFESTed modules =head1 SYNOPSIS # basic usage use strict; use Test::UseAllModules; BEGIN { all_uses_ok(); } # if you also want to test modules under t/lib use strict; use Test::UseAllModules under => qw(lib t/lib); BEGIN { all_uses_ok(); } # if you have modules that'll fail use_ok() for themselves use strict; use Test::UseAllModules; BEGIN { all_uses_ok except => qw( Some::Dependent::Module Another::Dependent::Module ^Yet::Another::Dependent::.* # you can use regex ) } =head1 DESCRIPTION I'm sick of writing 00_load.t (or something like that) that'll do use_ok() for every module I write. I'm sicker of updating 00_load.t when I add another file to the distro. This module reads MANIFEST to find modules to be tested and does use_ok() for each of them. Now all you have to do is update MANIFEST. You don't have to modify the test any more (hopefully). =head1 EXPORTED FUNCTION =head2 all_uses_ok Does Test::More's use_ok() for every module found in MANIFEST. If you have modules you don't want to test, give those modules or some regex rules as the argument. The word 'except' is ignored as shown above. As of 0.11, you can also test modules under arbitrary directories by providing a directory list at the loading time (the word 'under' is ignored as shown above). Modules under the lib directory are always tested. =head1 PROTECTED FUNCTION =head2 _get_module_list Returns module paths to test. This function will not be exported. If you want to use this (see below), you always need to call it by the full qualified name. =head1 NOTES As of 0.03, this module calls BAIL_OUT of Test::More if any of the use_ok tests should fail. (Thus the following tests will be ignored. Missing or unloadable modules cause a lot of errors of the same kind.) As of 0.12, you can add extra tests before/after all_uses_ok() if you explicitly declare test plan like this. use strict; use warnings; use Test::More; use Test::UseAllModules; use Test::NoWarnings; plan tests => Test::UseAllModules::_get_module_list() + 1; all_uses_ok(); # and extra nowarnings test =head1 SEE ALSO There're several modules like this on the CPAN now. L and a bit confusing L try to find modules to test by traversing directories. I'm not a big fan of them as they tend to find temporary or unrelated modules as well, but they may be handier especially if you're too lazy to update MANIFEST every time. =head1 AUTHOR Kenichi Ishigaki, Eishigaki@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2006 by Kenichi Ishigaki This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Test/Fake/HTTPD.pm000044400000017702152526336440007571 0ustar00package Test::Fake::HTTPD; use 5.008_001; use strict; use warnings; use HTTP::Daemon; use HTTP::Message::PSGI qw(res_from_psgi); use Test::TCP qw(wait_port); use URI; use Time::HiRes (); use Scalar::Util qw(blessed weaken); use Carp qw(croak); use Exporter qw(import); our $VERSION = '0.09'; $VERSION = eval $VERSION; our @EXPORT = qw( run_http_server run_https_server extra_daemon_args ); our $ENABLE_SSL = eval { require HTTP::Daemon::SSL; 1 }; sub enable_ssl { $ENABLE_SSL } our %EXTRA_DAEMON_ARGS = (); sub extra_daemon_args (%) { %EXTRA_DAEMON_ARGS = @_ } sub run_http_server (&) { my $app = shift; __PACKAGE__->new->run($app); } sub run_https_server (&) {} # noop if ($ENABLE_SSL) { no warnings 'redefine'; *run_https_server = sub (&) { my $app = shift; __PACKAGE__->new(scheme => 'https')->run($app); }; } sub new { my ($class, %args) = @_; bless { host => '127.0.0.1', timeout => 5, listen => 5, scheme => 'http', %args }, $class; } our $DAEMON_MAP = { http => 'HTTP::Daemon', https => 'HTTP::Daemon::SSL', }; sub _daemon_class { my $self = shift; return $DAEMON_MAP->{$self->{scheme}}; } sub run { my ($self, $app) = @_; my %extra_daemon_args = $self->{daemon_args} && ref $self->{daemon_args} eq 'HASH' ? %{ $self->{daemon_args} } : %EXTRA_DAEMON_ARGS; $self->{server} = Test::TCP->new( ($self->host ? (host => $self->host) : ()), code => sub { my $port = shift; my $d; for (1..10) { $d = $self->_daemon_class->new( # Note: IO::Socket::IP ignores LocalAddr if LocalHost is set. ($self->host ? (LocalAddr => $self->host) : ()), LocalPort => $port, Timeout => $self->{timeout}, Proto => 'tcp', Listen => $self->{listen}, ($self->_is_win32 ? () : (ReuseAddr => 1)), %extra_daemon_args, ) and last; Time::HiRes::sleep(0.1); } croak(sprintf("failed to listen on address %s port %s%s", $self->host || '', $self->port || '', $@ eq '' ? '' : ": $@")) unless $d; $d->accept; # wait for port check from parent process while (my $c = $d->accept) { while (my $req = $c->get_request) { my $res = $self->_to_http_res($app->($req)); $c->send_response($res); } $c->close; undef $c; } }, ($self->{port} ? (port => $self->{port}) : ()), ); weaken($self); $self; } sub scheme { my $self = shift; return $self->{scheme}; } sub host { my $self = shift; return $self->{host}; } sub port { my $self = shift; return $self->{server} ? $self->{server}->port : 0; } sub host_port { my $self = shift; return $self->endpoint->host_port; } sub endpoint { my $self = shift; my $uri = URI->new($self->scheme . ':'); my $host = $self->host; $host = 'localhost' if !defined($host) || $host eq '' || $host eq '0.0.0.0' || $host eq '::'; $uri->host($host); $uri->port($self->port); return $uri; } sub _is_win32 { $^O eq 'MSWin32' } sub _is_psgi_res { my ($self, $res) = @_; return unless ref $res eq 'ARRAY'; return unless @$res == 3; return unless $res->[0] && $res->[0] =~ /^\d{3}$/; return unless ref $res->[1] eq 'ARRAY' || ref $res->[1] eq 'HASH'; return 1; } sub _to_http_res { my ($self, $res) = @_; my $http_res; if (blessed($res) and $res->isa('HTTP::Response')) { $http_res = $res; } elsif (blessed($res) and $res->isa('Plack::Response')) { $http_res = res_from_psgi($res->finalize); } elsif ($self->_is_psgi_res($res)) { $http_res = res_from_psgi($res); } croak(sprintf '%s: response must be HTTP::Response or Plack::Response or PSGI', __PACKAGE__) unless $http_res; return $http_res; } 1; =head1 NAME Test::Fake::HTTPD - a fake HTTP server =head1 SYNOPSIS DSL-style use Test::Fake::HTTPD; my $httpd = run_http_server { my $req = shift; # ... # 1. HTTP::Response ok return $http_response; # 2. Plack::Response ok return $plack_response; # 3. PSGI response ok return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ]; }; printf "Listening on address:port %s\n", $httpd->host_port; # or printf "Listening on address %s port %s\n", $httpd->host, $httpd->port; # access to fake HTTP server use LWP::UserAgent; my $res = LWP::UserAgent->new->get($httpd->endpoint); # "http://127.0.0.1:{port}" # Stop http server automatically at destruction time. OO-style use Test::Fake::HTTPD; my $httpd = Test::Fake::HTTPD->new( timeout => 5, daemon_args => { ... }, # HTTP::Daemon args ); $httpd->run(sub { my $req = shift; # ... [ 200, [ 'Content-Type', 'text/plain' ], [ 'Hello World' ] ]; }); # Stop http server automatically at destruction time. =head1 DESCRIPTION Test::Fake::HTTPD is a fake HTTP server module for testing. =head1 FUNCTIONS =over 4 =item * C Starts HTTP server and returns the guard instance. my $httpd = run_http_server { my $req = shift; # ... return $http_or_plack_or_psgi_res; }; # can use $httpd guard object, same as OO-style LWP::UserAgent->new->get($httpd->endpoint); =item * C Starts B server and returns the guard instance. If you use this method, you MUST install L. extra_daemon_args SSL_key_file => "certs/server-key.pem", SSL_cert_file => "certs/server-cert.pem"; my $httpd = run_https_server { my $req = shift; # ... return $http_or_plack_or_psgi_res; }; # can use $httpd guard object, same as OO-style my $ua = LWP::UserAgent->new( ssl_opts => { SSL_verify_mode => 0, verify_hostname => 0, }, ); $ua->get($httpd->endpoint); =back =head1 METHODS =over 4 =item * C Returns a new instance. my $httpd = Test::Fake::HTTPD->new(%args); C<%args> are: =over 8 =item * C timeout value (default: 5) =item * C queue size for listen (default: 5) =item * C local address to listen on (default: 127.0.0.1) =item * C TCP port to listen on (default: auto detection) =back my $httpd = Test::Fake::HTTPD->new( timeout => 10, listen => 10, port => 3333, ); =item * C Starts this HTTP server. $httpd->run(sub { ... }); =item * C Returns a scheme of running, "http" or "https". my $scheme = $httpd->scheme; =item * C Returns the address the server is listening on. =item * C Returns the TCP port the server is listening on. my $port = $httpd->port; =item * C Returns the host:port from C (e.g., "127.0.0.1:1234", "[::1]:1234"). my $host_port = $httpd->host_port; =item * C Returns a URI object to the running server (e.g., "http://127.0.0.1:1234", "https://[::1]:1234"). If C returns C, C<''>, C<'0.0.0.0'>, or C<'::'>, the host portion of the URI is set to C. use LWP::UserAgent; my $res = LWP::UserAgent->new->get($httpd->endpoint); my $url = $httpd->endpoint; $url->path('/foo/bar'); my $res = LWP::UserAgent->new->get($url); =back =head1 AUTHOR NAKAGAWA Masaki Emasaki@cpan.orgE =head1 THANKS TO xaicron =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L, L =cut