[Catalyst-dev] Setting the port in the configuration
Thomas Klausner
domm at cpan.org
Mon Sep 8 21:47:24 BST 2008
Hi!
As we have some cat apps running that need to talk to each other, we'd
love to start them on the same port, even if we forget the --port flag
to ourapp_server.pl
After a very short conversation on IRC, I hacked together these two
patches.
port_in_config.Catalyst-Runtime-5.70.patch changes
Catalyst::Engine::HTTP to use the port defined in the 'Engine::Server'
config section. The problem with this approach is that one cannot
override the configured port from the commandline or environment.
port_in_config.Catalyst-Devel-1.00.patch changes lib/Catalyst/Helper.pm
(or rather the appname_server.pl script) to add a check for the config
item when trying to figure out the port.
I like port_in_config.Catalyst-Devel-1.00.patch a bit more, even though
it makes it necessary to regenerate the _server.pl script for all apps
that want the functionality.
What do you think?
Any chances that one of these patches will be applied? Or would you
rather want patches for the devel versions (5.80/1.10) ?
--
#!/usr/bin/perl http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
-------------- next part --------------
Index: lib/Catalyst/Engine/HTTP.pm
===================================================================
--- lib/Catalyst/Engine/HTTP.pm (revision 8365)
+++ lib/Catalyst/Engine/HTTP.pm (working copy)
@@ -201,6 +201,12 @@
$host = gethostbyaddr( $addr, AF_INET ) || inet_ntoa($addr);
}
+ if ( $self->config->{'Engine::Server'}
+ && $self->config->{'Engine::Server'}{port} )
+ {
+ $port = $self->config->{'Engine::Server'}{port};
+ }
+
# Handle requests
# Setup socket
-------------- next part --------------
Index: lib/Catalyst/Helper.pm
===================================================================
--- lib/Catalyst/Helper.pm (revision 8365)
+++ lib/Catalyst/Helper.pm (working copy)
@@ -930,7 +930,7 @@
my $fork = 0;
my $help = 0;
my $host = undef;
-my $port = $ENV{[% appenv %]_PORT} || $ENV{CATALYST_PORT} || 3000;
+my $port = undef;
my $keepalive = 0;
my $restart = $ENV{[% appenv %]_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
my $restart_delay = 1;
@@ -967,6 +967,14 @@
# variables can be set at runtime.
require [% name %];
+my $configured_port = undef;
+if ( [% name %]->config->{'Engine::Server'}
+ && [% name %]->config->{'Engine::Server'}{'port'} )
+{
+ $configured_port = [% name %]->config->{'Engine::Server'}{'port'};
+}
+$port ||= $ENV{[% appenv %]_PORT} || $ENV{CATALYST_PORT} || $configured_port || 3000;
+
[% name %]->run( $port, $host, {
argv => \@argv,
'fork' => $fork,
More information about the Catalyst-dev
mailing list