++ed by:
SRCHULO TOBYINK AERO

3 PAUSE users
2 non-PAUSE users.

Ashley Willis

NAME

Limper - extremely lightweight but not very powerful web application framework

VERSION

version 0.013

SYNOPSIS

  use Limper;

  my $generic = sub { 'yay' };

  get '/' => $generic;
  post '/' => $generic;

  post qr{^/foo/} => sub {
      status 202, 'whatevs';
      headers Foo => 'bar', Fizz => 'buzz';
      'you posted something: ' . request->{body};
  };

  get '/baz' => sub {
      'your non-decoded query, if any: ' . request->{query};    # URIs of '/baz?fizz=buzz&foo=bar' now work
  };

  limp;

DESCRIPTION

Limper was originally designed to primarily be a simple HTTP/1.1 test server in perl, but I realized it can be much more than that while still remaining simple.

Limper has a simple syntax like Dancer yet no dependencies at all, unlike the dozens that Dancer pulls in.

Limper is modular - support for serving files, easily returning JSON, or using PSGI can be included if and only if needed (and these features already exist on CPAN).

Limper is fast - about 2-3 times faster than Dancer.

Limper also fatpacks beautifully (at least on 5.10.1):

  fatpack pack example.pl > example-packed.pl

Do not taunt Limper.

EXPORTS

The following are all exported by default:

  get post put del trace options patch any
  status headers request response config hook limp

Also exportable:

  info warning rfc1123date

FUNCTIONS

get

post

put

del

trace

options

patch

Defines a route handler for METHOD to the given path:

  get '/' => sub { 'Hello world!' };

These can be chained together like so:

  get post del '/' => sub { 'Hello world!' };

Note that a route to match HEAD requests is automatically created as well for get.

any

Defines a route handler for all METHODs to the given path:

  any '/' => sub { 'Hello world!' };

status

Get or set the response status, and optionally reason.

  status 404;
  status 401, 'Nope';
  my $status = status;
  my ($status, $reason) = status;

headers

Get or set the response headers.

  headers Foo => 'bar', Fizz => 'buzz';
  headers Foo => ['this', 'that'];                # change Foo to two values
  headers Oops => 'inserted', Oops => 'ignored';  # don't do this
  my @headers = headers;

Note: Changed in 0.012. The headers are now stored in a hashref, where the value is either a string or array of strings. Calling headers in list mode returns a flattened list. If you want the hashref of headers, use response-{headers} >>. Setting header pairs no longer overwrites all previously defined headers.

request

Returns a HASH of the request. Request keys are: method, uri, and version. uri is now broken down and there are additional keys: scheme, authority, path, query, and fragment. It may also contain headers which is a HASH and body.

There is no decoding of the body content nor URL parameters.

response

Returns response HASH. Keys are status, reason, headers (a HASH of key/value pairs), and body.

config

Returns config HASH. See limp below for known config settings.

hook

Adds a hook at some position.

Three hooks are currently defined: after, request_handler, and response_handler.

after

Runs after all other processing, just before response is sent.

  hook after => sub {
    my ($request, $response) = @_;
    # modify response as needed
  };

request_handler

Runs when limp is called, after only setting passed config settings, and returns the result instead of starting up the built-in web server. A simplified example for PSGI (including the response_handler below) is:

  hook request_handler => sub {
    get_psgi @_;
    handle_request;
  };

response_handler

Runs right after the after hook, and returns the result instead of using the built-in web server for sending the response. For PSGI, this is:

  hook response_handler => sub {
    [ response->{status}, [headers], ref response->{body} ? response->{body} : [response->{body}] ];
  };

limp

Starts the server. You can pass it the same options as IO::Socket::INET takes. The default options are:

  Listen => SOMAXCONN, ReuseAddr => 1, LocalAddr => 'localhost', LocalPort => 8080, Proto => 'tcp'

In addition, the first argument can be a HASH to pass config settings:

  limp({debug => 1, timeout => 60, workers => 10}, LocalAddr => '0.0.0.0', LocalPort => 3001);

Default debug is 0, default timeout is 5 (seconds), and default workers is 10. A timeout of 0 means never timeout.

This keyword should be called at the very end of the script, once all routes are defined. At this point, Limper takes over control.

ADDITIONAL FUNCTIONS

info

warning

Log given list to STDOUT or STDERR. Prepends the current local time in format "YYYY-MM-DD HH:MM:SS".

rfc1123date

Returns the current time or passed timestamp as an HTTP 1.1 date (RFC 1123).

EVEN MORE

For additional (discouraged) functions to aid in transitioning to Limper, see Limper::Sugar.

For sending files and easily sending JSON, see Limper::SendFile and Limper::SendJSON.

For differences between Limper and Dancer, see Limper::Differences.

For extending Limper, see Limper::Extending.

NOTICE

This framework is still under development. Things may change without warning. Version 0.012 has such changes, but I hope I have what is in this version stable.

BREAKING CHANGES IN 0.012

options is now config, and there is a new function options for the HTTP method.

note has been changed to info.

headers now will update just the fields given, and not replace all the headers. The headers are now stored as a HASH instead of an ARRAY. Hence, response->{headers} cannot be directly passed to PSGI. Instead [headers] meets this need.

request->{header} is now what request->{hheader} was - no more ARRAY form.

CONTRIBUTING

Patches and Bug Fixes

Preferably, clone the repo (uses Dist::Zilla) and create one or more patch files with:

  git format patch <latest commit>

Email me the patch, or otherwise let me know how to find it.

Or if it's a simple patch and you don't want to mess with Dist::Zilla, patch the latest release and send me a patch file.

Module Namespaces

See "NAMESPACES" in Limper::Extending.

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Ashley Willis <ashley+perl@gitable.org>

rabcyr on irc and twitter.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.4 or, at your option, any later version of Perl 5 you may have available.

SEE ALSO

Limper::Differences

Limper::Extending

Limper::Engine::PSGI

Limper::SendFile

Limper::SendJSON

Limper::Sugar

App::FatPacker

IO::Socket::INET

Web::Simple