Initial module
Tomas Doran [Mon, 8 Aug 2011 22:39:24 +0000 (23:39 +0100)]
15 files changed:
.gitignore [new file with mode: 0644]
Changes [new file with mode: 0644]
MANIFEST.SKIP [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
lib/CatalystX/Script/Server/Starman.pm [new file with mode: 0644]
t/00-load.t [new file with mode: 0644]
t/author/pod-coverage.t [new file with mode: 0644]
t/author/pod.t [new file with mode: 0644]
t/lib/Makefile.PL [new file with mode: 0644]
t/lib/TestApp.pm [new file with mode: 0644]
t/lib/TestApp/Controller/Root.pm [new file with mode: 0644]
t/lib/script/testapp_server.pl [new file with mode: 0644]
t/lib/script/testapp_test.pl [new file with mode: 0644]
t/live-test.t [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..f65516f
--- /dev/null
@@ -0,0 +1,12 @@
+MYMETA.yml
+MYMETA.json
+cover_db
+META.yml
+Makefile
+blib
+inc
+pm_to_blib
+MANIFEST
+Makefile.old
+CatalystX-Script-Server-Starman-*
+
diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644 (file)
index 0000000..adf6e6d
--- /dev/null
@@ -0,0 +1,11 @@
+.git/
+blib
+pm_to_blib
+MANIFEST.bak
+MANIFEST.SKIP~
+cover_db
+Makefile$
+Makefile.old$
+^CatalystX-Script-Server-Starman-
+^.gitignore
+
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..069f0ad
--- /dev/null
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+use inc::Module::Install 0.91;
+use Module::Install::AuthorRequires;
+use Module::Install::AuthorTests;
+
+name 'CatalystX-Script-Server-Starman';
+all_from 'lib/CatalystX/Script/Server/Starman.pm';
+
+requires 'Moose';
+requires 'namespace::autoclean';
+
+build_requires 'Catalyst::Runtime' => '5.89';
+build_requires 'Test::WWW::Mechanize::Catalyst';
+build_requires 'Test::More' => '0.88';
+
+author_requires 'Test::Pod::Coverage' => '1.04';
+author_requires 'Test::Pod' => '1.14';
+
+author_tests 't/author';
+
+resources repository => 'git://somewhere.com/myproject.git';
+
+if ($Module::Install::AUTHOR) {
+    system("pod2text lib/CatalystX/Script/Server/Starman.pm > README")
+        and die $!;
+}
+
+WriteAll();
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..f30d51d
--- /dev/null
+++ b/README
@@ -0,0 +1,71 @@
+NAME
+    CatalystX::Script::Server::Starman - Replace the development server with
+    Starman
+
+SYNOPSIS
+        myapp_server.pl [options]
+
+           -d --debug           force debug mode
+           -f --fork            handle each request in a new process
+                                (defaults to false)
+           -? --help            display this help and exits
+           -h --host            host (defaults to all)
+           -p --port            port (defaults to 3000)
+           --follow_symlinks    follow symlinks in search directories
+                                (defaults to false. this is a no-op on Win32)
+           --background         run the process in the background
+           --pidfile            specify filename for pid file
+           --workers            Initial number of workers to spawn (defaults to 5)
+           --min_servers        Minimum number of worker processes runnning
+           --min_spare_servers  Minimum number of spare workers (more are forked
+                                if there are less spare than this)
+           --max_spare_servers  Maximum number of spare workers (workers are killed
+                                if there are more spare than this)
+           --max_servers        Maximum number of workers in total.
+           --max_requests       Maximum number of requests each worker will handle
+           --backlog            Number of backlogged connections allowed
+           --user               User to run as
+           --group              Group to run as
+
+         See also:
+           perldoc Starman
+           perldoc plackup
+           perldoc Catalyst::PSGI
+
+DESCRIPTION
+    A Catalyst extension to replace the development server with Starman.
+
+    This module replaces the functionality of
+    Catalyst::Engine::HTTP::Prefork, which is now deprecated.
+
+    It provides access to the prefork engine specific options which were
+    previously added by hacking your server script.
+
+Adding this to your application
+    Just write a server script in your application which inherits from this
+    package.
+
+    For example:
+
+        package MyApp::Script::Server;
+        use Moose;
+        use namespace::autoclean;
+
+        extends 'CatalystX::Script::Server::Starman';
+
+        1;
+
+SEE ALSO
+    plackup - can be used to start your application ".psgi" under Starman
+
+    Catalyst::PSGI
+
+AUTHOR
+    Tomas Doran (t0m) "<bobtfish@bobtfish.net"
+
+COPYRIGHT & LICENSE
+    Copyright 2009 the above author(s).
+
+    This sofware is free software, and is licensed under the same terms as
+    perl itself.
+
diff --git a/lib/CatalystX/Script/Server/Starman.pm b/lib/CatalystX/Script/Server/Starman.pm
new file mode 100644 (file)
index 0000000..ce297d9
--- /dev/null
@@ -0,0 +1,140 @@
+package CatalystX::Script::Server::Starman;
+use Moose;
+use MooseX::Types::Moose qw/ Str Int /;
+use Pod::Usage;
+use Pod::Find qw(pod_where);
+use namespace::autoclean;
+
+our $VERSION = '0.01';
+
+extends 'Catalyst::Script::Server';
+
+has '+fork' => ( default => 1, init_arg => undef );
+
+has [qw/ keepalive restart restart_delay restart_regex restart_directory/] => ( init_arg => undef, is => 'ro' );
+
+has workers => (
+    isa => Int,
+    is => 'ro',
+    default => 5,
+);
+
+has [qw/
+    min_servers
+    min_spare_servers
+    max_spare_servers
+    max_servers
+    max_requests
+    backlog
+/] => ( isa => Int, is => 'ro' );
+
+has [qw/
+    user
+    group
+/] => ( isa => Str, is => 'ro' );
+
+around _plack_loader_args => sub {
+    my ($orig, $self, @args) = @_;
+    my %out = $self->$orig(@args);
+    foreach my $key (qw/
+        workers
+        min_servers
+        min_spare_servers
+        max_spare_servers
+        max_servers
+        max_requests
+        backlog
+        user
+        group
+    /) {
+        $out{$key} = $self->$key();
+    }
+    return %out;
+};
+
+sub _getopt_full_usage {
+    my $self = shift;
+    pod2usage( -input => pod_where({-inc => 1}, __PACKAGE__), -verbose => 2 );
+    exit 0;
+}
+
+1;
+
+=head1 NAME
+
+CatalystX::Script::Server::Starman - Replace the development server with Starman
+
+=head1 SYNOPSIS
+
+    myapp_server.pl [options]
+
+       -d --debug           force debug mode
+       -f --fork            handle each request in a new process
+                            (defaults to false)
+       -? --help            display this help and exits
+       -h --host            host (defaults to all)
+       -p --port            port (defaults to 3000)
+       --follow_symlinks    follow symlinks in search directories
+                            (defaults to false. this is a no-op on Win32)
+       --background         run the process in the background
+       --pidfile            specify filename for pid file
+       --workers            Initial number of workers to spawn (defaults to 5)
+       --min_servers        Minimum number of worker processes runnning
+       --min_spare_servers  Minimum number of spare workers (more are forked
+                            if there are less spare than this)
+       --max_spare_servers  Maximum number of spare workers (workers are killed
+                            if there are more spare than this)
+       --max_servers        Maximum number of workers in total.
+       --max_requests       Maximum number of requests each worker will handle
+       --backlog            Number of backlogged connections allowed
+       --user               User to run as
+       --group              Group to run as
+
+     See also:
+       perldoc Starman
+       perldoc plackup
+       perldoc Catalyst::PSGI
+
+=head1 DESCRIPTION
+
+A Catalyst extension to replace the development server with L<Starman>.
+
+This module replaces the functionality of L<Catalyst::Engine::HTTP::Prefork>,
+which is now deprecated.
+
+It provides access to the prefork engine specific options which were previously
+added by hacking your server script.
+
+=head1 Adding this to your application
+
+Just write a server script in your application which inherits from this
+package.
+
+For example:
+
+    package MyApp::Script::Server;
+    use Moose;
+    use namespace::autoclean;
+
+    extends 'CatalystX::Script::Server::Starman';
+
+    1;
+
+=head1 SEE ALSO
+
+L<plackup> - can be used to start your application C<.psgi> under Starman
+
+L<Catalyst::PSGI>
+
+=head1 AUTHOR
+
+Tomas Doran (t0m) C<< <bobtfish@bobtfish.net >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 the above author(s).
+
+This sofware is free software, and is licensed under the same terms as perl itself.
+
+=cut
+
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644 (file)
index 0000000..dcd7c05
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+use_ok 'CatalystX::Script::Server::Starman';
+
+done_testing;
diff --git a/t/author/pod-coverage.t b/t/author/pod-coverage.t
new file mode 100644 (file)
index 0000000..83b1a5d
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Pod::Coverage 1.04;
+all_pod_coverage_ok();
diff --git a/t/author/pod.t b/t/author/pod.t
new file mode 100644 (file)
index 0000000..08d2afd
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+use Test::Pod 1.14;
+all_pod_files_ok();
diff --git a/t/lib/Makefile.PL b/t/lib/Makefile.PL
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm
new file mode 100644 (file)
index 0000000..a18a1ef
--- /dev/null
@@ -0,0 +1,11 @@
+package TestApp;
+use Moose;
+use namespace::autoclean;
+
+use Catalyst;
+
+extends 'Catalyst';
+
+__PACKAGE__->setup;
+
+1;
diff --git a/t/lib/TestApp/Controller/Root.pm b/t/lib/TestApp/Controller/Root.pm
new file mode 100644 (file)
index 0000000..6bbaa52
--- /dev/null
@@ -0,0 +1,17 @@
+package TestApp::Controller::Root;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller' }
+
+__PACKAGE__->config(namespace => q{});
+
+sub base : Chained('/') PathPart('') CaptureArgs(0) {}
+
+# your actions replace this one
+sub main : Chained('base') PathPart('') Args(0) {
+    my ($self, $ctx) = @_;
+    $ctx->res->body('<h1>It works</h1>');
+}
+
+__PACKAGE__->meta->make_immutable;
diff --git a/t/lib/script/testapp_server.pl b/t/lib/script/testapp_server.pl
new file mode 100644 (file)
index 0000000..b42c26f
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+
+BEGIN {
+    $ENV{CATALYST_SCRIPT_GEN} = 40;
+}
+
+use Catalyst::ScriptRunner;
+Catalyst::ScriptRunner->run('TestApp', 'Server');
+
+1;
diff --git a/t/lib/script/testapp_test.pl b/t/lib/script/testapp_test.pl
new file mode 100644 (file)
index 0000000..1cc8d04
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/..";
+use Catalyst::Test 'TestApp';
+
+print request($ARGV[0])->content . "\n";
+
+1;
diff --git a/t/live-test.t b/t/live-test.t
new file mode 100644 (file)
index 0000000..4ca1c81
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+
+# setup library path
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+
+# make sure testapp works
+use ok 'TestApp';
+
+# a live test against TestApp, the test application
+use Test::WWW::Mechanize::Catalyst 'TestApp';
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+$mech->get_ok('http://localhost/', 'get main page');
+$mech->content_like(qr/it works/i, 'see if it has our text');
+
+done_testing;