You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John Day <jo...@wordsnimages.com> on 2003/10/30 17:23:09 UTC
Switch (module) and mod_perl problem.
In my never ending search for more elegant looking and self-documenting code I decided to try out the Switch module. In the following fragment of code:
#!/usr/local/bin/perl
# AppSys: Manage Profile
use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
use Switch;
my $cgi = CGI->new;
my $control = 'Search';
switch ( $control ) {
case ("Search") {
print $cgi->header;
print $cgi->start_html;
print $cgi->p("Search");
print $cgi->end_html;
}
}
produces the following in the Apache error log:
[error] syntax error at /home/appsys/www/modperl/ap03.pl line 12, near ") {"
syntax error at /home/appsys/www/modperl/ap03.pl line 14, near "}
}"
When run as an Apache::Registry script.
When run under mod_cgi (i.e. run from the cgi-bin directory on the same server, it works perfectly and prints 'Search' on the browser.
Server is: RH8.0, Apache 1.3.28, mod_perl 1.28, Perl 5.8.1
John
Re: Switch (module) and mod_perl problem.
Posted by Steve Hay <st...@uk.radan.com>.
Geoffrey Young wrote:
>
>
> John Day wrote:
>
>> In my never ending search for more elegant looking and
>> self-documenting code I decided to try out the Switch module. In the
>> following fragment of code:
>> #!/usr/local/bin/perl
>>
>> # AppSys: Manage Profile
>>
>> use strict;
>> use CGI qw/:standard/;
>> use CGI::Carp qw(fatalsToBrowser);
>> use Switch;
>>
>> my $cgi = CGI->new;
>>
>> my $control = 'Search';
>> switch ( $control ) {
>> case ("Search") { print $cgi->header;
>> print $cgi->start_html;
>> print $cgi->p("Search");
>> print $cgi->end_html;
>> }
>> }
>>
>> produces the following in the Apache error log:
>> [error] syntax error at /home/appsys/www/modperl/ap03.pl line 12,
>> near ") {"
>> syntax error at /home/appsys/www/modperl/ap03.pl line 14, near "}
>> }"
>>
>> When run as an Apache::Registry script.
>
>
> Switch uses source filters, which probably doesn't work well with the
> way Registry wraps scripts up into handler() subs.
>
> without getting too far into Filter::Util::Call, Switch.pm, or
> Text::Balanced there is probably not much we can do to help.
Indeed. I've tried and failed to get source code filters working under
Apache::Registry in the past, and I tried it again only recently with
the same result -- it doesn't work.
However, it does work fine if you write mod_perl handler()'s yourself.
- Steve
Re: Switch (module) and mod_perl problem.
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
John Day wrote:
> In my never ending search for more elegant looking and self-documenting code I decided to try out the Switch module. In the following fragment of code:
>
> #!/usr/local/bin/perl
>
> # AppSys: Manage Profile
>
> use strict;
> use CGI qw/:standard/;
> use CGI::Carp qw(fatalsToBrowser);
> use Switch;
>
> my $cgi = CGI->new;
>
> my $control = 'Search';
> switch ( $control ) {
> case ("Search") {
> print $cgi->header;
> print $cgi->start_html;
> print $cgi->p("Search");
> print $cgi->end_html;
> }
> }
>
> produces the following in the Apache error log:
>
> [error] syntax error at /home/appsys/www/modperl/ap03.pl line 12, near ") {"
> syntax error at /home/appsys/www/modperl/ap03.pl line 14, near "}
> }"
>
> When run as an Apache::Registry script.
Switch uses source filters, which probably doesn't work well with the way
Registry wraps scripts up into handler() subs.
without getting too far into Filter::Util::Call, Switch.pm, or
Text::Balanced there is probably not much we can do to help.
you might be able to reduce the problem with a test case outside of mod_perl
and pass it on to the appropriate people if it doesn't work. Registry
essentially does this
package Apache::ROOT::modperl::ap03_2epl;
sub handler {
# your script
}
1;
then calls Apache::ROOT::modperl::ap03_2epl::handler().
HTH
--Geoff
Re: Switch (module) and mod_perl problem.
Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-10-30 at 11:41, Mark Hawkes wrote:
> At 11:23 2003-10-30 -0500, you wrote:
> >In my never ending search for more elegant looking and self-documenting
> >code I decided to try out the Switch module.
>
> I've sometimes faked a switch statement like this...
That's a good approach, and there are more examples in perlfaq7:
http://perldoc.com/perl5.8.0/pod/perlfaq7.html#How-do-I-create-a-switch-or-case-statement-
- Perrin
Re: Switch (module) and mod_perl problem.
Posted by Mark Hawkes <ha...@onetel.net.uk>.
At 11:23 2003-10-30 -0500, you wrote:
>In my never ending search for more elegant looking and self-documenting
>code I decided to try out the Switch module.
I've sometimes faked a switch statement like this...
SWITCH: {
$foo eq 'r' && do {
# read stuff
last SWITCH;
};
$foo eq 'w' && do {
# write stuff
last SWITCH;
};
DEFAULT: {
# default stuff
}
}
Hopefully more portable than the Switch module? I admit it's less elegant
though :-/
Mark