b480c3d6844c139664ed937054accb06fd333e54
[catagits/Web-Simple.git] / lib / Web / Simple / Deployment.pod
1 =head1 NAME
2
3 Web::Simple::Deployment - various deployment options
4
5 =head1 DESCRIPTION
6
7 This file documents common deployment methods for Web::Simple. If you feel one
8 is missing, please ask in the IRC channel and we'll work with you to add it.
9
10 =head1 CGI
11
12 The most basic deployment option is as a CGI script loading and running your
13 Web::Simple-module:
14
15   #!/usr/bin/env perl
16
17   use Your::Web::Simple::App;
18   Your::Web::Simple::App->run_if_script;
19
20 Save that as script.cgi and your web server will handle it correctly.
21
22 =head2 Self-contained CGI
23
24 Sometimes your app is so small that you have only one or two tiny classes that
25 you want to run as a CGI script. Web::Simple offers a helpful mechanism to
26 achieve that.
27
28   #!/usr/bin/env perl
29
30   use Web::Simple 'HelloWorld';   # enables strictures and warnings for the file
31                                   # additionally, HelloWorld is upgraded to a
32                                   # Web::Simple application
33   {
34     package HelloWorld;
35
36     sub dispatch_request {
37       sub (GET) {
38         [
39           200,
40           [ 'Content-type', 'text/plain' ],
41           [ 'Hello world! It is a fine ' . HelloWorld::Helper->day ]
42         ]
43       },
44       sub () {
45         [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
46       }
47     }
48   }
49
50   {
51     package HelloWorld::Helper;
52
53     use DateTime;
54
55     sub day {
56       return DateTime->now->day_name;
57     }
58   }
59
60   HelloWorld->run_if_script;
61
62 =head1 AUTHORS
63
64 See L<Web::Simple> for authors.
65
66 =head1 COPYRIGHT AND LICENSE
67
68 See L<Web::Simple> for the copyright and license.
69
70 =cut