Slashdot Mirror


Mojolicious 2.0: Modern Perl For the Web

Kvorg writes "After a year of rapid development, newly released version 2.0 of Mojolicious, the new generation real-time Perl web framework written by Sebastian Riedel and many others, offers a versatile and elegant web framework that is as good at web scraping and simple scripts as it is at building complex, interactive real-time applications with HTML5 and websockets. It supports easy 0-dependency installs, excellent developer mode, multiple deployment scenarios, many CPAN modules and plugins."

10 of 132 comments (clear)

  1. Perl is the most refreshing programming language by Anonymous Coward · · Score: 5, Funny

    Every time I look at a script I've written that's at least a year old, it's like the first time I've ever seen the code.

  2. Useful for just certain applications by FyberOptic · · Score: 3, Insightful

    I suppose the idea is neat, but I personally don't have any particular applications where I need Perl to actually be the whole webserver for me. The things that do come to mind would involve a small system where there is no webserver installed, but going on port 80 would mean running the script with higher privileges and the whole mess of Perl and everything need to be jailed. Or maybe to try one of those utilities I heard about to pass privileged ports to an app, but I haven't had experience with those.

    To be honest, frameworks left kind of a bad taste in my mouth when a language such as Ruby that had been around for years suddenly exploded when Ruby on Rails showed up. Everybody and their brother thought it was the new hip thing to use, until a lot of the bigger websites which had deployed it started to actually dump it due to limitations. Nobody wanted to take the time to write good code to start with, and it bit them in the butt.

    Using frameworks (whether it's .NET or on the web or otherwise) usually starts out as a means to set up a new project quickly, but the problem is that they end up being an excuse to make sloppy bloated coat for the final product. Perl was always fast and efficient; people should learn to develop in it that way.

    1. Re:Useful for just certain applications by skazatmebaby · · Score: 3, Interesting

      If I'm reading the docs correctly, the webserver part of Mojolicious is optional:

      http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#DEPLOYMENT

      It also supports a pretty substantial list of alternatives to its build in web server. Want to only run it as a CGI script? Then do that. Run your app as a PSGI script? Yeah, you can do that too. Started as a CGI script by now need a lot more HP? Not so hard to move what you started on something simple to something with a little more Umph.

      So that's I guess, "neat"

      --

      Dada Mail - Program, Art Project or Absurdity?

  3. Re:Yet Another by grcumb · · Score: 3, Insightful

    Because clearly what we need is _yet another_ way to develop web applications.

    Frankly, yes. As long as we're advancing and improving, yeah, it always makes sense to keep trying new approaches. I'm using Mojolicious for two apps currently in development. One of them was already in progress using other modules, bit with the Mojolicious::Lite module, I was able to cut my code base nearly in half.

    I'll tell you what - why don't.you try it first, then complain about it if you still don't like it.

    --
    Crumb's Corollary: Never bring a knife to a bun fight.
  4. Re:"Web development can be fun again" by Anrego · · Score: 3, Insightful

    I don't really get the desire to use Perl. I haven't touched Perl for a long time and can't think of any jobs where it would be the best tool. It's ugly.

    It's still _the_ tool for quick one-off type stuff. I know of no other tool that lets you just mash data together and produce something useful as easily and quickly as perl. That said, I'd never use it for a serious application or anything that had to be maintained for more than a few weeks. Those days are gone.. maintainability and reliability are king.

  5. Re:Perl is the most refreshing programming languag by arth1 · · Score: 4, Informative

    Don't avoid $_ and @_; use them when they are useful, even in implicit form. Perhaps especially in explicit form.

    What's more elegant?

    # Declare variable $mystring
    my($mystring);
    # Get rid of $_
    $mystring = $_;
    # Strip line endings from string
    # We use chomp because it will only delete CR and LF,
    # unlike chop which will delete any character.
    $mystring =~ chomp($mystring);
    # We do it twice in case the string ended in CR+LF
    # which is common in MSDOS
    $mystring =~ chomp($mystring);

    or

    require 5.9.0; # avoid ugly $foo =~ chop $foo
    my $mystring = $_;
    # Strip newlines
    while ($mystring =~ m/[\r\n]$/) {
      # String has CR or LF at end, strip it
      chop $mystring;
    }

    or

    # chop any number of CR and LF from end of string:
    chomp while chomp;

    I have seen far too much misguided code of the first and second type.

    Have the comments explain what the purpose of the code is, not how it does it. The way to fix perl code isn't to read and understand the actual code, but replace the part that doesn't work as expected with code that does. If you understand your comment and know how to write perl, you don't really need to understand how a cryptic line does something - it's faster to rewrite it from scratch to do what you want.

  6. Re:Wasn't that supposed to be Ruby? by RDW · · Score: 3, Insightful

    You can write 'Modern Perl' in the sense used here without switching to an entirely different language:

    http://www.onyxneon.com/books/modern_perl/index.html

  7. Assumptions by CadentOrange · · Score: 5, Insightful

    If you understand your comment and know how to write perl, you don't really need to understand how a cryptic line does something - it's faster to rewrite it from scratch to do what you want.

    That assumes that the comment correctly describes what the code intends to do. This is a very big assumption to make and I've worked on numerous projects where the comments were significantly different from what the code did. Looking through the change logs, this situation always arises because someone updated the code but didn't bother to update the comments.

    This brings me to my point: The code doesn't lie.

    If you can't understand a piece of code, you're going to be working off assumptions. Refactoring code based on assumptions is dangerous unless you have very rigorous unit tests. I've found that the level of code obfuscation is negatively correlated with the quality (or even presence!) of unit tests. YMMV.

  8. Re:Yet Another by MadMartigan2001 · · Score: 4, Informative

    Mojolicious is a complete HTTP 1.1 stack. No mod_perl required. It has its own built in webserver, hypnotoad which can be used in production. You can install Mojolicous with a single curl command

    sudo sh -c "curl -L cpanmin.us | perl - Mojolicious"

    And three lines can make a complete "hello world" application....

    use Mojolicious::Lite;
    get '/' => {text => 'Hello World!'};
    app->start;

    Part of what make Mojolicous so powerful is Perl's syntax and expressiveness. I know it's hip to beat up on Perl these days, but perl is still way ahead of most languages in its ability to be expressive. The author of Mojolicous is a really good programmer and insanely picky about well structured code, consistency and test driven development. Hence, the framework is very easy to use and understand. This framework is definitely worth a look.

  9. mojo by Rysc · · Score: 3, Interesting

    Totally apart from a pretty slick MVC framework the Mojolicious project has my undying affection for producing the mojo tool.

    How many times have you wanted to scrape something out of a web page and you thought "I know, I'll use wget (or curl) and sed! Easy enough." so you write

    # get story titles from slashdot
    wget slashdot.org -O - 2>/dev/null | sed -e 's/uh, what now?//'

    And then you get stuck fiddling with ever-crazier sed expressions to filter down to just the data you want? I know I've been there a dozen times and wound up with various unpleasant solutions or, when necessary, I've broken down and written a proper perl script which parses the HTML (and taken about 20 times as long as I planned to take to do it!) Maybe you try

    # get story titles from slashdot
    wget slashdot.org -O - 2>/dev/null | sed -n '/"title-/{s/<[^>]*>//g;s/^[ \t]*//;p}'

    And just go with it, because it's good enough. Well, no more! Now I can say

    mojo get slashdot.org 'h2.story > span:first-child>a' text

    And have my results just like that!

    Just as jQuery was a revolution in DOM scripting, to the point where I just won't write JS without it, so is mojo a revolution for these kinds of applications. I can now pull down pages and parse the actual structure and select just what I need. Beautiful.

    --
    I want my Cowboyneal