Commit latest CPAN ver of TWMC to repo
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / lib / ExternalCatty.pm
CommitLineData
6bc86362 1package ExternalCatty;
2use strict;
3use warnings;
4use Catalyst qw/-Engine=HTTP/;
5our $VERSION = '0.01';
6
7__PACKAGE__->config( name => 'ExternalCatty' );
8__PACKAGE__->setup;
9
10sub default : Private {
11 my ( $self, $c ) = @_;
12 $c->response->content_type('text/html; charset=utf-8');
13 $c->response->output( html( 'Root', 'Hello, test ☺!' ) );
14}
15
16sub html {
17 my ( $title, $body ) = @_;
18 return qq[
19<html>
20<head>
21 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
22 <title>$title</title>
23</head>
24<body>$body</body>
25</html>
26];
27}
28
29# The Cat HTTP server background option is useless here :-(
30# Thus we have to provide our own background method.
31sub background {
32 my $self = shift;
33 my $port = shift;
34 my $child = fork;
35 die "Can't fork Cat HTTP server: $!" unless defined $child;
36 return $child if $child;
37
38 if ( $^O !~ /MSWin32/ ) {
39 require POSIX;
40 POSIX::setsid() or die "Can't start a new session: $!";
41 }
42
43 $self->run($port);
44}
45
461;
47