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

G'day Monks,

I will shortly be writing some code using CGI and Mouse. (The basic environment is Linux/Apache with Perl at v14.0.)

I'm not looking for any help with these specific components; however, I would be interested to know if anyone has encountered any issues/gotchas/etc. with the CGI+Mouse combination.

For anyone possibly suggesting other combinations, the CGI component is fixed (that's out of my control). I chose Mouse over Moose (as I don't need the antlers). Other Mo* modules can be considered. The fallback plan is to hand-craft classes as I did in days of yore: I'd prefer not to have to do that much work, though.

Many thanks in advance.

-- Ken

  • Comment on Any gotchas with CGI and Mouse running together?

Replies are listed 'Best First'.
Re: Any gotchas with CGI and Mouse running together? ( Moo not Mouse )
by Anonymous Monk on Feb 25, 2015 at 03:57 UTC

      ++ Thanks for these links: that's newer information than I currently had to hand.

      -- Ken

Re: Any gotchas with CGI and Mouse running together?
by Your Mother (Archbishop) on Feb 27, 2015 at 01:39 UTC

    No real gotchas. I prefer Moo to Mouse/Moose. I think the defaults are better and things like inline “type” checking more Perlish; more self-documenting; easier to remember.

    Mouse is much faster than the other meta-OO options. So, if this were my project the choice between Moo and Mouse would boil down to the execution. If the app is persistently executed, I’d pick Moo, otherwise, Mouse. If it’s persistent then you should be looking at running/harnessing it as PSGI too, whether or not the base code is in CGI.

    …Then again, some casual tests on the command line suggest the start-up speed of Moo is only 0.001s slower than Mouse so maybe Moo anyway depending on how many objects and how much access you’re wrangling. I have also had far fewer cross compat/build/deps problems with Moo than Mouse or Moose, FWIW; in a very static env this shouldn’t matter though.

      ++ Thanks for this excellent answer: good information on both Moo and PSGI.

      -- Ken

      > the start-up speed 

      Maybe a silly question, but if start-up speed is so significant why isn't there a precompiled version of Moose?

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)

      PS: Je suis Charlie!

        I don’t think it’s silly. The Mouse is precompiled essentially being XS (when built with it). I expected it to be faster actually but regular old Perl often surprises me with how fast it is. I tend to forget that most of why stuff at work is slow is awful DB code and not just the awful Perl we have. :P Doing thousands of objects and methods would probably make the Mouse a clear winner. So it would depend on how big/complex the code chains will end up.

        Start up time is only a (serious) issue if running plain CGI as executables; which is a terrible way to do things but still the easiest. Our codebase at work is 50% legacy CGI that was finally taking 3 seconds to return simple pages—code bloat and universal loading of all the libs we have. Making it persistent (pre-compiled by a master server) fixed (most of the outward perception of) that.

Re: Any gotchas with CGI and Mouse running together?
by RonW (Parson) on Feb 27, 2015 at 01:00 UTC
    For anyone possibly suggesting other combinations, the CGI component is fixed (that's out of my control).

    Are you modifying existing code?

    CGI is not the only module (family) that "speaks" CGI to the webserver.

      Thanks for the reply.

      I can't say too much as this is for a commercial project. I'm under contract to work on specific code; the CGI component is not currently within my purview.

      -- Ken

Re: Any gotchas with CGI and Mouse running together?
by kcott (Archbishop) on Mar 03, 2015 at 06:29 UTC

    Many thanks to all for much useful information. ++s have been strewn liberally. I'm going ahead with Moo instead of Mouse.

    -- Ken

Re: Any gotchas with CGI and Mouse running together?
by Arunbear (Prior) on Feb 25, 2015 at 11:23 UTC
    When you created hand-craft classes did you create get/set methods for all of the object attributes? This is one of the cons of Moo(se), you are forced to trade encapsulation for convenience.

      Thanks for the reply. I really was just after any issues that may have been encountered with the CGI+Mouse combination.

      -- Ken

        I've used Mouse and Moo under CGI in the past, and found response times with Mouse noticeably longer. However I wouldn't use Moo for new projects because of the anti-modular code that results from it.

        I hope you wouldn't mind if I rephrase the question you didn't answer. Which of the following statements is correct?

        1. You don't realise how anti-modular Moo is
        2. You know that Moo is anti-modular but don't see that as a problem
Re: Any gotchas with CGI and Mouse running together?
by Anonymous Monk on Feb 25, 2015 at 17:23 UTC
    I would consider Dancer instead.