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

CGI::Application for complex web applications?

by techcode (Hermit)
on Jul 28, 2005 at 00:34 UTC ( [id://478775]=perlquestion: print w/replies, xml ) Need Help??

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

As I all ready have experience with CGI::Application and HTML::Template and I wanted to use those for creating web applications. Both are simple and can simply be copied into the application folder and things work - no hassle (that's another reason for using it).

Problem I'm now facing is that instead of putting several run modes in one file, I need several files also.

Maybe this would be clear with an example. Say it's an mailing list application. Naturally I want to place all the subscribers administration code in one place, newsletter admin in other place ... where place = module.

Some time ago (like a year passed) I started working on that mailing list application with CGI::App as framework but due to inexperience and lack of time I made it somewhat complicated - well not nice at least. I stopped working on it (~ 85% of it finished) because it was canceled (freelance project) and now I'm thinking to use it as my university project and/or dissertation from e-business ;)

Did anybody used CGI::App for things like that? Maybe some other framework - but for latter as I dint have time to learn new things now.

After thinking for some time I believe I came up with an elegant solution but would like any comments on it.

Basically there in only one index.pl file. That is the entry point to application (or website).
It will be a sort of dispatcher since you could call it with .../index.pl/subscribers/ and itself would require subscribers; (or maybe even several levels deep : index.pl/admin/subscribers for instance) and then folow the rest of plain CGI::App index file (create an object and call run method).

All those modules of application would be child's of some main application module. That main module would have code for authorization/authentication, sessions, reading in config files, connecting to DB ....
And it would be a child of CGI::App (use base 'CGI::Application') or probably that extension for automatic settings of run modes.

Is logic OK here?

I also wonder about few things:

  • will URLs like www.site.com/index.pl/admin/members/ call that index.pl in root where I will be able to extract the rest of path
  • if previous is yes, will post/get work (www.site.com/index.pl/admin/members/?run_mode=something)
  • How would all this URLs work with mod_perl - as if it works out with this project I might use same/similar for web sites based on CGI:App.
Thanks folks.
  • Comment on CGI::Application for complex web applications?

Replies are listed 'Best First'.
Re: CGI::Application for complex web applications?
by esskar (Deacon) on Jul 28, 2005 at 00:45 UTC
    Well, i was in a similar situation. I implemented a POP3/SMTP based WebMailer without using any framework (like CGI::Application(::Plus)). Everything was working but unclean. A year later i thought about including IMAP and NNTP as well. But i knew that my kernel was to unstructered, so i looked throught cpan and found CGI::Application(::Plus). I tried it and started reimplementing my webmailer. But i didn't like the fact, that i had to do the dispatching stuff (as you mentioned). Now I use Catalyst (The Elegant MVC Web Application Framework :) ) which is really powerful and easy to use (thanks sri). Have a look at it.
    Now I'm happy.

      CGI::Application::Plus should not be used. The author has depricated the module, and changed the name to CGI::Builder, so if you really want to, use that instead. However, make sure you read up on the author before using those packages...

        Yes I'm aware that CGI::App::Plus is deprecated but CGI::Application itself isn't.

        I was thinking of CGI::Application::Plugin::AutoRunmode so that I wouldn't need to write setup and add run modes by hand ...

Re: CGI::Application for complex web applications?
by cees (Curate) on Jul 28, 2005 at 01:40 UTC

    Have a look at CGI::Application::Dispatch. It works pretty much exactly like you describe. It can be used as a mod_perl handler if you use mod_perl, or it can be used in a simple CGI script if you don't use mod_perl.

    As for the three questions at the bottom:

    • will URLs like www.site.com/index.pl/admin/members/ call that index.pl in root where I will be able to extract the rest of path

      Yes

    • if previous is yes, will post/get work (www.site.com/index.pl/admin/members/?run_mode=something)

      Yes

    • How would all this URLs work with mod_perl - as if it works out with this project I might use same/similar for web sites based on CGI:App.

      It will work exactly the same under mod_perl, although you can hook the handler in a location that doesn't have a file extension, so you could have www.site.com/myapp/admin/members?param=1. That makes for nicer looking URLs

      Thanks for pointing it out to me :)

      I don't know if there is something I'm missing about/on CPAN? Can I simply browse to see all the CGI::Application modules (the folder CGI/Application/ and it's sub-folders)?

      I still have to check if it will work with AutoRunmode plug in as it's not mentioned in the docs. But I did spotted authors words that module is written because he's lazy and didn't wanted to write same code over and over - so there are good chances it will work :)

      Almost forgot - if I want to use several CGI::Application::Plugin(s) - say this AutoRunmode and Sessions - how do I do that?

      Thanks.

        I use CGI::Application::Plugin::AutoRunmode with CGI::Application::Dispatch all the time. They work really well together.

        for most of the plugins, you just have to use them in your module

        package My::App; use base qw(CGI::Application); use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Session;

        As for finding all the plugins, since many of the plugins are written by different authors, you can't easily see a list of all of them on one page. Your best bet is just to use search.cpan.org and search for CGI::Application. You will have to page through cause there are quite a few of them. Another way to find them all quickly is to look in the 02packages.details.txt.gz file in your local CPAN directory:

        zcat $HOME/.cpan/modules/02packages.details.txt.gz | grep 'CGI::Applic +ation'

        That will quickly give you a list, although you won't get you much information.

        I don't know if there is something I'm missing about/on CPAN? Can I simply browse to see all the CGI::Application modules (the folder CGI/Application/ and it's sub-folders)?
        You can browse the directory structure for CGI::Application *, but that only shows the modules that are in the default C::A install. There are several extensions on CPAN that you need to install seperately.

        Just use search.cpan.org to search for related modules that are not in the default distribution.

        * update: you can also walk the "modules by name" list on cpan, but IMO search.cpan.org is a lot easier to use.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-25 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found