rename C::E::HTTP.pm to C::E::LWP.pm
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Test.pm
1 package Catalyst::Engine::Test;
2
3 use strict;
4 use base 'Catalyst::Engine::LWP';
5
6 =head1 NAME
7
8 Catalyst::Engine::Test - Catalyst Test Engine
9
10 =head1 SYNOPSIS
11
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');
25
26 =head1 DESCRIPTION
27
28 This is the Catalyst engine specialized for testing.
29
30 =head1 OVERLOADED METHODS
31
32 This class overloads some methods from C<Catalyst::Engine::LWP>.
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 ) {
45
46         my $uri = ( $request =~ m/http/i )
47           ? URI->new($request)
48           : URI->new( 'http://localhost' . $request );
49
50         $request = $uri->canonical;
51     }
52
53     unless ( ref $request eq 'HTTP::Request' ) {
54         $request = HTTP::Request->new( 'GET', $request );
55     }
56
57     my $lwp = Catalyst::Engine::LWP::HTTP->new(
58         request  => $request,
59         address  => '127.0.0.1',
60         hostname => 'localhost'
61     );
62
63     $class->handler($lwp);
64
65     return $lwp->response;
66 }
67
68 =back
69
70 =head1 SEE ALSO
71
72 L<Catalyst>.
73
74 =head1 AUTHOR
75
76 Sebastian Riedel, C<sri@cpan.org>
77 Christian Hansen, C<ch@ngmedia.com>
78
79 =head1 COPYRIGHT
80
81 This program is free software, you can redistribute it and/or modify it under
82 the same terms as Perl itself.
83
84 =cut
85
86 1;