a5f9ca472e27018a8fd5fecde75ad76bec4a6906
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Test.pm
1 package Catalyst::Engine::Test;
2
3 use strict;
4 use base 'Catalyst::Engine::HTTP::Base';
5
6 use Catalyst::Utils;
7
8 =head1 NAME
9
10 Catalyst::Engine::Test - Catalyst Test Engine
11
12 =head1 SYNOPSIS
13
14 A script using the Catalyst::Engine::Test module might look like:
15
16     #!/usr/bin/perl -w
17
18     BEGIN { 
19        $ENV{CATALYST_ENGINE} = 'Test';
20     }
21
22     use strict;
23     use lib '/path/to/MyApp/lib';
24     use MyApp;
25
26     MyApp->run('/a/path');
27
28 =head1 DESCRIPTION
29
30 This is the Catalyst engine specialized for testing.
31
32 =head1 OVERLOADED METHODS
33
34 This class overloads some methods from C<Catalyst::Engine::HTTP::Base>.
35
36 =over 4
37
38 =item $c->run
39
40 =cut
41
42 sub run {
43     my ( $class, $request ) = @_;
44     
45     $request = Catalyst::Utils::request($request);
46
47     $request->header( 
48         'Host' => sprintf( '%s:%d', $request->uri->host, $request->uri->port )
49     );
50
51     my $http = Catalyst::Engine::HTTP::Base::struct->new(
52         address  => '127.0.0.1',
53         hostname => 'localhost',
54         request  => $request,
55         response => HTTP::Response->new
56     );
57
58     $http->response->date(time);
59
60     $class->handler($http);
61
62     return $http->response;
63 }
64
65 =back
66
67 =head1 SEE ALSO
68
69 L<Catalyst>.
70
71 =head1 AUTHOR
72
73 Sebastian Riedel, C<sri@cpan.org>
74 Christian Hansen, C<ch@ngmedia.com>
75
76 =head1 COPYRIGHT
77
78 This program is free software, you can redistribute it and/or modify it under
79 the same terms as Perl itself.
80
81 =cut
82
83 1;