[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] RFC: Sub applications, CGI and mod_perl issues


Hi there,

NOTE1: Everybody knows that when you narrow a problem to a simpler form
it's easier to solve it, and man, it's true!!! ;)

I got a solution to my problem (at least for the mean time, as I don't
like it very much), and like to share it with you to comment on. Also
because I have lost half a day with this and I think it may save the
same amount of time to someone reading the list.

The solution I found make me think this is more of a mod_perl issue,
but I would like that you to take a look and comment on the submodule
division method, to see if I got it right and what may be the drawbacks
of such a method.

I created a mod_perl instance script which uses all the modules of the
application (ie. use MyModule1; use MyModule2; etc.); and leave the CGI
instance script with only the basic modules and the require's in place
on the various submodules. So the CGI version compiles only the modules
it will use, and the mod_perl version compiles all the modules on load,
as it will not be recompiled again.

NOTE2: Also writting a message to the list helps get your thoughts in
order, because at this point, I think the solution is the right one in
this situation. So maybe this will be more of a RFC (and proof-reading
as English is not may native language), to give your opinions and for
help to post this on the wiki (as I have little time at the moment,
maybe latter I will do it, depending on the feedback from the list). ;)

So here it is, the original meta-post:

I have an application that is running ok as a CGI, but present a problem
when I try to run it under mod_perl2 (also on mod_perl1), so I may be
doing something wrong, as CGI::Application's are supoused to run ok under
Apache::Registry.

I was thinking that it may had something to do with the Debian package
of mod_perl2, as I readed some days ago in www.debian-administration.org
that the mod_perl2 package released with Debian 3.1 (sarge) was odd and
somewhat incompatible with the real mod_perl2 package (it is a 1.999
beta with some Debian specific patches). But then I tested the script in
the intranet server (which has Debian 3.0 (woody), and the application
presents the same problem there).

The configurations where I tested this are:

My Workstation: Apache 2.0.54, mod_perl 1.999.21, CGI::Application 3.31
(all default stable Debian packages). Fails even as a CGI, it gives an
use of uninitialized value in C::A 1446/1449 (sub mode_param trying to
work on a null pathinfo). Obviously an old version, as with
CGI::Application 4.03 locally installed it worked ok.

Server: Apache 1.3.26, mod_perl 1.26 (this two installed from Debian
default packages); and locally installed CGI::Application 4.03.

I think my problem is in the way I am using sub applications to divide
the various modules on the system (as it is very large), and I may have
missunderstood how to do it. (I sill think it's not optimal ;), so
comments are welcome).

On other notes, I leave the -T and related stuff there as the real app
does need them, I have not tested taking that off, because I can't take
them off the real app. The application has rights to read/execute in
/home/rruiz/perl/[ee|lib]

Also note that the use of path_info is optional and I leaved it there
because the main app do use it that way.

Hope someone can help me ;)

Sincerely,
Roberto Ruiz

Below are the minimal testing applications which presents the problem,
apache config directives and error log.

-------------------- double-mod instance script: 
(cut)
#!/usr/bin/perl -wT

# Needed for Taint checking.
BEGIN {
    $ENV{'PATH'} = '/bin:/usr/bin';
    delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
}

# ee/ has app modules, lib/ has cpan local installed modules
use lib qw( /home/rruiz/perl/ee /home/rruiz/perl/lib );
use strict;
use DoubleApp;
#use DoubleSubApp; # remove comment to work under mod_perl, also
                   # add more needed modules.

my $webapp = DoubleApp->new();
$webapp->run();
(cut)

-------------------- DoubleApp.pm main app module:
(cut)
package DoubleApp;

use base 'CGI::Application';

sub setup {
    my $self = shift;
    $self->start_mode('mode1');
    $self->mode_param( path_info => 1, param => 'module' );
    $self->run_modes( ['mode1', 'mode2', 'mode3'] );
}

sub mode1 {
    my $self = shift;
    my $html = '<html><head><title>Testing</title></head><body>';
    my $url = $self->query()->url();
    $html .= '<p>Goto <a href="' . $url . '/mode2">mode2</a></p>';
    $html .= '<p>Goto <a href="' . $url . '/mode3">mode3</a></p>';
    $html .= '</body></html>';
    return $html;
}

sub mode2 {
    my $self = shift;

    require DoubleSubApp;
    my $subapp = DoubleSubApp->new(query => $self->query());
    $ENV{CGI_APP_RETURN_ONLY} = 1;
    my $html = $subapp->run();
    $ENV{CGI_APP_RETURN_ONLY} = 0;
    return $html;
}

sub mode3 {
    my $self = shift;
    my $html = '<html><head><title>Mode3</title></head><body>';
    my $url = $self->query()->url();
    $html .= '<p>Goto <a href="' . $url . '/mode2">mode2</a></p>';
    $html .= '<p>Goto <a href="' . $url . '/mode1">mode1</a></p>';
    $html .= '</body></html>';
    return $html;
}

1;
(cut)

-------------------- DoubleSubApp.pm sub app module:
(cut)
package DoubleSubApp;

use base 'CGI::Application';

sub setup {
    my $self = shift;
    $self->start_mode('mode1');
    $self->mode_param( path_info => 2, param => 'action' );
    $self->run_modes( ['mode1'] );
    # no headers, output catched on calling app
    $self->header_type('none');
}

sub mode1 {
    my $self = shift;
    my $html = '<html><head><title>Test Succeed</title></head><body>';
    my $url = $self->query()->url();
    $html .= '<p>Goto <a href="' . $url . '/mode1">mode1</a></p>';
    $html .= '<p>Goto <a href="' . $url . '/mode3">mode3</a></p>';
    $html .= '<p>Sub app run-mode visible!!!</p>';
    $html .= '</body></html>';
    return $html;
}

1;
(cut)

-------------------- Apache 1 config directives:
<IfModule mod_perl.c>
    PerlTaintCheck On
    Alias /pcgi-bin/ /xtra/webs/server/pcgi-bin/
    <Location /pcgi-bin>
        SetHandler perl-script
        PerlHandler Apache::Registry
        Options +ExecCGI
    </Location>
</IfModule>

-------------------- Apache 2 config directives:
<IfModule mod_perl.c>
    PerlTaintCheck On
    Alias /pcgi-bin/ /home/rruiz/pcgi-bin/
    <Location /pcgi-bin>
        SetHandler perl-script
        PerlResponseHandler ModPerl::Registry
        #PerlOptions +ParseHeaders
        #PerlOptions -GlobalRequest
        Options +ExecCGI
    </Location>
</IfModule>


-------------------- Apache 1 error log:
[Mon Aug 22 16:29:35 2005] [error] Error executing run mode 'mode2':
Can't locate DoubleSubApp.pm in @INC (@INC contains:
/usr/local/lib/perl/5.6.1 /usr/local/share/perl/5.6.1 /usr/lib/perl5
/usr/share/perl5 /usr/lib/perl/5.6.1 /usr/share/perl/5.6.1
/usr/local/lib/site_perl /etc/apache/ /etc/apache/lib/perl) at
/home/rruiz/perl/ee/DoubleApp.pm line 25.
 at /xtra/webs/server/pcgi-bin/double-mod line 15


-------------------- Apache 2 error log:
[Mon Aug 22 17:28:28 2005] [error] Error executing run mode 'mode2': Can't locate DoubleSubApp.pm in @INC (@INC contains: /usr/lib/perl5/Apache2 /etc/perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl /etc/apache2) at /home/rruiz/perl/ee/DoubleApp.pm line 25.\n at /home/rruiz/pcgi-bin/double-mod
line 16\n



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
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.