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

30 of 132 comments (clear)

  1. Yet Another by bragr · · Score: 2

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

    1. 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.
    2. Re:Yet Another by drjones78 · · Score: 2

      mod_perl is out - no reason to use it any more, especially since its tied explicitly to Apache. Yuk. Who wants to write a web app that requires a specific web server?

      Mojo runs on PSGI, like most new generation web frameworks for perl. Its similar to WSGI (Python).

      There's some really cool stuff happening in the PSGI world. Check out Plack.

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

    4. Re:Yet Another by Just+Some+Guy · · Score: 2

      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.

      But far behind the languages that it's competing with in this space. There's a reason why literally ever Perl programmer I know has migrated to Ruby or Python.

      I'd much rather write a web app in Perl than C or Pascal. And by roughly the same margin, I'd much rather write the same app on Rails or Django or Pyramid.

      --
      Dewey, what part of this looks like authorities should be involved?
  2. Re:no post = dead by bragr · · Score: 2

    Says the AC posting on a site written in perl.

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

  4. Wasn't that supposed to be Ruby? by Sarusa · · Score: 2, Interesting

    Not to take anything away from this framework, but now I'm curious since at first I took the post title too literally. Wasn't Ruby supposed to be modern Perl for the web? Whatever happened to that? People get bored? Web developer ADHD?

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

    2. Re:Wasn't that supposed to be Ruby? by Kagetsuki · · Score: 2

      Sounds like you haven't touched Rails in 10 years. It handles unicode extremely well now, arguably better than any other framework out there, and even has an extended set of localization options that are way more accessible than probably anything else. As for your other arguments:
      1. Monkey patching is dangerous in any language - luckily with modern Rails there is significantly less need for it and it's generally discouraged
      2. ?? Sounds like you were doing something wrong
      3. You don't understand what the C in MVC means, do you?

    3. Re:Wasn't that supposed to be Ruby? by CadentOrange · · Score: 2

      Ruby has been in decline. Interestingly, so have PHP and Python. At it's peak in 2009, Ruby barely exceed's Python's current usage.

      Ruby: http://www.tiobe.com/index.php/paperinfo/tpci/Ruby.html

      Python: http://www.tiobe.com/index.php/paperinfo/tpci/PHP.html

      PHP: http://www.tiobe.com/index.php/paperinfo/tpci/Python.html .

  5. Oh boy by 93+Escort+Wagon · · Score: 2, Insightful

    Another perl web framework. I can't wait. I'm champing at the bit. /yawn

    I use perl all the time, and have yet to run into a framework that actually saves time overall. They're generally designed by Unix guys who really don't want to think about web design any more than they have to - and it shows.

    --
    #DeleteChrome
  6. Re:"Web development can be fun again" by nullchar · · Score: 2

    The only exciting part of this new Mojolicious is to expand on a bunch of Perl web stuff you might already maintain. I don't have any large apps (like slashdot), but many "single page" type applications that process data or serve up custom reports. The simple pages simply flush stdout so when displaying long output appear speedy to the user. Others use some javascript and cludgy .html() replacements. Websockets and json support would be nice when extending these applications where the "bulk" of the code written in plain Perl doesn't need to be modified.

  7. Re:"Web development can be fun again" by arth1 · · Score: 2

    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.

    String parsing and massaging.
    Hashes.

    Also, system administration. Like sed and awk, perl should be in most sysadmins' arsenal, seeing daily use.
    Want to replace all occurrences of foo with bar in all files, while making a backup?

    perl -pi.bak -e 's/foo/bar/g' *

    What perl is not good for, and frequently is abused for is providing multiple layers of abstraction. You burn memory at an alarming rate, and your code becomes even harder to maintain by "simplifying" it. If good perl code looks cryptic, add comments!

  8. 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?

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

  10. Re:"Web development can be fun again" by grcumb · · Score: 2
    I won't defend Perl's syntactical constructs; either you like the fluidity of the language or you don't. But Mojolicious is a modern, useable framework, far superior in important ways to Django.

    For my part, I find it remarkably easy to implement RPC calls, CRUD especially, using this framework. Go to CPAN, read the Mojolicious::Lite exampes and decide for yourself whether it's worth your while.

    --
    Crumb's Corollary: Never bring a knife to a bun fight.
  11. 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.

  12. Re:"Web development can be fun again" by Anonymous Coward · · Score: 2, Informative

    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.

    Well the really smart guys that figure out DNA started using it. Many startups use it. I've used it pretty much everywhere I've gone and it's leaps and bounds above what I find in use in most places. It's huge in Japan. It was the favorite language of the guy who created Ruby, he just wanted more.

    So yeah no serious application or anything that had to be maintained, no never that, because how could anyone possibly write maintainable Perl. Instead you should use a programming language where maintainability and reliability are king, that language of course is ...???

    By the way Slashdot the not so serious site you are on is written in Perl.

  13. Re:Perl is the most refreshing programming languag by arth1 · · Score: 2

    Indeed. While it's slower than "chomp while chomp", it doesn't depend on $/ being set correctly.

    (If you can rely on $/, and you golf, s-$/+$-- is even shorter)

  14. Re:"Web development can be fun again" by AlXtreme · · Score: 2

    By the looks of it Mojolicious does support stuff plain Django doesn't pay much attention to or leaves to the webserver (long polling for instance). Useful!

    Then again, Mojolicious doesn't have a built-in ORM or input-validation via forms. Together with URL handling and the request/response loop these are the basic building blocks in Django.

    So 'superior in important ways' depends on what you find important. I'm guessing 99% of Django users beg to differ.

    --
    This sig is intentionally left blank
  15. 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.

  16. Re:"Web development can be fun again" by CadentOrange · · Score: 2

    What happened to modularity?

    Django advocates loose coupling between it's modules. You can easily use Django's ORM in a non-Django app, or use a different ORM (e.g. SQLAlchemy) in a Django app. Having said that, I've found that the Django ORM is nice and intuitive if you're a programmer (like me!) and really want to avoid working with SQL directly while SQLAlchemy caters to people who are more comfortable with SQL.

  17. Re:"Web development can be fun again" by zippthorne · · Score: 2

    Your example of Perl is Slashcode? I'm not sure that has the desired affect on the audience...

    --
    Can you be Even More Awesome?!
  18. Re:"Web development can be fun again" by Anrego · · Score: 2

    Never said it _hasn't_ been used to write something maintainable.. just that I wouldn't use it for that (any more.. ).

    Yes you can write maintainable code in perl if you make a specific effort to do so, but to me that defeats the point. It's primarily a hack and slash language that lets you crank out code while you think. To me writing maintainable perl is like writing a quick one-off script in c++ or java. Yes you can do it, but why bother. Use the tool that is suited for the task.

    And the DNA thing is a perfect example of the kind of "we need an answer to this question, then don't care about the code afterwards" situations where perl is king.

  19. Re:"Web development can be fun again" by Jimmy+King · · Score: 2

    Perl can be as easy to read and maintain as the developer can be bothered to make it. Sloppy Perl is written by sloppy developers. It has proper variable scoping, namespacing, packages, object inheritance, etc. You also don't have to squeeze as much functionality into one line using as many special characters as possible.

    Sure, there's plenty of ugly Perl out there. I suspect much of that is stuff that started as a small, quickly hacked together script which grew into something larger. Perl also used to hold PHP's place as THE language to use for web back end stuff, so it had a lot of amateur devs doing stupid crap. I can find you awful code in any language you want, though. I've got some crazy Python in front of me right now.

    I'm not saying it's the best language to use anymore, but it's not even 1/4 as bad as people like to make it out to be around here. Plus many of its libraries are still easier to use and have more functionality than the equivalent libraries in other more popular languages (opinions on that may vary, of course). LWP is still my favorite web client library.

  20. Re:"Web development can be fun again" by Anrego · · Score: 2

    I agree that it's possible to write maintainable perl, but from my vantage point, perl is not really designed for this.

    To me it's more of a hack n` slash language. Code while you think. All those shortcuts and lack of boilerplate code and ability to just say "take this data, compare it with this, and do whatever" in a few lines is to me perl's strength. The fact that the resultant code is hard to read is the weakness. If you are not going to do that, and write code in a more rigid, designed manner to avoid this, why use perl in the first place? To me it's like writing a quick one-off type script in c++.. you can do it, but why would you want to? For the libraries as you said maybe.

    The argument that it's not the tools it's the developer stands, however I do think some tools are more oriented towards maintainability (java, c++) and others towards rapid development (perl). You get ugly code in every language, but perl almost directly encourages it. The CPAN tool is _the_ definition of perl. Works, but oh my god is this code or cyphertext!

  21. Re:Perl is the most refreshing programming languag by Just+Some+Guy · · Score: 2

    What's more elegant?

    mystring = mystring.rstrip()

    (or mystring = mystring.rstrip('\r\n') if you're pedantic about only removing EOL chars)

    --
    Dewey, what part of this looks like authorities should be involved?
  22. 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