Commit | Line | Data |
---|---|---|
e646f111 | 1 | package Catalyst::Engine::Test; |
2 | ||
3 | use strict; | |
c2e8e6fa | 4 | use base 'Catalyst::Engine::HTTP::Base'; |
e646f111 | 5 | |
d837e1a7 | 6 | use Catalyst::Utils; |
7 | ||
e646f111 | 8 | =head1 NAME |
9 | ||
10 | Catalyst::Engine::Test - Catalyst Test Engine | |
11 | ||
12 | =head1 SYNOPSIS | |
13 | ||
c9afa5fc | 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'); | |
e646f111 | 27 | |
28 | =head1 DESCRIPTION | |
29 | ||
30 | This is the Catalyst engine specialized for testing. | |
31 | ||
32 | =head1 OVERLOADED METHODS | |
33 | ||
c2e8e6fa | 34 | This class overloads some methods from C<Catalyst::Engine::HTTP::Base>. |
e646f111 | 35 | |
36 | =over 4 | |
37 | ||
38 | =item $c->run | |
39 | ||
40 | =cut | |
41 | ||
42 | sub run { | |
d837e1a7 | 43 | my ( $class, $request ) = @_; |
44 | ||
45 | $request = Catalyst::Utils::request($request); | |
e646f111 | 46 | |
d837e1a7 | 47 | $request->header( |
48 | 'Host' => sprintf( '%s:%d', $request->uri->host, $request->uri->port ) | |
49 | ); | |
4716267f | 50 | |
d837e1a7 | 51 | my $http = Catalyst::Engine::HTTP::Base::struct->new( |
45374ac6 | 52 | address => '127.0.0.1', |
1a80619d | 53 | hostname => 'localhost', |
54 | request => $request, | |
55 | response => HTTP::Response->new | |
45374ac6 | 56 | ); |
e646f111 | 57 | |
6dc87a0f | 58 | $http->response->date(time); |
b26df351 | 59 | |
6dc87a0f | 60 | $class->handler($http); |
e646f111 | 61 | |
6dc87a0f | 62 | return $http->response; |
e646f111 | 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; |