Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Multiple "Pages"

by Trihedralguy (Pilgrim)
on Feb 26, 2007 at 14:15 UTC ( [id://602125]=perlquestion: print w/replies, xml ) Need Help??

Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I was wondering if anyone had a good example of going about doing "Multiple Pages" within perl. For example if I have three pages but I want them all to run out of a script.cgi how would I go about doing that. I have looked at a few examples but I can't quite grasp the concept. One example I found almost looks like its calling a function.
I dont have the complete example with me, but it was something along the lines of this:

unless ( param()){
page1;
}else
{ page2;
}

Replies are listed 'Best First'.
Re: Multiple "Pages"
by scorpio17 (Canon) on Feb 26, 2007 at 14:35 UTC
    You might also want to read up on the CGI::Application module, available from CPAN. Instead of each page corresponding to a section of an ever-growing (and harder to maintain) if-then-else block, you create a subroutine for each page (called a 'run mode'). All the subroutines go into a module, and your cgi-script reduces to about 3 lines of code: load module, create instance, run application! If your starting a new project from scratch, it's definitely worth checking out. It could save you lots of time and energy down the road.
      Indeed, this is precisely what CGI::Application is made for. As a working example, here's a fairly simple C::A application.

      __________
      Systems development is like banging your head against a wall...
      It's usually very painful, but if you're persistent, you'll get through it.

Re: Multiple "Pages"
by Fletch (Bishop) on Feb 26, 2007 at 14:21 UTC

    The CGI would key off what set of information to display based on either a parameter (retrieved using the CGI param method) or by using extra path information after the name of the CGI itself (retrieved with path_info). It'd then use that key to decide what to return.

    That's pretty much it; not much more complicated than what you've already described.

    Update: Ooh, yeah seconding the CGI::Application recommendation below. It provides a ready-made framework that does just this type of thing for you out of the box.

Re: Multiple "Pages"
by agianni (Hermit) on Feb 26, 2007 at 16:46 UTC
    A simple bare-bones but very flexible option would be CGI::Prototype. While the documentation with the module itself is spare, Randal has written a few articles on it (1, 2, 3) as well as a freely available slideshow.
Re: Multiple "Pages"
by dorward (Curate) on Feb 26, 2007 at 14:57 UTC
      I think the OP is asking about separate web pages handled by a single script, as opposed to "paging" through a result set.
Re: Multiple "Pages"
by Trihedralguy (Pilgrim) on Feb 26, 2007 at 17:41 UTC
    That works, thank you all for your timely responses :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://602125]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found