
Mojolicious – Perl real-time web framework - megahz
http://mojolicio.us/
======
ThePhysicist
It's great to see such an awesome Perl project on HN, especially these days
when most folks here write Python, Ruby and JS and love to make fun of those
"nerdy old Perl hackers".

I mostly use Python these days myself but I'll never forget the sense of power
that Perl gave me when I learned it back in the late 90s (prior to Perl I had
programmed in Turbo Pascal and Basic). To most programming enthusiasts back
then it was what Python is today: A great, easy-to-learn, fun language that
let's you solve almost any problem with just a few lines of code, mostly
thanks to a huge ecosystem of powerful libraries (CPAN). Granted, the object-
orientation felt more like a hack than a normal language feature (because it
was one), but all in all it's still a really great language and just as
powerful as Python, JS or Ruby.

~~~
sigil
_Granted, the object-orientation [in Perl] felt more like a hack than a normal
language feature (because it was one)..._

Perl's OOP is definitely a hack! But it's a clever and elegant hack, and
younger languages can learn a lot from studying how an awk++ managed to evolve
support for all these new programming paradigms, without being totally co-
opted by the ones which turned out to be fads. (When these languages are
Perl's age, will they have evolved as successfully?)

Take OOP support in Perl. Prior to that, Perl had references, which could
point to other basic value types, and it had packages, which were namespaces
in the symbol table. Only two small changes were necessary for OOP.

First, a new built-in function `bless` was added which marked a reference as
associated with a certain package. Second, a new binary operator for dispatch
was added, the familiar `->` from other languages. The dispatch operator
looked up a package from the reference on the left hand side, looked up a
symbol within that package given by the right hand side, and pushed the
reference onto the front of the argument list in the subsequent function call.
In the called function, the initial reference argument became the equivalent
of `this`, by convention.

Modulo some discussion of @ISA, that's it. You now understand Perl's
implementation of OOP.

The elegance of this approach finally hit home for me when building
transparent RPC for Perl and other languages. On the client side, when you
dispatch a function call on a "stub" object, you'd like to dispatch a real
function call on a remote object. In Python, you have to worry about whether
you're calling a "bound function" on the remote object, versus calling a
static method of the remote object, versus calling a "free function" defined
at module scope (how do you address these?), and so on. In Perl, these are all
effectively the same thing because the dispatch operator is so simple, and
there's no extra OOP structure baked into the language itself like there is
with Python.

Disclaimer: I mostly write Python 2.x now, but things like the complicated
object runtime and the general uselessness of lambdas strike me as places
where the language has stumbled.

~~~
ThePhysicist
Great answer, thanks for explaining this! I'm curious about how much this
approach differs from the one pursued by Javascript, which seems pretty
similar to me.

~~~
perigrin
Javascript lacks the "packages" part of the mix, it uses Prototypal
inheritance rather than Class based inheritance.

If you squint you can view prototypal inheritance as class-based-inheritance-
where-everything-is-a-singleton ... but you really need some alcohol to deal
with the headache you get from squinting that much.

------
doesnt_know
The "installation" instructions wgets a script (over http) which in turn curls
a raw github link of cpanminus which is "a script to get, unpack, build and
install modules from CPAN" which then downloads and installs the perl module.

How many developers or "power users" would have just ran that command without
even thinking about it?

I guess signing packages with trusted keys and serving them over https is far
too lame for devs these days.

(Not that I'm calling out this particular project, it's seems to be crazy
popular to offer "curl some.script | bash" as installation instructions lately
for some reason.)

~~~
mike-cardwell
Hopefully, most people would check their package managers first. Debian and
Centos both have packages for it at least.

~~~
collyw
Distro packages are often a bit behind the official releases. I prefer to
develop in the most recent version of a framework / library, as it generally
makes things a bit more future proof.

~~~
BugBrother
What collyw said. And most people prefer to use their own installation of Perl
(see perlbrew) instead of the system Perl for development. The same seems to
go for other scripting environments.

------
f055
I've been using Mojolicious for about 5 years now - from somewhere around v1.0
- and it's been awesome. The more I learned the easier and quicker things got.
Now I use if for all my backend needs, from SaaS, APIs to real-time websockets
- and there's still a ton of things Mojo can do but I never tried them. Not to
mention Perl itself. And CPAN.

Let's face it - Perl is magic ;)

------
fibo
Mojolicious is best Perl web micro framework, remember that the Author also
started catalyst. Dancer is similar but I don't like dsl. Mojo is very fast,
powerful and expressive with a lor of features, mature and more perlish. Try
Mojolicious::Lite, there is no other web Framework that can write an app in a
single,file.

~~~
matthewmacleod
Flask, Sinatra, Rails, Express… actually, there are a lot of them.

~~~
grimgrin
Even Django!

[https://github.com/readevalprint/mini-
django/blob/master/min...](https://github.com/readevalprint/mini-
django/blob/master/mini_django.py)

~~~
Akron-
As far as I can see this is no full single file app: The template is stored
separately. In Mojolicious::Lite you can bundle all html/css etc. templates
and even images (as base64) in the data section of the file.

~~~
collyw
We are all arguing that you can bundle a whole app into a single file as if it
was a _good_ thing.

~~~
fibo
Yes, it is really good if you need to prototype quickly. Then you can use mojo
inflate command to turn a single app file into a Mojo project.

~~~
collyw
Its not realistically going to give you much of a productivity boost over
having two or three files.

------
perlgeek
I've done a few small projects with Mojolicious, and it's been real fun to
work with.

The only thing that's missing is a book that explains the concepts in more
depth than the documentation. (I believe some folks in the community are
working on that).

~~~
walterbell
It would be helpful to compare it with projects in other languages, e.g.
pro/con with Node.js or Erlang.

~~~
rihegher
I don't know much about erlang but I used to write node.js app and I still
maintain some today.

I really like the new concept brought by Node.js. However I realised that most
of the time I don't need/want to write asynchronous code which I found harder
to test and grow than synchronous code.

Now Mojolicious is a non-blocking IO framework that simulate blocking IO by
default. This means that with Mojo you can write code either with blocking or
non-blocking IO. To do that you'll have to learn using the mojo::IOLoop which
is less natural than node.js to do non blocking but does the job and got
easier to use with the 5.0 release.

With node.js you don't have that choice, you're stuck writing application
entirely asynchronous.

~~~
walterbell
Thanks. I found a 3-part tutorial at
[http://blogs.perl.org/users/joel_berger/mojolicious/](http://blogs.perl.org/users/joel_berger/mojolicious/)

------
elb0w
This is such a great project. I remember when it started back when I used to
work in perl. The main devs on it are awesome. If I ever build anything in
perl again that needs an webserver it would be this.

------
blue1
The problem with framework reviews is that they are mostly written by people
that have used just that one (not surprising since it takes some time to
become proficient in such things), and always the conclusion is, oh it is
awesome.

I would be much more interested in a comparison with the alternatives, for
example Mojolicious vs Catalyst, but apparently very few people are able to do
that.

~~~
perlgeek
I've used both Catalyst and Mojolicious. Mojolicious is much easier to get
started with, because you don't have to touch several namespaces just to get a
single page to render.

Also doing non-blocking stuff with Catalyst seems to be a real pain (though I
haven't tried it yet).

~~~
BugBrother
I liked the Catalyst tutorials and general documentation. But Catalyst is
_not_ Dancer, which is like chewing air to learn. :-)

When I read up a little on Mojolicious to have an opinion a couple of years
ago, it seemed more complex than Catalyst?

I'll put my JavaScript hobby aside and look at it again. Any good links?
[Except the one posted by walterbell at
[http://blogs.perl.org/users/joel_berger/mojolicious/](http://blogs.perl.org/users/joel_berger/mojolicious/)
Grumble, that was already on my reading list.]

~~~
Ultimatt
Catalyst is not less complex than Mojolicious, if that is your measure of
goodness. From an installing pov or from usability. In Mojolicious you don't
need Moose, and you don't have an explicit model layer so you aren't pushed
towards using an ORM. You can use either, but they aren't a hard or suggested
requirement. The MojoCasts might be a good place to start if all you've done
is read and come up with a slightly off impression
[http://mojocasts.com/e1](http://mojocasts.com/e1)

~~~
BugBrother
Thanks!

Those are elegant, I'll watch them as if they were new Seinfeld episodes. :-)

I didn't have a "slightly off impression", rather I didn't see a large reason
to go Mojo.* instead of Catalyst (without a need for real time support.)

------
lazyloop
My favourite IRC client is built with Mojolicious!
[http://convos.by/](http://convos.by/)

------
pimlottc
What exactly is a "real-time" web framework? Is that anything like being "web
scale"?

~~~
kraih
Not at all, it's a "real thing", the Wikipedia article might be of help.
[http://en.wikipedia.org/wiki/Real-
time_web](http://en.wikipedia.org/wiki/Real-time_web)

------
vijayboyapati
I've been developing with Perl for almost 20 years and am a great fan of it. I
think it's not difficult to write easy to read and understand Perl code
(although it's also not difficult to write awful Perl code). I'm very
interested to learn more about Mojolicious. I've been using and really
enjoying Perl Dancer, which from the example on the landing page of
Mojolicious looks very similar. Could someone familiar with the two give me a
summery of the differences and pros and cons between them?

------
odc
I love the combo Mojolicious + Mango (the MongoDB driver). They allow to build
a completely non-blocking applications very easily.

------
__Joker
If say I want to build a web application and new to Ruby, Python and Perl. But
I want to use one of the RoR, Flask (or Django), Mojolicious. Which one should
I go for. I.e. either one it had some advantage than other ? Rather, I know
Python so I should go for Flask, argument.

~~~
tmaly
In the Perl realm I chose Mojolicious because it has very little dependencies.
It does not come with an ORM or a built in user login. If you wanted that,
Catalyst is a better way to go. The Mojo Lite aspect of Mojolicious makes it
really easy to get a prototype up and running.

------
joeclark77
I used to love Perl... it's been about 15 years, though. What a great excuse
to learn it again!

------
qmaxquique
You can test and develop Mojolicious in a terminal.com container. Check my
snapshot at
[https://terminal.com/tiny/8TRpbtVffh](https://terminal.com/tiny/8TRpbtVffh)

------
Daviey
As web frameworks go, I prefer the experience of Django.... but a recent
project I did with Mojolicious was a really fast experience to 'get something'
together, whilst also staying out of the way.

------
sarciszewski
"curl get.mojolicio.us | sh"

Delicious! Let's pipe data retrieved over raw HTTP and pipe it directly to sh.
It's like one of those Head-On commercials (remember those?) only with digital
cyanide.

~~~
hadoukenio
As opposed to blindly downloading a repo and running "make install"? What's
the difference? If you really cared enough you would instead pipe it to a file
to inspect first. But I don't think you inspect most packages you download
from GitHub etc.

So again, what's the difference as opposed to convenience with the pipe?

~~~
andraganescu
Well, which is it more probable to to go unnoticed: a hack of the install
script you fetch via http or an entire github commit infesting the software
while it still lets it work as designed so no contributor notices?

It is not a problem with mojolicious at all. Its a nice helper that should be
carefully used.

------
instakill
Existing libraries around modern web frameworks sure do have a unicorn
obsession.

------
chawk
People still use Perl?

~~~
wschroed
Yes. And I am looking for Perl programmers right now:

    
    
      http://www.reddit.com/r/stljobs/comments/2a9940/seeking_software_developer_for_the_genome/
    
    

It gets the job done, is an easy language for people to get into, has enough
flexibility to adapt to a huge number of programming patterns, and has a large
and active community. We write real applications with it that help scientists
find cures for diseases.

~~~
collyw
Would there be any possibility of remote work from Europe? My current job is
building / maintaining the LIMS system for a sequencing centre in Spain. I did
that in Django, but I did years of Perl before hand.

~~~
wschroed
No. :( Our users -- lab folks -- are not particularly computer savvy, and
everyone benefits from the face time, especially when it comes to translating
what they said on a JIRA issue to their actual problem.

