[Catalyst-dev] subdomain hook for Catalyst::Test
Tomas Doran
bobtfish at bobtfish.net
Fri Oct 10 00:04:16 BST 2008
On 9 Oct 2008, at 17:23, Jason Gottshall wrote:
> We've already solved the problem of specifying a fully qualified
> "host", and hearing no objections I'm going to continue to use the
> term "subdomain" for the mechanism that allows you to specify just
> a portion of the host.
Surely this is just a case of generating the correct url?
# So a simple function
sub sub_request {
my ($sub, $path, %params) = @_;
$params{host} = $sub . '.maindomain.com';
request($path, \%params);
}
# Sub domain per request style
ok( sub_request('dom1', '/')->is_success );
ok( sub_request('dom2', '/')->is_success );
# And Matt's previous technique, but this time on the request method
directly..
sub with_domain {
my ($domain, $code) = @_;
my $orig_request = \&request;
local *request = sub { $orig_request->($_[0], { %{$_[1]}, host
=> $domain }); };
$code->();
}
# Many requests to one subdomain style
with_domain 'www.example.com' => sub {
ok( request('/')->is_success );
ok( request('/login')->is_success );
};
Cheers
t0m
More information about the Catalyst-dev
mailing list