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 is 0.0.0.0, i.e. bind to all available interfaces. 🌐 Can also be set with environment variable DANCER_SERVER
  • port (int) β€” the port Dancer will listen to. Default value is 3000. This setting can be changed on the command-line with the --port switch. πŸ”Œ Can also be set with environment variable DANCER_PORT
  • daemon (boolean) β€” if set to true, runs the standalone webserver in the background. This setting can be changed on the command-line with the --daemon flag. πŸŒ€ Can also be enabled by setting environment variable DANCER_DAEMON to a true value.
  • behind_proxy (boolean) β€” if set to true, Dancer will look to X-Forwarded-Protocol and X-Forwarded-host when constructing URLs (for example, when using redirect). 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 variable DANCER_CONTENT_TYPE
  • charset (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" in Dancer::Plugin::Database

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's Dancer::MIME module uses application/data as 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 the default_mime_type to text/plain. πŸ“„

πŸ—‚οΈ File / directory locations πŸ—‚οΈ

  • environment (string) β€” this is the name of the environment that should be used. Standard Dancer applications have an environments folder 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 generic config.yml configuration 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 the view part 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 to config.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, config will return an object instead of a hash reference. See Dancer::Config::Object for more information. πŸ“¦
  • global_warnings (boolean, default: false) β€” if true, use warnings will be in effect for all modules and scripts loaded by your Dancer application. Default is false. Can also be enabled by setting the environment variable DANCER_WARNINGS to 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 variable DANCER_NO_STARTUP_INFO to 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 sets Carp::Verbose). Default is false. Can also be enabled by setting environment variable DANCER_TRACES to 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 an X-Powered-By header and also append the Dancer version to the Server header. Can also be disabled by setting the environment variable DANCER_NO_SERVER_TOKENS to a true value. 🏷️
  • log_path (string) β€” folder where the file "logger" saves log files. πŸ“
  • log_file (string) β€” name of the file to create when file "logger" is active. It defaults to the environment setting contents.
  • logger (enum) β€” select which logger to use. For example, to write to log files in log_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 are core, debug, warning or error. 🧐
    • core : all messages are logged, including some from Dancer itself
    • debug : all messages are logged
    • info : only info, warning and error messages are logged
    • warning : only warning and error messages are logged
    • error : 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.html if it exists or the template specified by the error_template setting. 🐞
πŸ™ˆ 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" in Dancer::Cookie). By default there is no specific expiry time. ⏳
  • session_name β€” the name of the cookie to store the session ID in. Defaults to dancer.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 to 1, and it tells the session cookie to be created with the HttpOnly option 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 their SameSite attribute 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 with GET request 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?). See Dancer::Route::Cache for the details. Default is false.
  • route_cache_size_limit (bytes) β€” maximum size of the route cache (e.g. 1024, 2M). Defaults to 10M (10MB) β€” see Dancer::Route::Cache.
  • route_cache_path_limit (number) β€” maximum number of routes to cache. Defaults to 600 β€” see Dancer::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_APPDIR
  • DANCER_APPHANDLER β€” a Dancer::Handler::* by default Dancer::Handler::Standalone
  • DANCER_AUTO_RELOAD
  • DANCER_CHARSET
  • DANCER_CONFDIR
  • DANCER_CONTENT_TYPE
  • DANCER_DAEMON
  • DANCER_ENVDIR
  • DANCER_ENVIRONMENT
  • DANCER_NO_SERVER_TOKENS
  • DANCER_NO_STARTUP_INFO
  • DANCER_LOGGER
  • DANCER_PORT
  • DANCER_SERVER
  • DANCER_TRACES
  • DANCER_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

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