Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cafe01/mojolicious-plugin-facets
https://github.com/cafe01/mojolicious-plugin-facets
Last synced: about 22 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/cafe01/mojolicious-plugin-facets
- Owner: cafe01
- License: other
- Created: 2018-03-13T18:17:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-08T13:14:47.000Z (over 6 years ago)
- Last Synced: 2024-10-11T21:08:12.880Z (26 days ago)
- Language: Perl
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
# NAME
Mojolicious::Plugin::Facets - Multiple facets for your app.
# SYNOPSIS
package MyApp;
use Mojo::Base 'Mojolicious';
sub startup {
my $app = shift;# set default static/renderer paths, routes and namespaces
$app->plugin('Facets',
backoffice => {
host => 'backoffice.example.com',
setup => \&_setup_backoffice
}
# or a path-based facet
# request URL gets rebased to the facet path (for that path only)
# backoffice => {
# path => '/backoffice',
# setup => \&_setup_backoffice
# }
);
}sub _setup_backoffice {
my $app = shift;# set default static/renderer paths, routes and namespaces
@{$app->static->paths} = ($app->home->child('backoffice/static')->to_string);
@{$app->renderer->paths} = ($app->home->child('backoffice/template')->to_string);# setup session
$app->sessions->cookie_name('backoffice');
$app->sessions->default_expiration(60 * 10); # 10 min# setup routes
my $r = $app->routes;
@{$r->namespaces} = ('MyApp::Backoffice');
$r->get(...);
}# DESCRIPTION
Mojolicious::Plugin::Facets allows you to declare multiple facets on a Mojolicious app.
A Facet is a way to organize your app as if it were multiple apps. Each facet can
declare its own routes, namespaces, static paths and renderer paths.A common use case is to create a facet for the backoffice application.
# HELPERS
## facet\_do
Run a subroutine in the context of a facet. Any code related to sessions,
routes, template rendering and static files works as if you were on that facet.# Example: get backoffice facet session when the facet shares the same host (i.e. path-based facet)
my $backoffice_session = $c->facet_do(backoffice => sub { shift->session });## has\_facet
if ($c->has_facet('foo')) { ... }
# LICENSE
Copyright (C) Carlos Fernando Avila Gratz.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.# AUTHOR
Carlos Fernando Avila Gratz