markstos / CGI--Application

A Perl framework for building reusable web-applications
http://www.cgi-app.org/
22 stars 13 forks source link

psgi_app() doesn't update QUERY #1

Closed anazawa closed 11 years ago

anazawa commented 11 years ago

psgi_app() returns a PSGI code reference which never updates QUERY, while $env is updated, and so we can't reload the PSGI app.

sub psgi_app {
    my $class = shift;
    my $args_to_new = shift;

    return sub {
        my $env = shift;

        if (not defined $args_to_new->{QUERY}) {
            require CGI::PSGI;
            $args_to_new->{QUERY} = CGI::PSGI->new($env);
        }

        my $webapp = $class->new($args_to_new);
        return $webapp->run_as_psgi;
    }
}

The aboce "if" statement will be executed only once if $args_to_new->{QUERY} is undefined. I believe psgi_app() is a shorcut for:

use CGI::PSGI;
use MyApp;

my $app = sub {
    my $env = shift;

    my $cgiapp = MyApp->new(
        QUERY => CGI::PSGI->new($env), # always updates QUERY
        ...
    );

    $cgiapp->run_as_psgi;
};

By the way, this repository doesn't contain Makefile.PL. How can I run "make test"?

anazawa commented 11 years ago

I found the solution to run "make test" by myself:

$ perl Build.PL $ ./Build $ ./Build test

anazawa commented 11 years ago

In addition, we can't specify the query object explicitly:

use CGI::PSGI;
use MyApp;

my $app = MyApp->psgi_app({
    # How can I specify QUERY without $env?
    ...
});
markstos commented 11 years ago

Thanks for the feedback, Ryo. A proposed patch with tests would be welcome.

anazawa commented 11 years ago

Thanks for your reply. I sent the pull request.