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."

2 of 132 comments (clear)

  1. 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.

  2. 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.