You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Svein E. Seldal" <Sv...@solidas.com> on 2003/03/11 01:40:02 UTC
Newbie help with mod-perl 2.0
Hello,
I'm running: Apache/2.0.44 (Win32) mod_perl/1.99_09-dev Perl/v5.8.0
I'm toying around with mod_perl handlers. And I've written this silly
little app attached below which works partly. My problem is simple:
- I need to get the querystring (and possibly the xform contents as
well). And I would like to receive it parsed (in a hash). But when I use
$r->args() I get the whole lot in a single variable. And I get hints
from doc's lying around that args() is depreciated. How can I get the
querystring anno mod_perl 2.0? Do I have to parse it myself?
- The script below leaves a message in apache's error log:
Can't locate object method "request" via package "Apache::RequestRec" at
D:/Prosjekt/designs/gear/gear2/Test/Test.pm line 49.
I would guess that I lack a "use Apache::SomeThing;", but I cant figure
it out. (Mainly because I cant find references to it in any documentation.)
Any help would be very useful, please. I'm stuck. (Even if you replied
with only four lines of perl code :o)
Thanks,
Svein
package Test::Test;
use strict;
use warnings;
use Apache::Reload;
use Apache::RequestRec;
use Apache::RequestIO;
use Apache::Const -compile => qw(OK);
sub handler {
my $r = shift;
$r->content_type('text/plain');
print "mod_perl 2.0 rocks!\n";
my $path_info = $r->path_info();
print "path_info: $path_info\n";
my $method = $r->method();
print "method: $method\n";
my %a = $r->args();
my @b = %a;
print "Args " . @b . ": @b\n";
my $content = $r->request();
print "Content: $content\n";
return Apache::OK;
}
1;
Re: Newbie help with mod-perl 2.0
Posted by Stas Bekman <st...@stason.org>.
> Apache::Request is not a mod_perl core module. It's a 3rd party module.
> It could be part of the core if Apache 2.0 were to accept the C library,
> but they didn't. So it's going to have its own life. And if you are
> interested in Apache::Request subscribe to
> apreq-subscribe@httpd.apache.org.
oops, s/apreq-subscribe\@httpd.apache.org/apreq-dev-subscribe\@httpd.apache.org/
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Newbie help with mod-perl 2.0
Posted by Stas Bekman <st...@stason.org>.
Svein E. Seldal wrote:
> Hi,
>
> Thanks for your help. I'm closer to my goal, thanks to you. However, I
> have more questions, and I'd hoped you'd enlighten me. I'm reading a lot
> of documentation on the web about MP2, but I need some more information
> to clear things out, and to stitch all these small threads of
> information together.
Sure, after reading the available docs you are welcome to ask questions here.
> First of all, my intentions was to use the new MP2 methods only, because
> I'm redesigning things from scratch. And thus having to use
> Apache::compat is a slightly setback, isn't it?
It is.
> Do you have any idea
> when the new MP2-ish methods will be ready?
Which ones are you talking about? args() and content() would never be the same
as they were in mp1 (it's not a question of time). See:
http://perl.apache.org/docs/2.0/user/compat/compat.html#C__r_E_gt_content_
> Especially Apache::Request?
Apache::Request is not a mod_perl core module. It's a 3rd party module. It
could be part of the core if Apache 2.0 were to accept the C library, but they
didn't. So it's going to have its own life. And if you are interested in
Apache::Request subscribe to apreq-subscribe@httpd.apache.org.
Joe is working on finishing the C library, feel free to ask if he needs help
and help him to finish it faster. Once the C library is completed the Perl
glue can be written. But not before.
> With other words Apache::Request will be the new MP2 way to do things in
> the future?
Yes.
> Now, testing revealed that $r->args() is only containing the
> query-string that is part of the URI (now I would guess you say daahh)
> -- this is usually used in context with GET requests.
>
> When I send a POST request, the query-string will be stored in the
> contents of the message, and not in $r->args(). However, I still need to
> parse the string as with the GET message.
>
> Last but least, I need to support GET form-data (to support file
> uploads), which leaves us with a third type of argument syntax.
>
> Are there any methodes that I can use (now) to parse these POST
> requests, or do I have to write a parser myself? Will Apache::Request be
> able to handle these cases? (Because if it will, I can probably settle
> for args() and content() now, and use my own parser until
> Apache::Request shows up.)
Yes. But you can use CGI.pm for now, which does all that, but slower (pure perl).
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Newbie help with mod-perl 2.0
Posted by Nick Tonkin <ni...@tonkinresolutions.com>.
On Tue, 11 Mar 2003, Svein E. Seldal wrote:
> Hi,
>
> Thanks for your help. I'm closer to my goal, thanks to you. However, I
> have more questions, and I'd hoped you'd enlighten me. I'm reading a lot
> of documentation on the web about MP2, but I need some more information
> to clear things out, and to stitch all these small threads of
> information together.
>
> First of all, my intentions was to use the new MP2 methods only, because
> I'm redesigning things from scratch. And thus having to use
> Apache::compat is a slightly setback, isn't it?
Yes. You are doing the Right Thing.
> Do you have any idea
> when the new MP2-ish methods will be ready? Especially Apache::Request?
It's under development. The others are all there, or what specifically are
you lacking?
Meanwhile you use CGI.pm ...
>
> With other words Apache::Request will be the new MP2 way to do things in
> the future?
Yes. Subscribe to apreq-dev@apache.org to get the progress updates.
>
> Now, testing revealed that $r->args() is only containing the
> query-string that is part of the URI (now I would guess you say daahh)
> -- this is usually used in context with GET requests.
>
> When I send a POST request, the query-string will be stored in the
> contents of the message, and not in $r->args(). However, I still need to
> parse the string as with the GET message.
>
> Last but least, I need to support GET form-data (to support file
> uploads), which leaves us with a third type of argument syntax.
>
> Are there any methodes that I can use (now) to parse these POST
> requests, or do I have to write a parser myself? Will Apache::Request be
> able to handle these cases? (Because if it will, I can probably settle
> for args() and content() now, and use my own parser until
> Apache::Request shows up.)
CGI.pm should be able to do all of the above .... and many of its methods
are the same as Apache::Request's.
HTH,
- nick
--
~~~~~~~~~~~~~~~~~~~~
Nick Tonkin {|8^)>
Re: Newbie help with mod-perl 2.0
Posted by "Svein E. Seldal" <Sv...@solidas.com>.
Hi,
Thanks for your help. I'm closer to my goal, thanks to you. However, I
have more questions, and I'd hoped you'd enlighten me. I'm reading a lot
of documentation on the web about MP2, but I need some more information
to clear things out, and to stitch all these small threads of
information together.
First of all, my intentions was to use the new MP2 methods only, because
I'm redesigning things from scratch. And thus having to use
Apache::compat is a slightly setback, isn't it? Do you have any idea
when the new MP2-ish methods will be ready? Especially Apache::Request?
With other words Apache::Request will be the new MP2 way to do things in
the future?
Now, testing revealed that $r->args() is only containing the
query-string that is part of the URI (now I would guess you say daahh)
-- this is usually used in context with GET requests.
When I send a POST request, the query-string will be stored in the
contents of the message, and not in $r->args(). However, I still need to
parse the string as with the GET message.
Last but least, I need to support GET form-data (to support file
uploads), which leaves us with a third type of argument syntax.
Are there any methodes that I can use (now) to parse these POST
requests, or do I have to write a parser myself? Will Apache::Request be
able to handle these cases? (Because if it will, I can probably settle
for args() and content() now, and use my own parser until
Apache::Request shows up.)
Thanks,
Svein
Re: Newbie help with mod-perl 2.0
Posted by Stas Bekman <st...@stason.org>.
Svein E. Seldal wrote:
> Hello,
>
> I'm running: Apache/2.0.44 (Win32) mod_perl/1.99_09-dev Perl/v5.8.0
good choice ;)
> I'm toying around with mod_perl handlers. And I've written this silly
> little app attached below which works partly. My problem is simple:
>
> - I need to get the querystring (and possibly the xform contents as
> well). And I would like to receive it parsed (in a hash). But when I use
> $r->args() I get the whole lot in a single variable. And I get hints
> from doc's lying around that args() is depreciated. How can I get the
> querystring anno mod_perl 2.0? Do I have to parse it myself?
$r->args in the *list* context is deprecated. See:
http://perl.apache.org/docs/2.0/user/compat/compat.html#C__r_E_gt_args__in_an_Array_Context
For now you can copy the pure-perl implementation from Apache/compat.pm. Later
when Apache::Request is ported you will be able to use the faster C implementation
> - The script below leaves a message in apache's error log:
>
> Can't locate object method "request" via package "Apache::RequestRec" at
> D:/Prosjekt/designs/gear/gear2/Test/Test.pm line 49.
>
> I would guess that I lack a "use Apache::SomeThing;", but I cant figure
> it out. (Mainly because I cant find references to it in any documentation.)
Because you haven't read this:
http://perl.apache.org/docs/2.0/user/compat/compat.html#Code_Porting
which at the end links you to:
http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html
Also see:
http://perl.apache.org/docs/2.0/devel/porting/porting.html#Porting_mod_perl_1_0_Modules_to_Work_with_mod_perl_2_0_
> package Test::Test;
> use strict;
> use warnings;
> use Apache::Reload;
> use Apache::RequestRec;
> use Apache::RequestIO;
> use Apache::Const -compile => qw(OK);
>
> sub handler {
> my $r = shift;
> $r->content_type('text/plain');
>
> print "mod_perl 2.0 rocks!\n";
>
> my $path_info = $r->path_info();
> print "path_info: $path_info\n";
>
> my $method = $r->method();
> print "method: $method\n";
>
> my %a = $r->args();
> my @b = %a;
> print "Args " . @b . ": @b\n";
>
> my $content = $r->request();
/home/stas> lookup request
to use method 'request' add:
use Apache::RequestUtil ();
see:
http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html#Command_Line_Lookups
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com