NAME

Drogo - Lightweight web framework

SYNOPSIS

Kick-start a project: drogo --create=[projectname]

or

app.psgi:

use Drogo::Server::PSGI;
use Example::App;

my $app = sub {
    my $env = shift;

    return sub {
        my $respond = shift;

        # create new server object
        my $server = Drogo::Server::PSGI->new( env => $env, respond => $respond );

        Example::App->handler( server  => $server );
    }
};

Example/App.pm:

package Example::App;
use strict;

use Drogo::Dispatch( auto_import => 1 );

sub init
{
    my $self = shift;

    $self->{foo} = 'bar';
}

sub primary :Index
{
    my $self = shift;

    # $self->r is a shared response/requet object
    # $self->request/req gives a request object
    # $self->response/res gives a response object
    # $self->dispatcher returns drogo object
    # $self->server is a server object

    $self->r->header('text/html'); # default
    $self->r->status(200); # defaults to 200 anyways

    $self->r->print('Welcome!');
    $self->r->print(q[Go here: <a href="/moo">Mooville</a>]);
}

# referenced by /foo
sub foo :Action
{
    my $self = shift;
    my $stuff = $self->r->param('stuff');

    $self->r->print('Howdy!');
}

sub stream_this :Action
{
    my $self = shift;

    # stop dispatcher
    $self->dispatcher->dispatching(0);

    $self->server->header_out('ETag' => 'fakeetag');
    $self->server->header_out('Cache-Control' => 'public, max-age=31536000');
    $self->server->send_http_header('text/html');
    $self->server->print('This was directly streamed');
}

# referenced by /moo/whatever
sub moo :ActionMatch
{
    my $self = shift;
    my @args = $self->r->matches;

    $self->r->print('Howdy: ' . $args[0]);
}

# referenced by /king/whatever/snake/whatever
sub beavers :ActionRegex('king/(.*)/snake/(.*)')
{
    my $self = shift;
    my @args = $self->matches;

    $self->r->print("roar: $args[0], $args[1]");
}
}

METHODS

$self->server

Returns the server object.

$self->uri

Returns the uri.

$self->module_url

Returns the url associated with the module.

$self->filename

Returns the path filename.

$self->request_method

Returns the request_method.

$self->remote_addr

Returns the remote_addr.

$self->header_in

Return value of header_in.

$self->print(...)

Output via http.

$self->auto_header

Returns true if set, otherwise args 1 sets true and 0 false.

$self->dispatching

Returns true if we're dispatching actively.

$self->header_set('header_type', 'value')

Set output header.

$self->header('content-type')

Set content type.

$self->headers

Returns hashref of response headers.

$self->location('url')

Redirect to a url (sets the Location header out).

$self->status(...)

Set output status... (200, 404, etc...) If no argument given, returns status.

$self->request_part(...)

Returns reference for upload.

{
   'filename' => 'filename',
   'tmp_file' => '/tmp/drogomp-23198-1330057261',
   'fh'       => \*{'Drogo::MultiPart::$request_part{...}'},
   'name'     => 'foo'
}

$self->param(...)

Return a parameter passed via CGI--works like CGI::param.

$self->param_hash

Return a friendly hashref of CGI parameters.

$self->request_body & $self->request

Returns request body.

$self->request_parts

Returns arrayref of request parts, used for multipart/form-data requests.

$self->args

Returns args.

$self->matches

Returns array of post_arguments (matching path after a matched ActionMatch attribute) Returns array of matching elements when used with ActionRegex.

$self->post_args

Same as matches, deprecated.

process_auto_header

Process the autoheader.

error_stack

Returns the "error stack" as an array.

get_error

Returns error as string.

$self->unescape

Unscape HTTP URI encoding.

$self->cookie

Cookie methods:

$self->cookie->set(-name => 'foo', -value => 'bar');
my %cookies = $self->cookie->read;

$self->elapsed_time

Returns elapsed time since initial dispatch.

COPYRIGHT

Copyright 2011, 2012 Ohio-Pennsylvania Software, LLC.

LICENSE

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.