Discussion:
[cgi-prototype-users] Tried to use My/App, unable to make it work
Kai Andresen
2005-10-12 06:41:38 UTC
Permalink
Hello,

I copied the My/App test application from the CGI-Prototype
distribution, and added a app.cgi like:
use strict;
use warnings;
use lib qw( /real/path/here );

use My::App;
My::App->activate;

----
Now, directing the browser to the application brings up the welcome
page, and the source of the page seems ok, form, action, fields and
submit-button and all.

But filling out the form and submitting it, only yields the same page.
The only way to get to the thanks-page is to add the parameters into
the url, like http:://localhost/app.cgi?first=john&last=doe -> then
I get the nice thank-you-page.

I use this under a recent Cygwin installation, Perl 5.8.7, and lighthttpd

I obviously miss something fundamental here, but I can't figure it
out, can anyone point me in the right direction?

Kai
Kai Andresen
2005-10-12 16:40:10 UTC
Permalink
Hi Terrence, first let me thank you for your time
http://www.metaperl.org/Guestbook
I have already looked at it earlier, and it's nice - I really did not
think I had any problems understanding the logic or the relationship
between the files.
Post by Kai Andresen
But filling out the form and submitting it, only yields the same page.
What did the FORM action attribute action have?
it has action="http://localhost/test/app.cgi" as appropriate, and method="post"

Also I forgot to mention that the page source validates (i.e. the form
is closed).
Yes, I think what you are missing is the concept of dispatch. If you look
at the activate method in package CGI::Prototype (the easiest way to learn
CGIP is to look at the source code), it calls dispatch early on in the
sub dispatch {
my $self = shift;
return $self; # do nothing, stay here
}
No, -well dispatch might be a better place than render_enter for what
I know, but the dispatch actually does happen. The problem seems to
be that when posted, the params are not seen serverside?

app.cgi only uses My/App.pm which extends CGIPH, which defaults to
call welcome.pm

welcome.pm does dispatch using render_enter where control is
transferred to thanks.pm only if both params first and last is
available, but that only happens when I set those params in the url.
I still don't get why...??


Kai
Terrence Brannon
2005-10-12 12:29:47 UTC
Permalink
Post by Kai Andresen
Hello,
Hi Kai!
Post by Kai Andresen
I copied the My/App test application from the CGI-Prototype
distribution,
There's a fully functioning CGI::Prototype app here:

http://www.metaperl.org/Guestbook

You can download the tarfile and look through it. I can explain
it to you step-by-step if you have questions.
Post by Kai Andresen
and added a app.cgi like: use strict; use warnings; use lib qw(
/real/path/here );
use My::App;
My::App->activate;
----
Now, directing the browser to the application brings up the welcome
page, and the source of the page seems ok, form, action, fields and
submit-button and all.
Cool...
Post by Kai Andresen
But filling out the form and submitting it, only yields the same page.
What did the FORM action attribute action have?
Post by Kai Andresen
Post by Kai Andresen
The only way to get to the thanks-page is to add the parameters into
the url, like http:://localhost/app.cgi?first=john&last=doe -> then
I get the nice thank-you-page.
Cool...
Post by Kai Andresen
I use this under a recent Cygwin installation, Perl 5.8.7, and lighthttpd
I obviously miss something fundamental here, but I can't figure it
out, can anyone point me in the right direction?
Yes, I think what you are missing is the concept of dispatch. If you look
at the activate method in package CGI::Prototype (the easiest way to learn
CGIP is to look at the source code), it calls dispatch early on in the
activate method. The default dispatch method looks like this:

sub dispatch {
my $self = shift;
return $self; # do nothing, stay here
}

And so the same page object returning itself is no surprise. In fact,
unless you subclass the default dispatch method and specializing it
to do certain things with a certain query string parameter (such as
rm for runmode), you should never get a different page.

If you dont want to handle dispatch yourself, you can use Aristotle's
CGI::Prototype::PathInfo, which you can get here:

http://prdownloads.sourceforge.net/cgi-prototype/PathInfo.pm?download

The dispatch logic is documented in the code.

I've also uploaded it to our Sourceforge CVS project but there is a
5-hour delay between anonymous and developer access to cvs updates.
Randal L. Schwartz
2005-10-13 11:58:39 UTC
Permalink
Kai> I copied the My/App test application from the CGI-Prototype
Kai> distribution, and added a app.cgi like:
Kai> use strict;
Kai> use warnings;
Kai> use lib qw( /real/path/here );

Kai> use My::App;
Kai> My::App->activate;

There's no dispatcher in the TestApp. Inheriting the "return $self"
from the base class means that you'll stay forever in the "My::App"
state, meaning you'll get the "intentionally left blank" message
forever.

For a better "tiny" app, see my Linux Magazine articles (google
site:stonehenge.com CGI::Prototype for the location).
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Terrence Brannon
2005-10-13 12:24:48 UTC
Permalink
Post by Randal L. Schwartz
For a better "tiny" app, see my Linux Magazine articles (google
site:stonehenge.com CGI::Prototype for the location).
That location is:

http://www.stonehenge.com/merlyn/LinuxMag/col70.html
and also 7[12].html
A. Pagaltzis
2005-10-13 17:29:25 UTC
Permalink
Post by Randal L. Schwartz
For a better "tiny" app, see my Linux Magazine articles (google
site:stonehenge.com CGI::Prototype for the location).
Randal: just point people at http://cgi-prototype.sf.net/ – there
are links to those articles in the Resources section.

Terrence: would you please `chmod -R g+w *` the web site? You
have created a directory and a bunch of files that I can’t do
anything with because they only have owner write permission.

Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
Continue reading on narkive:
Loading...