<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
=pod

Back in the early days of the web, many people learned Perl because of a
wonderful Perl library called L&lt;CGI&gt;.
It was simple enough to get started without knowing much about the language
and powerful enough to keep you going, learning by doing was much fun.
While most of the techniques used are outdated now, the idea behind it is not.
L&lt;Mojolicious&gt; is a new attempt at implementing this idea using state of the
art technology.

=head2 Features

=over 2

=item *

An amazing MVC web framework supporting a simplified single file mode through
L&lt;Mojolicious::Lite&gt;.

=over 2

Powerful out of the box with RESTful routes, plugins, Perl-ish templates,
session management, signed cookies, testing framework, static file server,
I18N, first class unicode support and much more for you to discover.

=back

=item *

Very clean, portable and Object Oriented pure Perl API without any hidden
magic and no requirements besides Perl 5.8.7 (although 5.10+ is recommended).

=item *

Full stack HTTP 1.1 and WebSocket client/server implementation with IPv6,
TLS, Bonjour, IDNA, Comet (long polling), chunking and multipart support.

=item *

Built-in async IO web server supporting epoll, kqueue, UNIX domain sockets
and hot deployment, perfect for embedding.

=item *

Automatic CGI, FastCGI and L&lt;PSGI&gt; detection.

=item *

JSON and XML/HTML5 parser with CSS3 selector support.

=item *

Fresh code based upon years of experience developing L&lt;Catalyst&gt;.

=back

=head2 Installation

All you need is a oneliner, it takes less than a minute.

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

=head2 Getting Started

These three lines are a whole web application.

  use Mojolicious::Lite;

  get '/' =&gt; {text =&gt; 'Hello World!'};

  app-&gt;start;

To run this example with the built-in development web server just put the
code into a file and execute it with C&lt;perl&gt;.

  % perl hello.pl daemon
  Server available at http://127.0.0.1:3000.

  % curl http://127.0.0.1:3000/
  Hello World!

=head2 Duct Tape For The HTML5 Web

Web development for humans, making hard things possible and everything fun.

  use Mojolicious::Lite;

  # Simple plain text response
  get '/' =&gt; sub {
    my $self = shift;
    $self-&gt;render_text('Hello World!');
  };

  # Route associating the "/time" URL to template in DATA section
  get '/time' =&gt; 'clock';

  # RESTful web service sending JSON responses
  get '/list/:offset' =&gt; sub {
    my $self = shift;
    $self-&gt;render_json({list =&gt; [0 .. $self-&gt;param('offset')]});
  };

  # Scrape and return information from remote sites
  post '/title' =&gt; sub {
    my $self = shift;
    my $url  = $self-&gt;param('url') || 'http://mojolicio.us';
    $self-&gt;render_text(
      $self-&gt;ua-&gt;get($url)-&gt;res-&gt;dom-&gt;html-&gt;head-&gt;title-&gt;text);
  };

  # WebSocket echo service
  websocket '/echo' =&gt; sub {
    my $self = shift;
    $self-&gt;on_message(sub {
      my ($self, $message) = @_;
      $self-&gt;send_message("echo: $message");
    });
  };

  app-&gt;start;
  __DATA__

  @@ clock.html.ep
  % my ($second, $minute, $hour) = (localtime(time))[0, 1, 2];
  &lt;%= link_to clock =&gt; begin %&gt;
    The time is &lt;%= $hour %&gt;:&lt;%= $minute %&gt;:&lt;%= $second %&gt;.
  &lt;% end %&gt;

=head2 Growing

Single file prototypes can easily grow into well-structured applications.
A controller collects several actions together.

  package MyApp::Example;
  use Mojo::Base 'Mojolicious::Controller';

  # Plain text response
  sub hello {
    my $self = shift;
    $self-&gt;render_text('Hello World!');
  }

  # Render external template "templates/example/clock.html.ep"
  sub clock { }

  # RESTful web service sending JSON responses
  sub restful {
    my $self = shift;
    $self-&gt;render_json({list =&gt; [0 .. $self-&gt;param('offset')]});
  }

  # Scrape and return information from remote sites
  sub title {
    my $self = shift;
    my $url  = $self-&gt;param('url') || 'http://mojolicio.us';
    $self-&gt;render_text(
      $self-&gt;ua-&gt;get($url)-&gt;res-&gt;dom-&gt;html-&gt;head-&gt;title-&gt;text);
  }

  1;

While the application class is unique, you can have as many controllers as
you like.

  package MyApp::Realtime;
  use Mojo::Base 'Mojolicious::Controller';

  # WebSocket echo service
  sub echo {
    my $self = shift;
    $self-&gt;on_message(sub {
      my ($self, $message) = @_;
      $self-&gt;send_message("echo: $message");
    });
  }

  1;

Larger applications benefit from the separation of actions and routes,
especially when working in a team.

  package MyApp;
  use Mojo::Base 'Mojolicious';

  # Runs once on application startup
  sub startup {
    my $self = shift;
    my $r    = $self-&gt;routes;

    # Create a route at "/example" for the "MyApp::Example" controller
    my $example = $r-&gt;route('/example')-&gt;to('example#');

    # Connect these HTTP GET routes to actions in the controller
    # (paths are relative to the controller)
    $example-&gt;get('/')-&gt;to('#hello');
    $example-&gt;get('/time')-&gt;to('#clock');
    $example-&gt;get('/list/:offset')-&gt;to('#restful');

    # All common HTTP verbs are supported
    $example-&gt;post('/title')-&gt;to('#title');

    # ... and much, much more
    # (including multiple, auto-discovered controllers)
    $r-&gt;websocket('/echo')-&gt;to('realtime#echo');
  }

  1;

Through all of these changes, your action code and templates can stay almost
exactly the same.

  % my ($second, $minute, $hour) = (localtime(time))[0, 1, 2];
  &lt;%= link_to clock =&gt; begin %&gt;
    The time is &lt;%= $hour %&gt;:&lt;%= $minute %&gt;:&lt;%= $second %&gt;.
  &lt;% end %&gt;

Mojolicious has been designed from the ground up for a fun and unique
workflow.

=head2 Want to know more?

Take a look at our excellent documentation at L&lt;http://mojolicio.us/perldoc&gt;!

=cut
</pre></body></html>