Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Something like Tomcat for Perl

by Improv (Pilgrim)
on May 18, 2003 at 03:12 UTC ( #258945=perlquestion: print w/replies, xml ) Need Help??
Improv has asked for the wisdom of the Perl Monks concerning the following question:

I've recently been using tomcat4, learning Java, and using it for Servlets and JSPs. Although I've written several CGIs in Perl, it seems to me that tomcat offers some stuff that's hard to do via CGI. The two that I'm most interested in are session objects and directory mapping -- the first allows for objects on the server to easily be stored and modified, with an association with an existing session without the user seeing or being able to mess with any of that stuff. The second allows a servlet, say ResourceManager.class, to be bound to all requests starting with the path "Resources/", and the servlet can use HttpServletRequest::getPathInfo() to get the path it was passed and respond accordingly. I would like to do the second without a redirect or any other such ugliness.

So, in sum, is there a way to do this kind of thing with Tomcat, or is there something similar to Tomcat that does for Perl what it does for Java?

Replies are listed 'Best First'.
Re: Something like Tomcat for Perl
by The Mad Hatter (Priest) on May 18, 2003 at 03:18 UTC
    If I understand correctly, you can definately do the first one using CGI::Session. I think you can do the second if you use Apache (and possibly IIS).

    If you call the CGI script Resources.cgi, you should be able to configure Apache (it may be enabled by default even) to execute it when called as "Resources/stuff/goes/here". Once that is working, check out the path_info method of CGI; it should let you fetch the last bit of the URL the script was called with (ex/ "stuff/goes/here").

    I know both of these work, as I use them myself.

    Update You might also be interested in the Jellybean Object Web Server. I don't personally use it, but it is written by our very own chromatic.

    NB I know that I responded to this and then front-paged it, but I think it is a good question. I'm honestly not trying to gain XP, and you can feel free to downvote this if you really think it was in bad form to front-page and reply.

      mod_perl handlers allow you associate arbitrary locations with your code. Consider this snippet. It uses a redirect so requests for the root go to the script's URL and from there I've associated /opencivics with the OpenCivics::WebApp::handler() method.

      Redirect /index.html <Location /opencivics> PerlSetEnv ALZABO_DEBUG ALL SetHandler perl-script PerlModule Apache::Request PerlModule OpenCivics PerlHandler OpenCivics::WebApp </Location>

      According to their web site, the last version of the Jellybean Object Web server (0.13) was released on 26 June 2001.

      Would you know if this software is maintained or abandoned?

      Everything went worng, just as foreseen.

        I got distracted writing one book and then another. I have code in evserver that needs to be merged and plan to do that in the near future.

        "Near", of course, is open to interpretation, users, and patches.

        Hmmm, good question. :-) I guess I missed that. You could probably find out by /msg-ing chromatic...
•Re: Something like Tomcat for Perl
by merlyn (Sage) on May 18, 2003 at 12:24 UTC
Re: Something like Tomcat for Perl
by Zaxo (Archbishop) on May 18, 2003 at 05:15 UTC

    The path tricks you want are handled by Apache's mod_rewrite.

    After Compline,

      The path tricks you want are handled by Apache's mod_rewrite.

      And handled well they are. I've really fallen in love with mod_rewrite, it is just so useful. I set up a demo server for our customers, where depending on the login name used, a completely different server will be presented to them. On the server-side, it's just subdirectories (makes it easy for us to manage them), but the clients are never aware that there's anything else on the server apart from what they're seeing. I also use it to redirect multi-language pages and setting environment variables according to the language selected.

        Beware though. If you use internal redirects (like with mod_rewrite), you must also use a custom 404 handler that does not accidentally reveal your internal structure. The default 404 handler leaks the layout.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Re: Something like Tomcat for Perl
by TVSET (Chaplain) on May 18, 2003 at 15:09 UTC
    I might be interested in Mason. You can create the following structure:

    /my/super/dir/somefile.mhtml /my/super/dir/autohandler /my/super/autohandler /my/autohandler /autohandler

    If someone, say requests /my/super/dir/somefile.blah you can take care of it in /my/super/dir/autohandler. You can even forward the request to the handlers in other directories.

    As to sessions - it does them too :)

    Leonid Mamtchenkov aka TVSET


      I actually use HTML::Mason to do exactly what you are talking about. I use this call...

      #Get the current component's session information my $current = $m->current_comp(); #Get the current directory relative the the web server's #root directory. my $directory = $current->dir_path;
      I then use that information for other purposes. HTML::Mason looks and feels extremely similar to both JSP and ASP. Give it a try Mason's HomePage.

      Kristofer Hoch

      Si vos can lego is, vos es super erudio

Re: Something like Tomcat for Perl
by belg4mit (Prior) on May 18, 2003 at 12:56 UTC
Re: Something like Tomcat for Perl
by crenz (Priest) on May 18, 2003 at 12:17 UTC
Re: Something like Tomcat for Perl
by Starky (Chaplain) on May 19, 2003 at 03:54 UTC
    You may be interested in Apache::PageKit. It is a mod_perl based system with session management features (you can store and retrieve objects with something like FreezeThaw) via Apache::SessionX and directories mapping to classes.

    I've used it before, and it works bee-yoo-tee-fully. Fast and reliable with many nice features. The only caveat I would offer is that the documentation was sparse last time I checked.

Re: Something like Tomcat for Perl
by mvc (Scribe) on May 19, 2003 at 19:30 UTC

    You will that Perl/Apache handle the directory aliasing feature very nicely, and even sessions work OK. For simple things.

    Sometimes you need to store objects (blessed references) in the session or application scope. This is easy in Java. In Perl you must deal with serialization issues. Even 5.8 with mod_perl2 offers little help here.

    Luckily this is rarely needed.

      If you create a resource pool that your objects can fetch resources from then serialization of those objects becomes less of a problem.

      See ResourcePool on the CPAN.
Re: Something like Tomcat for Perl
by tent8f (Initiate) on Oct 17, 2006 at 09:32 UTC
    I've been looking into this myself. Why are there no multi-thread Perl-centric application servers (ala Java's Tomcat) ?
    mod_perl is not a realistic option for me because some of our customers use IIS / ISA proxy server.
    What would be ideal is a standalone multi-thread webserver written in Perl that could be reverse-proxied using Apache or IIS/Proxy Server. I want to avoid the startup overhead of CGI, and the non-portability of mod_perl. Having a standalone HTTP app server that's proxied seems to be the way to build scalable web apps.
    At least according to these guys...
    The web is a pipe
    Is building a light-weight multi-threaded web-server in perl really that hard ?
      Why are there no multi-thread Perl-centric application servers?
      Maybe because there was no need to do that?

      I'm not aware of any out-of-the-box drop-in replacement for tomcat, but I guess the POE framework provides the bits for that, not using threads but cooperative multitasking. On the POE projects page there is Philip Gwyn's Just Another Application Server. Have a look. There's PAS also - a Perl Application Server.

      On CPAN you find Net::Server, a generic Perl server engine, HTTP::Server::Simple, a simple standalone Perl HTTP server, templating engines, parsers and so on... it's all there, so it shouldn't be hard to do it. But somebody has to put the bits together.

      Happy assembling ;-)


      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://258945]
Front-paged by The Mad Hatter
and the sunlight beams...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-04-25 07:14 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (449 votes). Check out past polls.