Skip Menu |
 

This queue is for tickets about the HTTP-Server-Simple CPAN distribution.

Report information
The Basics
Id: 53974
Status: resolved
Priority: 0/
Queue: HTTP-Server-Simple

People
Owner: Nobody in particular
Requestors: nanis [...] cpan.org
Cc:
AdminCc:

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



Subject: HTTP::Server::Simple::CGI : Use user provided CGI class
Download (untitled) / with headers
text/plain 1.3k
I recently uploaded a module <http://search.cpan.org/perldoc/HTTP::Server::Simple::CGI::Simple> to CPAN which uses CGI::Simple rather than CGI.pm to provide a $cgi object to handle_request. brian d foy commented that it might be better to add support to HTTP::Server::Simple::CGI for the name of the CGI class to be specified at run time. I agree with him and, in hindsight, I should have known better than to upload such a stupidly named module to CPAN ;-) To do this without altering the interface to programs that do not care about using a different CGI module, I added the following methods to HTTP::Server::Simple::CGI: set_cgi_class / get_cgi_class set_cgi_init / get_cgi_init In addition, I removed the hard coded use CGI; from the module and modified post_setup_hook so that a CGI.pm object is initialized if no initialization sub is provided and in handler, the $cgi object is instantiated using the user supplied class name rather than the hard coded CGI.pm. If there is no user supplied class name, CGI.pm is used. This seems to work on my machines (ArchLinux and Windows XP both with latest versions of Perl). I think it would be nice if this support could be added to HTTP::Server::Simple::CGI. Alternatively, a module called HTTP::Server::Simple::CGI::Any could be provided (which I can package if you want). Thank you. HTTP::Server::Simple is a very hand module.
Subject: CGI-use-user-supplied.pm
package HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple HTTP::Server::Simple::CGI::Environment); use strict; use warnings; use vars qw($VERSION $default_doc); $VERSION = $HTTP::Server::Simple::VERSION; =head1 NAME HTTP::Server::Simple::CGI - CGI.pm-style version of HTTP::Server::Simple =head1 DESCRIPTION HTTP::Server::Simple was already simple, but some smart-ass pointed out that there is no CGI in HTTP, and so this module was born to isolate the CGI.pm-related parts of this handler. =head2 accept_hook The accept_hook in this sub-class clears the environment to the start-up state. =cut sub accept_hook { my $self = shift; $self->setup_environment(@_); } =head2 post_setup_hook Initializes the global L<CGI> object, as well as other environment settings. =cut sub post_setup_hook { my $self = shift; $self->setup_server_url; if ( my $init = $self->get_cgi_init ) { $init->(); } else { require CGI; CGI::initialize_globals(); } } =head2 set_cgi_class Sets the class to use for creating the C<$cgi> object passed to C<handle_request> and optionally provide initialization code. e.g. $server->set_cgi_class(CGI => sub { require CGI; CGI::initialize_globals(); }); or, if you want to use L<CGI::Simple>, $server->set_cgi_class('CGI::Simple' => sub { require CGI::Simple; }); =cut sub set_cgi_class { my $self = shift; my ($class, $init) = @_; $self->{cgi_class} = $class; $self->{cgi_init} = $init if defined $init; return; } =head2 set_cgi_init =cut sub set_cgi_init { my $self = shift; my ($init) = @_; $self->{cgi_init} = $init; return; } =head2 get_cgi_class =cut sub get_cgi_class { my $self = shift; return $self->{cgi_class}; } =head2 get_cgi_init =cut sub get_cgi_init { my $self = shift; return $self->{cgi_init}; } =head2 setup This method sets up CGI environment variables based on various meta-headers, like the protocol, remote host name, request path, etc. See the docs in L<HTTP::Server::Simple> for more detail. =cut sub setup { my $self = shift; $self->setup_environment_from_metadata(@_); } =head2 handle_request CGI This routine is called whenever your server gets a request it can handle. It's called with a CGI object that's been pre-initialized. You want to override this method in your subclass =cut $default_doc = ( join "", <DATA> ); sub handle_request { my ( $self, $cgi ) = @_; print "HTTP/1.0 200 OK\r\n"; # probably OK by now print "Content-Type: text/html\r\nContent-Length: ", length($default_doc), "\r\n\r\n", $default_doc; } =head2 handler Handler implemented as part of HTTP::Server::Simple API =cut sub handler { my $self = shift; my $cgi; if ( my $cgi_class = $self->get_cgi_class ) { $cgi = $cgi_class->new; } else { require CGI; $cgi = CGI->new; } eval { $self->handle_request($cgi) }; if ($@) { my $error = $@; warn $error; } } 1; __DATA__ <html> <head> <title>Hello!</title> </head> <body> <h1>Congratulations!</h1> <p>You now have a functional HTTP::Server::Simple::CGI running. </p> <p><i>(If you're seeing this page, it means you haven't subclassed HTTP::Server::Simple::CGI, which you'll need to do to make it useful.)</i> </p> </body> </html>
Subject: Re: [rt.cpan.org #53974] HTTP::Server::Simple::CGI : Use user provided CGI class
Date: Tue, 2 Feb 2010 12:11:51 -0800
To: "A. Sinan Unur via RT" <bug-HTTP-Server-Simple [...] rt.cpan.org>
From: Jesse Vincent <jesse [...] fsck.com>
I rewrote your patch somewhat to better match my preferred style for things and to cut down the API size a bit. Can you see if 0.41_01 now headed to CPAN meets your needs? On Mon 25.Jan'10 at 10:43:01 -0500, A. Sinan Unur via RT wrote: Show quoted text
> Mon Jan 25 10:43:00 2010: Request 53974 was acted upon. > Transaction: Ticket created by NANIS > Queue: HTTP-Server-Simple > Subject: HTTP::Server::Simple::CGI : Use user provided CGI class > Broken in: 0.41 > Severity: Normal > Owner: Nobody > Requestors: nanis@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=53974 > > > > I recently uploaded a module > <http://search.cpan.org/perldoc/HTTP::Server::Simple::CGI::Simple> to > CPAN which uses CGI::Simple rather than CGI.pm to provide a $cgi object > to handle_request. > > brian d foy commented that it might be better to add support to > HTTP::Server::Simple::CGI for the name of the CGI class to be specified > at run time. I agree with him and, in hindsight, I should have known > better than to upload such a stupidly named module to CPAN ;-) > > To do this without altering the interface to programs that do not care > about using a different CGI module, I added the following methods to > HTTP::Server::Simple::CGI: > > set_cgi_class / get_cgi_class > > set_cgi_init / get_cgi_init > > In addition, I removed the hard coded use CGI; from the module and > modified post_setup_hook so that a CGI.pm object is initialized if no > initialization sub is provided and in handler, the $cgi object is > instantiated using the user supplied class name rather than the hard > coded CGI.pm. If there is no user supplied class name, CGI.pm is used. > > This seems to work on my machines (ArchLinux and Windows XP both with > latest versions of Perl). > > I think it would be nice if this support could be added to > HTTP::Server::Simple::CGI. Alternatively, a module called > HTTP::Server::Simple::CGI::Any could be provided (which I can package if > you want). > > Thank you. HTTP::Server::Simple is a very hand module.
Download (untitled) / with headers
text/plain 2.3k
Looks good just from examining the source. I am going to test it in my current project some time tomorrow and let you know. Thank you very much. I have benefited a lot from your work. Sinan On Tue Feb 02 15:12:26 2010, jesse@fsck.com wrote: Show quoted text
> > I rewrote your patch somewhat to better match my preferred style for > things and to cut down the API size a bit. Can you see if 0.41_01 now > headed to CPAN meets your needs? > > > > On Mon 25.Jan'10 at 10:43:01 -0500, A. Sinan Unur via RT wrote:
> > Mon Jan 25 10:43:00 2010: Request 53974 was acted upon. > > Transaction: Ticket created by NANIS > > Queue: HTTP-Server-Simple > > Subject: HTTP::Server::Simple::CGI : Use user provided CGI class > > Broken in: 0.41 > > Severity: Normal > > Owner: Nobody > > Requestors: nanis@cpan.org > > Status: new > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=53974 > > > > > > > I recently uploaded a module > > <http://search.cpan.org/perldoc/HTTP::Server::Simple::CGI::Simple> to > > CPAN which uses CGI::Simple rather than CGI.pm to provide a $cgi object > > to handle_request. > > > > brian d foy commented that it might be better to add support to > > HTTP::Server::Simple::CGI for the name of the CGI class to be specified > > at run time. I agree with him and, in hindsight, I should have known > > better than to upload such a stupidly named module to CPAN ;-) > > > > To do this without altering the interface to programs that do not care > > about using a different CGI module, I added the following methods to > > HTTP::Server::Simple::CGI: > > > > set_cgi_class / get_cgi_class > > > > set_cgi_init / get_cgi_init > > > > In addition, I removed the hard coded use CGI; from the module and > > modified post_setup_hook so that a CGI.pm object is initialized if no > > initialization sub is provided and in handler, the $cgi object is > > instantiated using the user supplied class name rather than the hard > > coded CGI.pm. If there is no user supplied class name, CGI.pm is used. > > > > This seems to work on my machines (ArchLinux and Windows XP both with > > latest versions of Perl). > > > > I think it would be nice if this support could be added to > > HTTP::Server::Simple::CGI. Alternatively, a module called > > HTTP::Server::Simple::CGI::Any could be provided (which I can package if > > you want). > > > > Thank you. HTTP::Server::Simple is a very hand module.
> >
Download (untitled) / with headers
text/plain 2.8k
I tested on Windows XP SP3 w/ ActiveState perl v.5.10.1.1006 using dmake & mingw installed from PPM. Everything worked. My application also seems to be perfectly content. I am marking this as 'resolved' (this is the first time I am doing this so I hope it is OK). Thank you very much. Sinan On Tue Feb 02 19:56:02 2010, NANIS wrote: Show quoted text
> Looks good just from examining the source. I am going to test it in my > current project some time tomorrow and let you know. > > Thank you very much. I have benefited a lot from your work. > > Sinan > > On Tue Feb 02 15:12:26 2010, jesse@fsck.com wrote:
> > > > I rewrote your patch somewhat to better match my preferred style for > > things and to cut down the API size a bit. Can you see if 0.41_01 now > > headed to CPAN meets your needs? > > > > > > > > On Mon 25.Jan'10 at 10:43:01 -0500, A. Sinan Unur via RT wrote:
> > > Mon Jan 25 10:43:00 2010: Request 53974 was acted upon. > > > Transaction: Ticket created by NANIS > > > Queue: HTTP-Server-Simple > > > Subject: HTTP::Server::Simple::CGI : Use user provided CGI class > > > Broken in: 0.41 > > > Severity: Normal > > > Owner: Nobody > > > Requestors: nanis@cpan.org > > > Status: new > > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=53974 > > > > > > > > > > I recently uploaded a module > > > <http://search.cpan.org/perldoc/HTTP::Server::Simple::CGI::Simple> to > > > CPAN which uses CGI::Simple rather than CGI.pm to provide a $cgi
object Show quoted text
> > > to handle_request. > > > > > > brian d foy commented that it might be better to add support to > > > HTTP::Server::Simple::CGI for the name of the CGI class to be
specified Show quoted text
> > > at run time. I agree with him and, in hindsight, I should have known > > > better than to upload such a stupidly named module to CPAN ;-) > > > > > > To do this without altering the interface to programs that do not care > > > about using a different CGI module, I added the following methods to > > > HTTP::Server::Simple::CGI: > > > > > > set_cgi_class / get_cgi_class > > > > > > set_cgi_init / get_cgi_init > > > > > > In addition, I removed the hard coded use CGI; from the module and > > > modified post_setup_hook so that a CGI.pm object is initialized if no > > > initialization sub is provided and in handler, the $cgi object is > > > instantiated using the user supplied class name rather than the hard > > > coded CGI.pm. If there is no user supplied class name, CGI.pm is used. > > > > > > This seems to work on my machines (ArchLinux and Windows XP both with > > > latest versions of Perl). > > > > > > I think it would be nice if this support could be added to > > > HTTP::Server::Simple::CGI. Alternatively, a module called > > > HTTP::Server::Simple::CGI::Any could be provided (which I can
package if Show quoted text
> > > you want). > > > > > > Thank you. HTTP::Server::Simple is a very hand module.
> > > >
> >


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.