Howdy,
> Could Eric or someone provide some examples of how we could take advantage
> of this new method? What modules do you use?
I'm using a module called OpenPlugin, which is soon to appear on CPAN. Amongst
a bunch of other things, OpenPlugin abstracts Apache::Request and CGI, allowing
you to seamlessly move your application between the two (and any others you
write a driver for) without needing to alter your code.
CGI::Application's new functionality will allow you to use OpenPlugin, or any
number of other "query" modules, instead of CGI. By default, it does still use
CGI.pm.
What CGI::Application is doing, is instead of immediatly loading CGI.pm when
CGI::App is loaded, it calls a subroutine, cgiapp_get_query(), which loads
CGI.pm for you.
So, to use another module instead of CGI.pm, you just need to override the
cgiapp_get_query function in your subclass. For example:
package MyCGI::Application::Subclass;
use base qw( CGI::Application );
sub cgiapp_get_query {
my $self = shift;
require CGI::Alternate;
my $alternate_cgi_object = CGI::Alternate->new();
return $alternate_cgi_object;
}
Or, in your case, you were looking for CGI::Base:
sub cgiapp_get_query {
my $self = shift;
require CGI::Base;
my $cgi_base_obj = CGI::Base->new();
return $cgi_base_obj;
}
There's one catch to this whole thing. Your alternative query object
(CGI::Base in this case) must have a param() and header() function that works
like CGI's does. Since almost no other query object does, you'll need to write
a wrapper class. I'm still working out some of the details on how I'm going
to do this, but one example of how this might work is:
package MyCGI::Application::Subclass;
use base qw( CGI::Application );
sub cgiapp_get_query {
my $self = shift;
require CGI::Base::Wrapper;
my $cgi_base_obj = CGI::Base::Wrapper->new();
return $cgi_base_obj;
}
package CGI::Base::Wrapper;
use CGI::Base();
@CGI::Base::Wrapper::ISA = qw( CGI::Base );
sub param {
my $self = shift;
my @params = @_;
my $cgi_base_obj = $self->query;
return $cgi_base_obj->var( @params );
}
sub header {
my $self = shift;
my @params = @_;
my $cgi_base_obj = $self->query;
return $cgi_base_object->SendHeaders( @params );
}
Notice that your cgiapp_get_query sub is no longer instanciating a new
CGI::Base object, it's instead instanciating a new CGI::Base::Wrapper object.
We've made CGI::Base::Wrapper a subclass of CGI::Base.
Then, we have two functions in the wrapper class -- param() and header().
Without the wrapper class, your program would die whenever CGI::Application
tried to call param() or header(). So what we did is create these two methods,
and have them call the appropriate function within CGI::Base, and they'll
return the values which CGI::Application was expecting.
The above code has not been tested, but it should be pretty close :-)
Have fun,
-Eric
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.