NAME
Kelp::Module::Storage::Abstract - Abstract file storage for Kelp
SYNOPSIS
# in the configuration
modules => [qw(Storage::Abstract)],
modules_init => {
'Storage::Abstract' => {
driver => 'directory',
directory => '/path/to/rootdir',
public_routes => {
# map URL /public to the root of the storage
'/public' => '/',
},
kelp_extensions => 1,
},
},
DESCRIPTION
This module adds Storage::Abstract instance to Kelp, along with a static file server functionality and some file-related utility methods.
METHODS INTRODUCED TO KELP
storage
$obj = $app->storage
This is a Storage::Abstract object constructed using the module configuration.
CONFIGURATION
Most configuration values will be used to construct the underlying storage object. Consult Storage::Abstract and its drivers documentation for details.
Two special flags exist:
public_routes
This key, if passed, should be a hash reference where each key is a base route and each value is a storage path from which the files will be served. If you write:
public_routes => { '/public' => '/', },
Then it will be possible to access to all files from your storage through
/public
route. A Plack::App::Storage::Abstract instance will be set up on each of these routes.This route will be given a name corresponding to its url, with slashes replaced with underscores and
storage_
prepended. So the route above will be namedstorage_public
. You may use it to build URLs for this route - the additional path of the file must be passed as afile
placeholder, so for example:my $url = $app->url_for(storage_public => (file => 'my/file'));
kelp_extensions
This key will enable additional extensions to Kelp::Response. It will add a new method to it called
render_file
. This method will take files from your storage and render them much like Plack::App::Storage::Abstract does:$app->add_route('/serve_file' => sub { my $app = shift; $app->res->render_file('/file/path'); });
Note that it modifies the base Kelp::Response class and not create a subclass.
SEE ALSO
AUTHOR
Bartosz Jarzyna <bbrtj.pro@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2024 by Bartosz Jarzyna
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.