Marquee Marquee - Yet another Mojo based web framework

TABLE OF CONTENTS

NAME

Marquee - Yet another Mojo based web framework

SYNOPSIS

use Marquee directly.

#!/usr/bin/env perl
use strict;
use warnings;

use File::Basename 'dirname';
use File::Spec;
use lib join '/', File::Spec->splitdir(File::Spec->rel2abs(dirname(__FILE__))), 'lib';

use Marquee;

my $app = Marquee->new;
$app->document_root($app->home->rel_dir('public_html'));
$app->start;

Inherited application.

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

sub new {
    my $self = shift->SUPER::new(@_);
    
    $self->document_root($self->home->rel_dir('public_html'));
    $self->log_file($self->home->rel_dir('mojo_log/Marquee.log'));
    $self->default_file('index.html');
    $self->under_development(1);
    $self->secrets(['g3y3nheher']);
    
    return $self;
}

package main;

MyApp->new->start;

DESCRIPTION

Marquee distribution is yet another web framework built on mojo modules in Mojolicious distribution, designed to make dynamic content development to be plotted at an extension of designer work.

ATTRIBUTES

Marquee inherits all attributes from Mojo and implements the following new ones.

document_root

Specify a path to document root directory. The directory can contain both static files and templates.

$app->document_root($app->home->rel_dir('public_html'));

default_file

Specify a default file name and activate auto fill. The auto fill will occurs when the request path is trailing slashed.

$app->default_file('index.html');

dynamic

Marquee::Dynamic class instance.

$app->dynamic(Marquee::Dynamic->new);
my $dynamic = $app->dynamic;

error_document

Error document renderer instance. Defaults to Marquee::ErrorDocument.

$app->error_document(Marquee::ErrorDocument->new);

hooks

A Marquee::Hooks instance.

$app->hooks(Marquee::Hooks->new);

roots

Array of paths that contains static and templates. Marquee tries to find asset files in ascend order in the array. The array is started with "document_root" copy, and followed by bundle directories for Marquee core and plugins.

push(@{$app->roots}, 'path/to/additional_dir')

secrets

A secret passphrases used for signed cookies and the like, defaults to random string. By changing this, you can expire all signed cookies at once.

my $secrets = $app->secrets;
$app       = $app->secrets(['passw0rd']);

Only the first passphrase is used to create new signatures, but all of them for verification. So you can increase security without invalidating all your existing signed cookies by rotating passphrases, just add new ones to the front and remove old ones from the back.

# Rotate passphrases
$app->secrets(['new_passw0rd', 'old_passw0rd', 'very_old_passw0rd']);

stash

An Marquee::Stash instance. Though Marquee's stash is localized and cloned per request, this also can contain persistent values for application specific and can be referred transparently from anywhere.

$app->stash(Marquee::Stash->new);
my $stash = $app->stash;

static

Marquee::Static class instance.

$app->static(Marquee::Static->new);
my $static = $app->static;

types

Contains Mojolicious::Type instance.

my $type = $app->types;
$type->type(zip => 'application/zip');

under_development

Activate debug screen, defaults to undef.

$app->under_development(1);

x_powered_by

Set X-POWERED-BY response header.

$app->x_powered_by('MyApp');

The header appears as follows.

Content-Type: text/html;charset=UTF-8
X-Powered-By: MyApp
Server: Mojolicious (Perl)

CLASS METHODS

Marquee inherits all class methods from Mojo and implements the following new ones.

new

Constructor.

my $app = Marquee->new;

asset

Returns bundled asset path for given file name. If the file name not specified, The method returns the asset directory.

my $asset = Marquee->asset('path/to/common.css');

say $asset # /path/to/lib/Marquee/Asset/path/to/common.css

my $asset = Marquee->asset();

say $asset # /path/to/lib/Marquee/Asset

This method allows you to bundle files for perl modules in separated name spaces. The following is an example for getting bundle files of arbitrary module.

my $asset = SomePackage->Marquee::asset('path/to/common.css');

say $asset # /path/to/lib/SomePackage/Asset/path/to/common.css

my $asset = SomePackage->Marquee::asset();

say $asset # /path/to/lib/SomePackage/Asset

INSTANCE METHODS

Marquee inherits all instance methods from Mojo and implements the following new ones.

c

An alias for "context" method.

context

Returns current context. This refers to $Marquee::CONTEXT localized per request.

my $c = $app->context;

dispatch

Front dispatcher.

$app->dispatch()

handler

Handler called by mojo layer. This is the base point for every request and sets a response to $tx.

$app->handler($tx)

hook

Alias to $app->hooks->on. This adds a callback for specified hook point. These hooks are currently available:

around_dispatch

Wraps dispatch process.

$app->hook(around_dispatch => sub {
    my ($next) = @_;
    ### pre-process
    $next->();
    ### post-process
});
around_static

Wraps static dispatch process.

$app->hook(around_static => sub {
    my ($next, @args) = @_;
    ### pre-process
    $next->(@args);
    ### post-process
});
around_dynamic

Wraps dynamic dispatch process.

$app->hook(around_dynamic => sub {
    my ($next, @args) = @_;
    ### pre-process
    $next->(@args);
    ### post-process
});

is_directory

Returns if the path is directory. The search is made against the directories in "roots" attribute paths.

$app->is_directory('/path/to/directory') # bool

log_file

Set log file

$app->log_file('/path/to/file')

plugin

Load a class as a plugin. The prefix Marquee::Plugin is prepended unless the class name $class begins with + sign, which means the class name is already fully qualified.

my $plugin = $app->plugin(MyPlug => @params); # Marquee::Plugin::MyPlug
my $plugin = $app->plugin('+MyPlugins::MyPlug' => @params); # MyPlugins::MyPlug

serve

Serves specific content for given file path. This internally searches static contents and dynamic contents.

$app->serve('index.html');

serve_redirect

Serves response that redirects to given URI.

$app->serve_redirect('http://example.com/');
$app->serve_redirect('/path/');

start

Starts app

$app->start();

to_abs

Generates absolute URI for given path along to the request URI.

On request to https://example.com:3001/a/index.html The example below generates https://example.com:3001/path/to/file.html

say $self->to_abs('/path/to/file.html');

SEE ALSO

Mojolicious

AUTHOR

Sugama Keita, <sugama@jamadam.com>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Sugama Keita.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.