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