pulled all files out, i believe i got everything.
[catagits/Catalyst-Devel.git] / share / root / server.tt
1 [% startperl %]
2
3 BEGIN {
4     $ENV{CATALYST_ENGINE} ||= 'HTTP';
5     $ENV{CATALYST_SCRIPT_GEN} = [% scriptgen %];
6     require Catalyst::Engine::HTTP;
7 }
8
9 use strict;
10 use warnings;
11 use Getopt::Long;
12 use Pod::Usage;
13 use FindBin;
14 use lib "$FindBin::Bin/../lib";
15
16 my $debug             = 0;
17 my $fork              = 0;
18 my $help              = 0;
19 my $host              = undef;
20 my $port              = $ENV{[% appenv %]_PORT} || $ENV{CATALYST_PORT} || 3000;
21 my $keepalive         = 0;
22 my $restart           = $ENV{[% appenv %]_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
23 my $background        = 0;
24 my $pidfile           = undef;
25
26 my $check_interval;
27 my $file_regex;
28 my $watch_directory;
29 my $follow_symlinks;
30
31 my @argv = @ARGV;
32
33 GetOptions(
34     'debug|d'             => \$debug,
35     'fork|f'              => \$fork,
36     'help|?'              => \$help,
37     'host=s'              => \$host,
38     'port|p=s'            => \$port,
39     'keepalive|k'         => \$keepalive,
40     'restart|r'           => \$restart,
41     'restartdelay|rd=s'   => \$check_interval,
42     'restartregex|rr=s'   => \$file_regex,
43     'restartdirectory=s@' => \$watch_directory,
44     'followsymlinks'      => \$follow_symlinks,
45     'background'          => \$background,
46     'pidfile=s'           => \$pidfile,
47 );
48
49 pod2usage(1) if $help;
50
51 if ( $debug ) {
52     $ENV{CATALYST_DEBUG} = 1;
53 }
54
55 # If we load this here, then in the case of a restarter, it does not
56 # need to be reloaded for each restart.
57 require Catalyst;
58
59 # If this isn't done, then the Catalyst::Devel tests for the restarter
60 # fail.
61 $| = 1 if $ENV{HARNESS_ACTIVE};
62
63 my $runner = sub {
64     # This is require instead of use so that the above environment
65     # variables can be set at runtime.
66     require [% name %];
67
68     [% name %]->run(
69         $port, $host,
70         {
71             argv       => \@argv,
72             'fork'     => $fork,
73             keepalive  => $keepalive,
74             background => $background,
75             pidfile    => $pidfile,
76         }
77     );
78 };
79
80 if ( $restart ) {
81     die "Cannot run in the background and also watch for changed files.\n"
82         if $background;
83
84     require Catalyst::Restarter;
85
86     my $subclass = Catalyst::Restarter->pick_subclass;
87
88     my %args;
89     $args{follow_symlinks} = 1
90         if $follow_symlinks;
91     $args{directories} = $watch_directory
92         if defined $watch_directory;
93     $args{sleep_interval} = $check_interval
94         if defined $check_interval;
95     $args{filter} = qr/$file_regex/
96         if defined $file_regex;
97
98     my $restarter = $subclass->new(
99         %args,
100         start_sub => $runner,
101     );
102
103     $restarter->run_and_watch;
104 }
105 else {
106     $runner->();
107 }
108
109 1;
110
111 =head1 NAME
112
113 [% appprefix %]_server.pl - Catalyst Testserver
114
115 =head1 SYNOPSIS
116
117 [% appprefix %]_server.pl [options]
118
119  Options:
120    -d -debug          force debug mode
121    -f -fork           handle each request in a new process
122                       (defaults to false)
123    -? -help           display this help and exits
124       -host           host (defaults to all)
125    -p -port           port (defaults to 3000)
126    -k -keepalive      enable keep-alive connections
127    -r -restart        restart when files get modified
128                       (defaults to false)
129    -rd -restartdelay  delay between file checks
130                       (ignored if you have Linux::Inotify2 installed)
131    -rr -restartregex  regex match files that trigger
132                       a restart when modified
133                       (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
134    -restartdirectory  the directory to search for
135                       modified files, can be set mulitple times
136                       (defaults to '[SCRIPT_DIR]/..')
137    -follow_symlinks   follow symlinks in search directories
138                       (defaults to false. this is a no-op on Win32)
139    -background        run the process in the background
140    -pidfile           specify filename for pid file
141
142  See also:
143    perldoc Catalyst::Manual
144    perldoc Catalyst::Manual::Intro
145
146 =head1 DESCRIPTION
147
148 Run a Catalyst Testserver for this application.
149
150 =head1 AUTHORS
151
152 Catalyst Contributors, see Catalyst.pm
153
154 =head1 COPYRIGHT
155
156 This library is free software. You can redistribute it and/or modify
157 it under the same terms as Perl itself.
158
159 =cut