Dancer::Config(3pm)
πΈ NAME πΈ
okay so bestie, meet Dancer::Config (3pm) β it's the whole vibe guide for how to configure Dancer to suit your needs β¨ (this one's from the User Contributed Perl Documentation, and yes, it's giving essential).
π’ VERSION π’
version 1.3522 π
π¦ DESCRIPTION π¦
Dancer::Config handles reading and changing the configuration of your Dancer apps. That's the whole job, no cap. This documentation is here to walk you through how to change settings, and which settings are even available to you in the first place. π«Ά
π SETTINGS π
You can change a setting with the keyword set, like this:
use Dancer;
# changing default settings
set port => 8080;
set content_type => 'text/plain';
set startup_info => 0;
But lowkey there's a better way: use a YAML file. For that to be possible, you have to install the YAML module. If a file named config.yml exists in the application directory, it will be loaded as a setting group. π
The same is done for the environment file located in the environments directory.
To fetch the available configuration values, use the config keyword β it returns a reference to a hash:
my $port = config->{port};
my $appdir = config->{appdir};
By default, the module YAML will be used to parse the configuration files. If you want, it's possible to use YAML::XS instead, by changing the YAML engine configuration in the application code:
config->{engines}{YAML}{module} = 'YAML::XS';
See Dancer::Serializer::YAML for more details. π
π SUPPORTED SETTINGS π
π Run mode and listening interface/port π
server(string) β the IP address that the Dancer app should bind to. Default is0.0.0.0, i.e. bind to all available interfaces. π Can also be set with environment variableDANCER_SERVERport(int) β the port Dancer will listen to. Default value is3000. This setting can be changed on the command-line with the--portswitch. π Can also be set with environment variableDANCER_PORTdaemon(boolean) β if set to true, runs the standalone webserver in the background. This setting can be changed on the command-line with the--daemonflag. π Can also be enabled by setting environment variableDANCER_DAEMONto a true value.behind_proxy(boolean) β if set to true, Dancer will look toX-Forwarded-ProtocolandX-Forwarded-hostwhen constructing URLs (for example, when usingredirect). This is useful if your application is behind a proxy. π°οΈ
It will also cause Dancer::Request->address to return what Dancer::Request->forwarded_for_address would return, namely the content of the HTTP_X_FORWARDED_FOR env var/header, so that requests will appear to have come from the end user's IP and not the proxy's.
β οΈ Because of the above, you should not turn this on if your app isn't behind a proxy which will pass this information on appropriately, otherwise a malicious user could supply false information. π¨
πΈ Content type / character set πΈ
content_type(string) β the default content type of outgoing content. Default value is'text/html'. Can also be set with environment variableDANCER_CONTENT_TYPEcharset(string) β this setting has multiple effects:- It sets the default charset of outgoing content.
"charset="item will be added to Content-Type response header. - It makes Unicode bodies in HTTP responses of
"text/*"types to be encoded to this charset. - It also indicates to Dancer in which charset the static files and templates are encoded.
- If you're using
Dancer::Plugin::Database, UTF-8 support will automatically be enabled for your database β see "AUTOMATIC UTF-8 SUPPORT" inDancer::Plugin::Database
- It sets the default charset of outgoing content.
Default value is empty which means don't do anything. HTTP responses without charset will be interpreted as ISO-8859-1 by most clients. π€·βοΈ
You can cancel any charset processing by specifying your own charset in Content-Type header or by ensuring that response body leaves your handler without Unicode flag set (by encoding it into some 8bit charset, for example).
Also, since automatically serialized JSON responses have application/json Content-Type, you should always encode them by hand. βοΈ
Can also be set with environment variable DANCER_CHARSET
default_mime_type(string) β Dancer'sDancer::MIMEmodule usesapplication/dataas a default mime type. This setting lets the user change it. For example, if you have a lot of files being served in the public folder that do not have an extension, and are text files, set thedefault_mime_typetotext/plain. π
ποΈ File / directory locations ποΈ
environment(string) β this is the name of the environment that should be used. Standard Dancer applications have anenvironmentsfolder with specific configuration files for different environments (usually development and production environments). They specify different kinds of error reporting, deployment details, etc. These files are read after the genericconfig.ymlconfiguration file. π
The running environment can be set with:
set environment => "production";
Note that this variable is also used as a default value if other values are not defined.
Can also be set with environment variable DANCER_ENVIRONMENT
appdir(directory) β this is the path where your application will live. It's where Dancer will look by default for your config files, templates and static content. π
It is typically set by use Dancer to use the same directory as your script.
Can also be set with environment variable DANCER_APPDIR
public(directory) β this is the directory, where static files are stored. Any existing file in that directory will be served as a static file, before matching any route. πΌοΈ
By default it points to $appdir/public.
views(directory) β this is the directory where your templates and layouts live. It's theviewpart of MVC (model, view, controller). π¨
This defaults to $appdir/views.
π§ Templating & layouts π§
templateβ allows you to configure which template engine should be used. For instance, to use Template Toolkit, add the following toconfig.yml:
template: template_toolkit
layout(string) β the name of the layout to use when rendering view. Dancer will look for a matching template in the directory$views/layouts. π
Your can override the default layout using the third argument of the template keyword. Check Dancer manpage for details.
π₯ Logging, debugging and error handling π₯
strict_config(boolean, default: false) β if true,configwill return an object instead of a hash reference. SeeDancer::Config::Objectfor more information. π¦global_warnings(boolean, default: false) β if true,use warningswill be in effect for all modules and scripts loaded by your Dancer application. Default is false. Can also be enabled by setting the environment variableDANCER_WARNINGSto a true value. β οΈstartup_info(boolean) β if set to true (the default), prints a banner at server startup with information such as versions and the environment (or "dancefloor"). π Can also be disabled by setting the environment variableDANCER_NO_STARTUP_INFOto a true value.warnings(boolean) β if set to true, tells Dancer to consider all warnings as blocking errors. Default is false. πtraces(boolean) β if set to true, Dancer will display full stack traces when a warning or a die occurs. (Internally setsCarp::Verbose). Default is false. Can also be enabled by setting environment variableDANCER_TRACESto a true value. πrequire_environment(boolean) β if set to true, Dancer will fail during startup if your environment file is missing or can't be read. This is especially useful in production when you have things like memcached settings that need to be set per-environment. Defaults to false. πserver_tokens(boolean) β if set to true (the default), Dancer will add anX-Powered-Byheader and also append the Dancer version to theServerheader. Can also be disabled by setting the environment variableDANCER_NO_SERVER_TOKENSto a true value. π·οΈlog_path(string) β folder where thefile "logger"saves log files. πlog_file(string) β name of the file to create whenfile "logger"is active. It defaults to theenvironmentsetting contents.logger(enum) β select which logger to use. For example, to write to log files inlog_path:
logger: file
Or to direct log messages to the console from which you started your Dancer app in standalone mode,
logger: console
Various other logger backends are available on CPAN, including Dancer::Logger::Syslog, Dancer::Logger::Log4perl, Dancer::Logger::PSGI (which can, with the aid of Plack middlewares, send log messages to a browser's console window) and others. π
Can also be set with environment variable DANCER_LOGGER
log(enum) β tells which log messages should be actually logged. Possible values arecore,debug,warningorerror. π§core: all messages are logged, including some from Dancer itselfdebug: all messages are loggedinfo: only info, warning and error messages are loggedwarning: only warning and error messages are loggederror: only error messages are logged
During development, you'll probably want to use debug to see your own debug messages, and core if you need to see what Dancer is doing. In production, you'll likely want error or warning only, for less-chatty logs. π€«
show_errors(boolean) β if set to true, Dancer will render a detailed debug screen whenever an error is caught. If set to false, Dancer will render the default error page, using$public/$error_code.htmlif it exists or the template specified by theerror_templatesetting. π
π The error screen attempts to sanitise sensitive looking information (passwords / card numbers in the request, etc) but you still should not have show_errors enabled whilst in production, as there is still a risk of divulging details. π
error_template(template path) β this setting lets you specify a template to be used in case of runtime error. At the present moment the template can use three variables: πtitleβ the error title.messageβ the error message.codeβ the code throwing that error.
π Session engine π
session(enum) β this setting lets you enable a session engine for your web application. By default sessions are disabled in Dancer. You must choose a session engine to use them. πͺ
See Dancer::Session for supported engines and their respective configuration.
session_expiresβ the session expiry time in seconds, or as e.g."2 hours"(see "expires" inDancer::Cookie). By default there is no specific expiry time. β³session_nameβ the name of the cookie to store the session ID in. Defaults todancer.session. This can be overridden by certain session engines. π·οΈsession_secure
The user's session ID is stored in a cookie. If the session_secure setting is set to a true value, the cookie gets marked as secure, which means it should only ever be sent over HTTPS connections. protection era π
session_is_http_onlyβ this one defaults to1, and it tells the session cookie to be created with theHttpOnlyoption switched on, meaning JavaScript literally cannot reach in and read its value. hands off, scripts π«Άsession_domainβ lets you set the domain property on the cookie, and it overrides the default. This is the move when you want your session cookie's domain to be something like".domain.com"so the exact same cookie is applicable and usable across subdomains of a base domain. one cookie, all the subdomains β¨session_same_siteβ if you set this, session cookies get theirSameSiteattribute set to whatever value you give, so you can control cross-site request cookie handling. If it is set, the value has to be one of the ones described in RFC6265bis β<hotpink>'Strict'</hotpink>,'Lax'or'None'. No freelancing, bestie."Strict"β cookies only get sent in a first-party context, and they will not be sent along with requests initiated by third party websites."Lax"β cookies are allowed to be sent with top-level navigations, and they will be sent along withGETrequest initiated by third party website. This is the default value in modern browsers. the people's choice π"None"β cookies get sent in all contexts, i.e. sending cross-origin is allowed. everybody gets a cookie π
πΈ auto_page (boolean) πΈ
Okay so for simple pages where you're not doing anything dynamic, but you still wanna use the template engine to provide headers etc, you can use the auto_page feature and skip having to create a route for every single page. lazy girl optimization, but make it valid π
With auto_page enabled, if the requested path doesn't match any specific route, Dancer checks in the views directory for a matching template, and uses it to satisfy the request if it finds one.
Simply enable auto_page in your config:
auto_page: 1
Then, if you request /foo/bar, Dancer will look in the views dir for /foo/bar.tt.
Dancer will honor your before_template_render code, and all default variables. They will be accessible and interpolated on automaticly-served pages. yes it says "automaticly", we don't make the rules π«
The pages served this way will have Content-Type set to text/html, so don't use the feature for anything else.
π Route caching π
route_cache(boolean) β if true, enables route caching (that's for quicker route resolution on larger apps β not caching of responses, okay?). SeeDancer::Route::Cachefor the details. Default isfalse.route_cache_size_limit(bytes) β maximum size of the route cache (e.g.1024,2M). Defaults to10M(10MB) β seeDancer::Route::Cache.route_cache_path_limit(number) β maximum number of routes to cache. Defaults to600β seeDancer::Route::Cache.
π¦ DANCER_CONFDIR and DANCER_ENVDIR π¦
You can totally set the configuration directory and the environment directory using these two environment variables. Setting `DANCER_CONFDIR` has the same effect as doing
set confdir => '/path/to/confdir'
and setting `DANCER_ENVDIR` is similar to:
set envdir => '/path/to/environments'
π ENVIRONMENT VARIABLES π
Some settings can be provided via environment variables at runtime, as detailed above; a full list of environment variables you can use follows. pick your fighters π
DANCER_APPDIRDANCER_APPHANDLERβ aDancer::Handler::*by defaultDancer::Handler::StandaloneDANCER_AUTO_RELOADDANCER_CHARSETDANCER_CONFDIRDANCER_CONTENT_TYPEDANCER_DAEMONDANCER_ENVDIRDANCER_ENVIRONMENTDANCER_NO_SERVER_TOKENSDANCER_NO_STARTUP_INFODANCER_LOGGERDANCER_PORTDANCER_SERVERDANCER_TRACESDANCER_WARNINGS
π AUTHOR π
This module has been written by Alexis Sukrieh <sukria@cpan.org> and others, see the AUTHORS file that comes with this distribution for details. shoutout to the whole squad π«Ά
π LICENSE π
This module is free software and is released under the same terms as Perl itself.
π SEE ALSO π
Dancer
β AUTHOR β
Dancer Core Developers
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2010 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie β this was perl v5.40.1, dated 2026-05-05, and it's the Dancer::Config(3pm) manpage. go forth and configure π
β¨
π¦ where this page comes from
- ubuntu stonking: libdancer-perl 1.3522-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms