cgi application dispatch - HomeworkEssaywritercsClub

cgi application dispatch


Beefy Boxes and Bandwidth Generously Provided by pair Networks


good chemistry is complicated,
and a little bit messy -LW
PerlMonks   

using CGI::Application::Dispatch in my existing application

by punkish (Priest)

  • Log in
  • Create a new user
  • The Monastery Gates
  • Super Search
  • Seekers of Perl Wisdom
  • Meditations
  • PerlMonks Discussion
  • Obfuscation
  • Reviews
  • Cool Uses For Perl
  • Perl News
  • Q&A
  • Tutorials
  • Poetry
  • Recent Threads
  • Newest Nodes
  • Donate
  • What’s New

on Oct 29, 2008 at 16:21 UTC
( # 720257 = perlquestion : print w/replies , xml )

Need Help??


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

I started looking for alternatives for cleaning up my web application URLs, and found CGI::Application::Dispatch . Except, I can’t, for the life of me, figure out how to graft in C::A::D into my existing application.

Update: Added words in emphasis to the above para. Without them the sentence didn’t make any sense.

Here is the background —

I have a reasonably mainstream application made with CGI::Application and a sprinkling of Plugins (DBH, Session, LogDispatch, AutoRunmode).

I follow the usual pattern —

package Myapp; use base 'CGI::Application'; use CGI::Application::Plugin::* sub view : StartRunmode {} sub edit : Runmode {} sub update : Runmode {} sub create : Runmode {} sub save : Runmode {} sub find : Runmode {} .. bunch of supporting subs .. sub setup {} sub cgiapp_get_query .. require CGI::Simple; sub cgiapp_init
[download]

Everything works, and now I want to clean up my URLs. Nothing fancy, just the usual stuff like so —

<server> --> <server>/index.cgi <server>/ --> <server>/index.cgi <server>/Item --> <server>/index.cgi?rm=view&id=Item <server>/(view|edit|create)/Item --> <server>/index.cgi?rm=$1&id=Item <server>/find/?q=search_term --> <server>/index.cgi?rm=find&q=search_t+erm
[download]

calls to “update” and “save” will be via POST, so they should be let in freely, and the same applies to all static content such as css, js, media, etc.

So, I started with mod_rewrite voodoo, but after 4 days of tackling it unsuccessfully, I have given up on it.

Even if I get everything working well with mod_rewrite, I am actually loathe to implement it, because in the long run, I want to do minimum amount of messing with Apache configs, something I may not have complete control over in different conditions. Keep in mind, I don’t mind implement a couple of mod_rewrite rules, but doing it in my application will give me more control for future development and modification.

So, I started looking for alternatives, and found CGI::Application::Dispatch . Except, I can’t, for the life of me, figure out how to graft in C::A::D into my existing application.

If I am being dense, just whack me on your head with your esc key. In any case, do guide me through this valley of confusion.

Once I figure it all out, I will write up a nice easy tutorial that even PHP folks will be able to understand. Promise.

Update: and, yes, I have looked at all the CGI::App::Dispatch articles that I could find. While they do explain stuff, they don’t explain it in context of implementing CAD within and existing CGI::App application. At least, not in the way I could understand.

Update2: and, I need to do with vanilla cgi first, before I attempt all the CAD magic with mod_perl


when small people start casting long shadows, it is time to go to bed

  • Comment on using CGI::Application::Dispatch in my existing application
  • Select or Download Code

Replies are listed ‘Best First’.

Re: using CGI::Application::Dispatch in my existing application

by Anonymous Monk on Oct 29, 2008 at 17:28 UTC

    http://search.cpan.org/src/MARKSTOS/CGI-Application-Dispatch-2.13/t/ contains examples, anyway, try

    # index.cgi use CGI::Application::Dispatch; CGI::Application::Dispatch->dispatch( table => [ '' => app => 'Myapp', '/' => app => 'Myapp', 'Item' => app => 'Myapp', id =>'Item', rm => 'view', 'find' => app => 'Myapp', id =>'Item', rm => 'find', 'view/Item' => app => 'Myapp', id =>'Item', rm => 'view', 'edit/Item' => app => 'Myapp', id =>'Item', rm => 'edit', , 'create/Item' => app => 'Myapp', id =>'Item', rm => 'create', , ], ); #
    [download]
    Re^2: using CGI::Application::Dispatch in my existing application

    by punkish (Priest) on Oct 29, 2008 at 18:11 UTC
      I did say I am being dense here, and that denseness continues. I saw the code you refer to. What am I to do with that code? Does it go in my package or in my index.cgi? It seems it should go in index.cgi, but putting it there (with the necessary modifications, of course) and then going to http://<server>/myapp/index.cgi/view, ends up with the error

      No such run mode 'view' at .../index.cgi
      [download]

      Additionally, I can’t really have id => 'Item' hard coded in my script. The string ‘Item’ is shown just for example. It changes all the time.

      Sorry, I am not getting it.


      when small people start casting long shadows, it is time to go to bed

      Re^3: using CGI::Application::Dispatch in my existing application

      by punkish (Priest) on Oct 29, 2008 at 19:19 UTC
        Jeebus, I finally understand it!

        CAD docs need some serious rewrite (and I shall do so, soon as I figure *everything* out about it) especially for someone like me who already has a working CGI::App application and then wants to add CAD to it (and happens to be a bit dense like me).

        Great app, but docs need to be improved.


        when small people start casting long shadows, it is time to go to bed

        Re^4: using CGI::Application::Dispatch in my existing application

        by Anonymous Monk on Mar 29, 2009 at 11:14 UTC

Back to
Seekers of Perl Wisdom

Log In ?
Node Status ?

node history
Node Type: perlquestion [id://720257]
Approved by osunderdog
help

Chatterbox ?


How do I use this? | Other CB clients

Other Users ?

Others scrutinizing the Monastery: (2)

  • marto
  • Tux

As of 2018-08-17 17:14 GMT

Sections ?
  • Seekers of Perl Wisdom
  • Cool Uses for Perl
  • Meditations
  • PerlMonks Discussion
  • Categorized Q&A
  • Tutorials
  • Obfuscated Code
  • Perl Poetry
  • Perl News
  • about
Information ?
  • PerlMonks FAQ
  • Guide to the Monastery
  • What’s New at PerlMonks
  • Voting/Experience System
  • Tutorials
  • Reviews
  • Library
  • Perl FAQs
  • Other Info Sources
Find Nodes ?
  • Nodes You Wrote
  • Super Search
  • List Nodes By Users
  • Newest Nodes
  • Recently Active Threads
  • Selected Best Nodes
  • Best Nodes
  • Worst Nodes
  • Saints in our Book
Leftovers ?
    • The St. Larry Wall Shrine
    • Buy PerlMonks Gear
    • Offering Plate
    • Awards
    • Random Node
    • Quests
    • Craft
    • Snippets
    • Code Catacombs
    • Editor Requests
    • blogs.perl.org
    • Perlsphere
    • Perl Ironman Blog
    • Perl Weekly
    • Perl.com
    • Perl Jobs
    • Perl Mongers
    • Perl Directory
    • Perl documentation
    • MetaCPAN
    • CPAN
    Voting Booth ?
    Asked to put a square peg in a round hole, I would:

    Results (182 votes) . Check out past polls .

    Notices ?

      PerlMonks lovingly hand-crafted by Tim Vroom .
      PerlMonks somehow became entangled with
      The Perl Foundation .
      Marvelous Managed Hosting and Bandwidth Generously Provided by

      pair Networks

      Built with the Perl programming language .