added cgi.pl helper script
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Test.pm
CommitLineData
fc7ec1d9 1package Catalyst::Test;
2
3use strict;
4use UNIVERSAL::require;
fc7ec1d9 5
bc024080 6require Catalyst;
7
fc7ec1d9 8my $class;
fc7ec1d9 9
10=head1 NAME
11
12Catalyst::Test - Test Catalyst applications
13
14=head1 SYNOPSIS
15
49faa307 16 # Helper
49faa307 17 script/test.pl
18
fc7ec1d9 19 # Tests
20 use Catalyst::Test 'TestApp';
21 request('index.html');
22 get('index.html');
23
24 # Request
25 perl -MCatalyst::Test=MyApp -e1 index.html
26
fc7ec1d9 27=head1 DESCRIPTION
28
29Test Catalyst applications.
30
31=head2 METHODS
32
33=head3 get
34
35Returns the content.
36
37 my $content = get('foo/bar?test=1');
38
39=head3 request
40
41Returns a C<HTTP::Response> object.
42
43 my $res =request('foo/bar?test=1');
44
45=cut
46
47{
48 no warnings;
49 CHECK {
50 if ( ( caller(0) )[1] eq '-e' ) {
585893b9 51 print request( $ARGV[0] || 'http://localhost' )->content;
fc7ec1d9 52 }
53 }
54}
55
56sub import {
57 my $self = shift;
bc024080 58 if ( $class = shift ) {
59 $class->require;
60 unless ( $INC{'Test/Builder.pm'} ) {
61 die qq/Couldn't load "$class", "$@"/ if $@;
62 }
e646f111 63
bc024080 64 no strict 'refs';
fc7ec1d9 65
e646f111 66 unless ( $class->engine->isa('Catalyst::Engine::Test') ) {
67 require Catalyst::Engine::Test;
68 splice( @{"$class\::ISA"}, @{"$class\::ISA"} - 1,
69 0, 'Catalyst::Engine::Test' );
49faa307 70 }
e646f111 71
72 my $caller = caller(0);
73 *{"$caller\::request"} = sub { $class->run(@_) };
74 *{"$caller\::get"} = sub { $class->run(@_)->content };
49faa307 75 }
fc7ec1d9 76}
77
fc7ec1d9 78=head1 SEE ALSO
79
80L<Catalyst>.
81
82=head1 AUTHOR
83
84Sebastian Riedel, C<sri@cpan.org>
85
86=head1 COPYRIGHT
87
88This program is free software, you can redistribute it and/or modify it under
89the same terms as Perl itself.
90
91=cut
92
931;