]> ruin.nu Git - ndwebbie.git/blob - script/ndweb_server.pl
fbd487270c9943ed1d5bc34615c9eb79c5954062
[ndwebbie.git] / script / ndweb_server.pl
1 #!/usr/bin/perl -w
2
3 BEGIN { 
4     $ENV{CATALYST_ENGINE} ||= 'HTTP';
5     $ENV{CATALYST_SCRIPT_GEN} = 31;
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 #Need to preload, otherwise the first hit is slow
17 use CGI qw/:standard/;
18 escapeHTML('');
19
20 my $debug             = 0;
21 my $fork              = 0;
22 my $help              = 0;
23 my $host              = undef;
24 my $port              = $ENV{NDWEB_PORT} || $ENV{CATALYST_PORT} || 3000;
25 my $keepalive         = 0;
26 my $restart           = $ENV{NDWEB_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
27 my $restart_delay     = 1;
28 my $restart_regex     = '(?:/|^)(?!\.#).+(?:\.yml$|\.yaml$|\.pm)$';
29 my $restart_directory = undef;
30 my $follow_symlinks   = 0;
31
32 my @argv = @ARGV;
33
34 GetOptions(
35     'debug|d'             => \$debug,
36     'fork'                => \$fork,
37     'help|?'              => \$help,
38     'host=s'              => \$host,
39     'port=s'              => \$port,
40     'keepalive|k'         => \$keepalive,
41     'restart|r'           => \$restart,
42     'restartdelay|rd=s'   => \$restart_delay,
43     'restartregex|rr=s'   => \$restart_regex,
44     'restartdirectory=s@' => \$restart_directory,
45     'followsymlinks'      => \$follow_symlinks,
46 );
47
48 pod2usage(1) if $help;
49
50 if ( $restart && $ENV{CATALYST_ENGINE} eq 'HTTP' ) {
51     $ENV{CATALYST_ENGINE} = 'HTTP::Restarter';
52 }
53 if ( $debug ) {
54     $ENV{CATALYST_DEBUG} = 1;
55 }
56
57 # This is require instead of use so that the above environment
58 # variables can be set at runtime.
59 require NDWeb;
60
61 NDWeb->run( $port, $host, {
62     argv              => \@argv,
63     'fork'            => $fork,
64     keepalive         => $keepalive,
65     restart           => $restart,
66     restart_delay     => $restart_delay,
67     restart_regex     => qr/$restart_regex/,
68     restart_directory => $restart_directory,
69     follow_symlinks   => $follow_symlinks,
70 } );
71
72 1;
73
74 =head1 NAME
75
76 ndweb_server.pl - Catalyst Testserver
77
78 =head1 SYNOPSIS
79
80 ndweb_server.pl [options]
81
82  Options:
83    -d -debug          force debug mode
84    -f -fork           handle each request in a new process
85                       (defaults to false)
86    -? -help           display this help and exits
87       -host           host (defaults to all)
88    -p -port           port (defaults to 3000)
89    -k -keepalive      enable keep-alive connections
90    -r -restart        restart when files get modified
91                       (defaults to false)
92    -rd -restartdelay  delay between file checks
93    -rr -restartregex  regex match files that trigger
94                       a restart when modified
95                       (defaults to '\.yml$|\.yaml$|\.pm$')
96    -restartdirectory  the directory to search for
97                       modified files, can be set mulitple times
98                       (defaults to '[SCRIPT_DIR]/..')
99    -follow_symlinks   follow symlinks in search directories
100                       (defaults to false. this is a no-op on Win32)
101  See also:
102    perldoc Catalyst::Manual
103    perldoc Catalyst::Manual::Intro
104
105 =head1 DESCRIPTION
106
107 Run a Catalyst Testserver for this application.
108
109 =head1 AUTHOR
110
111 Sebastian Riedel, C<sri@oook.de>
112 Maintained by the Catalyst Core Team.
113
114 =head1 COPYRIGHT
115
116 This library is free software, you can redistribute it and/or modify
117 it under the same terms as Perl itself.
118
119 =cut