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