Skip Menu |
 

This queue is for tickets about the FCGI-Engine CPAN distribution.

Report information
The Basics
Id: 33885
Status: resolved
Priority: 0/
Queue: FCGI-Engine

People
Owner: stevan.little [...] gmail.com
Requestors: bcbailey [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Attachments


Subject: PATCH: handler_args
Download (untitled) / with headers
text/plain 159b
Stevan, I have attached a patch (with tests and docs) that adds the ability to pass specific args to the handler in FCGI::Engine. Regards, Bradley C Bailey
Subject: fcgi-engine-handler-args.patch
diff -ruN FCGI-Engine-0.03.orig/lib/FCGI/Engine.pm FCGI-Engine-0.03/lib/FCGI/Engine.pm --- FCGI-Engine-0.03.orig/lib/FCGI/Engine.pm 2008-02-03 14:39:27.000000000 -0700 +++ FCGI-Engine-0.03/lib/FCGI/Engine.pm 2008-03-04 17:53:57.000000000 -0700 @@ -77,6 +77,13 @@ default => sub { 'handler' }, ); +has 'handler_args' => ( + metaclass => 'NoGetopt', + is => 'ro', + isa => 'ArrayRef', + default => sub { [ CGI::Simple->new ] }, +); + has 'pre_fork_init' => ( metaclass => 'NoGetopt', is => 'ro', @@ -102,6 +109,7 @@ my $handler_class = $self->handler_class; my $handler_method = $self->handler_method; + my $handler_args = $self->handler_args; Class::MOP::load_class($handler_class) unless blessed $handler_class; @@ -164,7 +172,7 @@ $ENV{PATH_INFO} ||= delete $ENV{SCRIPT_NAME}; } - $handler_class->$handler_method(CGI::Simple->new); + $handler_class->$handler_method(@$handler_args); $proc_manager && $proc_manager->post_dispatch; } @@ -294,6 +302,12 @@ to server as a dispatch entry point to your web application. It will default to C<handler>. +=item I<handler_args> + +These are the arguments to pass to the I<handler_method>. It is +specified as an arrayref, but expanded when passed to the +I<handler_method>. It defaults to a L<CGI::Simple> object. + =item I<pre_fork_init> This is an optional CODE reference which will be executed prior diff -ruN FCGI-Engine-0.03.orig/t/001_basic.t FCGI-Engine-0.03/t/001_basic.t --- FCGI-Engine-0.03.orig/t/001_basic.t 2008-02-03 13:45:56.000000000 -0700 +++ FCGI-Engine-0.03/t/001_basic.t 2008-03-04 17:47:36.000000000 -0700 @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 15; use Test::Moose; BEGIN { @@ -31,6 +31,8 @@ is($e->handler_class, 'Foo', '... we have a handler class'); is($e->handler_method, 'handler', '... we have our default handler method'); +is(ref $e->handler_args, 'ARRAY', '... default handler args is an arrayref'); +isa_ok($e->handler_args->[0], 'CGI::Simple', '... default arg isa CGI::Simple'); eval { $e->run }; ok(!$@, '... we ran the handler okay'); diff -ruN FCGI-Engine-0.03.orig/t/003_basic_with_options.t FCGI-Engine-0.03/t/003_basic_with_options.t --- FCGI-Engine-0.03.orig/t/003_basic_with_options.t 2008-02-03 13:59:48.000000000 -0700 +++ FCGI-Engine-0.03/t/003_basic_with_options.t 2008-03-04 17:50:41.000000000 -0700 @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 15; use Test::Moose; BEGIN { @@ -12,7 +12,17 @@ { package Foo; - sub dispatcher { ::pass("... dispatcher was called") } + sub dispatcher + { + if (@_ == 3 && $_[0] eq 'Foo' && $_[1] eq 'q') + { + ::pass("... dispatcher was called"); + } + else + { + ::fail("... dispatcher was called with wrong args"); + } + } } @ARGV = (); @@ -20,6 +30,7 @@ my $e = FCGI::Engine->new_with_options( handler_class => 'Foo', handler_method => 'dispatcher', + handler_args => [ q => CGI::Simple->new ], nproc => 10, ); isa_ok($e, 'FCGI::Engine'); @@ -35,6 +46,8 @@ is($e->handler_class, 'Foo', '... we have a handler class'); is($e->handler_method, 'dispatcher', '... we have our default handler method'); +is(ref $e->handler_args, 'ARRAY', '... we got our handler args as an arrayref'); +is($e->handler_args->[0], 'q', '... first argument is correct'); eval { $e->run }; ok(!$@, '... we ran the handler okay');
Download (untitled) / with headers
text/plain 388b
I have altered your patch somewhat. Instead of handler_args being an ARRAY ref, it has been changed to handler_args_builder and is a CODE ref which gets called for every request. This is closer to the original behavior and assures that there is no issues with sharing across multiple backend processes. THis is being released onto the CPAN right now as version 0.04. Thanks, - Stevan


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.