Dancer2...::Config(3)

πŸ“¦
version 2.2.1 Β· 3 versions
, in fedora 44

✨ NAME ✨

Dancer2::Config β€” the Dancer2 Configuration Reference πŸ’– (yes bestie, this is the Dancer2...::Config(3) page from the User Contributed Perl Documentation, and it's about to be your fave)


πŸŽ€ VERSION πŸŽ€

version 2.2.1


πŸ’… DESCRIPTION πŸ’…

okay so. The Dancer2 default configuration system β€” implemented by Dancer2::ConfigReader::Config::Any β€” is the thing that handles reading and changing the configuration of your Dancer2 apps. Iconic behaviour honestly.

This doc walks you through how to manipulate Dancer2's configuration settings (either through code or via a file), and it also documents all the various settings that are available in Dancer2. So like, it's giving reference manual and tutorial energy. πŸ¦‹


🌸 MANIPULATING SETTINGS VIA CODE 🌸

You can change a setting with the keyword set:

use Dancer2;

# changing default settings
set port         => 8080;
set content_type => 'text/plain';
set startup_info => 0;

literally that easy. no cap. ✨


🌈 MANIPULATING SETTINGS VIA CONFIGURATION FILES 🌈

ngl, there is absolutely nothing wrong with using set to configure your application. In fact you might have some genuinely great reasons for doing so. But for greater flexibility, ease of deployment, etc., you should also consider extracting those settings into a configuration file. bestie behaviour, fr fr.

πŸ—‚ Configuration file path and file names

Dancer2 will first look for the file config.EXT (where EXT is the type of configuration file you're using; e.g. ini or json or yml) in the root directory of your application. This is considered your global Dancer2 config file. If you do not care to have separate settings for production and development environments (and btw, that is not a recommended practice!), then this file is all you need.

Next, Dancer2 will look for a file called config_local.EXT. This file is typically useful for deployment-specific configuration that should not be checked into source control. For instance, database credentials could be stored in this file. Any settings in this file are merged into the existing configuration such that those with the same name in your local configuration file will take precedence over those settings in the global file. πŸ‘‘

Next, Dancer2 will look in the environments directory for a configuration file specific to the platform you are deploying to (production.EXT or development.EXT, for example). Again, the configuration from the environment is merged with the existing configuration, with the deployment config taking precedence.

Finally, Dancer2 will look in the environments directory for a local configuration for the specific platform you are deploying to (e.g. production_local.EXT or development_local.EXT). The configuration in this file is merged as before.

Much like config_local.EXT, this file would be useful for environment-specific configuration that would not be checked into source control. For instance, when developing an application that talks to multiple services, each developer could have their own URLs to those services stored within their environments/development_local.yaml file. so cute, so organised. πŸŽ€

⚠️ Note, if there is no config.EXT, Dancer2 will not look for a config_local.EXT. The same is true for the local environment configuration. πŸ’€

🧚 Supported configuration file formats

Dancer2 supports any configuration file format that is supported by Config::Any. At the time of this writing, that includes:

  • YAML (.yml and .yaml)
  • JSON (.jsn and .json)
  • INI (.ini)
  • Apache-style configurations (.cnf and .conf)
  • XML (.xml)
  • Perl-style hashes (.pl and .perl)

Dancer2 iterates over these file extensions in the order provided by Config::Any and loads any config files that it finds, with later configuration information overriding earlier config information. To restrict which file extension Dancer2 looks for, you may set the DANCER_CONFIG_EXT environment variable to a specific extension and Dancer2 will only look for config files with that extension. 🫢

Make sure you pick the appropriate extension for your configuration file name, as Dancer2 guesses the type of format based on the file extension.

πŸ“ Sample configuration files

Note: Not all possibilities are covered here, only the most common options.

If you prefer YAML, a sample YAML based config file might look like this:

appname: "Hello"
charset: "UTF-8"
auto_page: 1

session: "YAML"
serializer: "JSON"

plugins:
  DBIC:
    default:
      dsn: dbi:SQLite:db/mydata.db
      schema_class: Hello::Schema

If JSON is more your thing, your file might look more like this:

{
    "appname": "Hello",
    "charset": "UTF-8",
    "auto_page": "1",
    "session": "YAML",
    "serializer": "JSON",
    "plugins": {
        "DBIC": {
            "default": {
                "dsn": "dbi:SQLite:db/mydata.db",
                "schema_class": "Hello::Schema"
            }
        }
    }
}

If you like Apache configuration files, try something similar to:

    appname = Hello
    charset = UTF-8
    auto_page = 1
    session = YAML
    serializer = JSON
    <plugins>
        <DBIC>
            <default>
                dsn = dbi =SQLite =db/mydata.db
                schema_class = Hello = =Schema
            </default>
        </DBIC>
    </plugins>

INI-style files are deliberately simplistic and not recommended for use in your Dancer2 applications. πŸ’€


πŸ¦‹ USING ALTERNATE CONFIG READERS πŸ¦‹

Dancer2 allows you to use your own configuration system too. See the Dancer2::ConfigReader documentation for more information.

πŸ’œ Bootstrapping other config readers

You can use the default Dancer2 configuration reader to load additional configuration/configuration readers:

additional_config_readers:
    - Dancer2::ConfigReader::SQLite:
        path: /path/to/sqlite.db
        table: config

See the Dancer2::ConfigReader documentation for more information and examples.


πŸ‘‘ SUPPORTED SETTINGS πŸ‘‘

πŸ”₯ Run mode and listening interface/port

  • host (string) β€” The IP address that the Dancer2 app should bind to. Default is 0.0.0.0, i.e. bind to all available interfaces.
  • port (int) β€” The port Dancer2 will listen to. Default value is 3000. This setting can be changed on the command-line with the --port switch.
  • behind_proxy (boolean) β€” If set to true, Dancer2 will look to X-Forwarded-Protocol and X-Forwarded-host when constructing URLs (for example, when using redirect or host). This is useful if your application is behind a proxy.
Note: If either of these are missing, the values of the proxy server will be used instead. For example, if the client sends a HTTP/1.0 request to a proxy that is hosted locally, then host will return the value localhost. In a similar vein, if the client makes a secure connection to the proxy, but the proxy does not pass X-Forwarded-Protocol, then base will return http://.... For these reasons, it is recommended that the values are hard-configured in the proxy if possible. For Apache this would be:
RequestHeader set X_FORWARDED_PROTO "https"
RequestHeader set X_FORWARDED_HOST "www.example.com"
  • no_default_middleware (boolean) β€” If set to true, your Dancer2 application will NOT be wrapped with the default PSGI middleware. The default middleware wrappers are:
    • Plack::Middleware::FixMissingBodyInRedirect
    • Plack::Middleware::Head
  • additional_config_readers β€” Dancer2::ConfigReader instances to bootstrap the application's configuration. See the ConfigReader's POD for more information.

🌈 Content type / character set

  • content_type (string) β€” The default content type of outgoing content. Default value is 'text/html'.
  • 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 Dancer2 in which charset the static files and templates are encoded.
    • If you're using Dancer2::Plugin::Database, UTF-8 support will automatically be enabled for your database β€” see "AUTOMATIC UTF-8 SUPPORT" in Dancer2::Plugin::Database

Default value is UTF-8. HTTP responses without charset will be interpreted as ISO-8859-1 by most clients.

If charset is empty, Dancer2 will not encode response bodies. Handlers should return already-encoded byte strings.

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).

Serialized JSON responses are UTF-8 encoded by the JSON serializer. Pass character strings to the serializer so it can do the encoding once. ✨

  • strict_utf8 (boolean) β€” Controls how invalid UTF-8 bytes are handled at decoding boundaries (request path/parameters) and in JSON serialization.
    • If false (default), invalid UTF-8 is left as bytes and a warning is emitted.
    • If true, invalid UTF-8 causes an immediate error. 😭
  • default_mime_type (string) β€” Dancer2's Dancer2::Core::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.

πŸ’– Serializing responses

  • serializer (string) β€” When writing a webservice, data serialization/deserialization is a common issue to deal with. Dancer2 can automatically handle that for you, via a serializer.

πŸŽ€ Available serializer engines

The following serializers are available, be aware they dynamically depend on Perl modules you may not have on your system.

  • JSON β€” Requires JSON.
  • YAML β€” Requires YAML,
  • XML β€” Requires XML::Simple.
  • Mutable β€” Will try to find the appropriate serializer using the Content-Type and Accept-type header of the request.

⭐ Serializer engine

The serializer can be configured in a separate engines section, like so:

serializer: "JSON"

engines:
  serializer:
    JSON:
      pretty: 1

See documentation for a particular serializer for supported options.

🌸 File / directory locations

  • environment (string) β€” This is the name of the environment that should be used. Standard Dancer2 applications have a environments folder with specific configuration files for different environments (usually development and production environments). They specify different kind of error reporting, deployment details, etc. These files are read after the generic config.yml configuration file.
  • appdir (directory)

Okay so bestie, this is the path where your application will live πŸ’– It's where Dancer2 goes looking by default for your config files, your templates and your static content.

It's typically set by use Dancer2 to use the same directory as your script.


public_dir (directory)

This is the directory where your static files get stored. Any file that already exists in there will be served as a static file, and it happens before anything gets matched against a route. so your CSS is safe, no cap.

See also static_handler.

Default: $appdir/public.

static_handler (boolean)

You have to declare this one and set it to true if you go and modify the standard public_dir location. yeah, it's a whole thing.

Default: true if $ENV{DANCER_PUBLIC} is set or public_dir is set to $appdir/public.

views (directory)

This is where your templates and layouts live. It's the "view" part of MVC (model, view, controller) ✨

Default: $appdir/views.

views can only be set once, preferably via config. Once the template engine is initialized, changing the views setting has no effect. periodt.

🌸 Templating & layouts 🌸

template

Lets you configure which template engine should be used. Like, to use Template Toolkit, you drop this into config.yml:

template: template_toolkit

layout (string)

The name of the layout to use when rendering a view. Dancer2 will look for a matching template in the directory $views/layouts.

You can override the default layout using the third argument of the template keyword. Check the Dancer2 manpage for the deets.

layout_dir (string)

A relative path where the layouts reside inside the views directory.

layout_dir: actual_layouts

Default: layouts.


πŸ› Logging, debugging and error handling πŸ›

startup_info (boolean)

Set it to true and it prints a banner when the server starts, with info like versions and the environment (or "dancefloor"). πŸ’…

Conforms to the environment variable DANCER_STARTUP_INFO.

traces (boolean)

If you set it to true, Dancer2 will display full stack traces whenever a warning or a die happens. (Internally it sets Carp::Verbose.) Defaults to false.

strict_config (boolean)

If it's true, Dancer2 will warn about unknown configuration keys at the top level, and about unknown keys in built-in engine sections where the options are actually known. Set it to false if you intentionally store application-specific settings at the top level, or if you use custom engines with extra configuration keys.

strict_config_allow (array)

A list of top-level configuration keys that strict config warnings should just ignore. This lets you keep strict_config enabled while still permitting application-specific keys. best of both worlds honestly.

strict_config: 1
strict_config_allow:
  - my_custom_key
  - feature_flags

no_server_tokens (boolean)

If true, Dancer2 won't add an X-Powered-By header, and it will avoid setting the Server header when you're using Dancer2's standalone server.

Defaults to false.

You can also use the environment variable DANCER_NO_SERVER_TOKENS.

logger (enum)

Pick which logger to use. For example, to write to log files with Dancer2::Logger::File:

logger: File

Or to direct log messages to the console you started your Dancer2 app from, with Dancer2::Logger::Console:

logger: Console

Loggers are configured with a corresponding Logger engine section, shown below πŸ‘‡

session (enum)

This setting lets you enable a session engine for your web application. By default, sessions are disabled in Dancer2 β€” you have to choose a session engine to use them.

Sessions are configured with a corresponding Session engine section, shown below πŸ‘‡

show_errors (boolean)

Deprecated configuration. πŸ™ˆ Use show_stacktrace, described below, instead.

show_stacktrace (boolean)

If true, Dancer2 renders a detailed debug screen whenever an error gets caught. If false, Dancer2 renders the default error page, using $public/$error_code.html if it exists, $views/$error_code.tt, 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_stacktrace enabled while in production β€” there's still a risk of divulging details. fr fr, do not.

error_template (template path)

This setting lets you specify a template to be used in case of a runtime error. Right now, the template (as well as the $views/$error_code.tt templates) can use four variables:

  • title β€” the error title.
  • content β€” the error-specific content (if any).
  • status β€” the HTTP status code throwing that error.
  • exception β€” the stringified exception (e.g. $@) if any.

Keep in mind that content and exception can vary depending on the problem.

For example:

  • A 404 has an empty exception, and content contains the URI that was not found. Unless you do the 404 yourself via send_error("You chose ... poorly!", 404);, and then content is You chose ... poorly!.
  • A 500 because of, say, dividing 0 by 0 will have an empty content and an exception like Illegal division by zero at ....
  • A 401 from send_error("You can not know the secret until you sign in grasshopper!", 401); will have an empty exception, and content will contain You can not know the secret until you sign in grasshopper!.

πŸ“‹ Logger engine πŸ“‹

The logger must be configured in a separate engines section, like so:

logger: Console

engines:
  logger:
    Console:
      log_level: core

All loggers support the configuration options below. See the documentation for a particular logger for other supported options.

log_level

This option tells which log messages should actually be logged. Possible values are core, info, debug, warning or error.

  • core β€” all messages are logged, including some from Dancer2 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 Dancer2 is doing. In production, you'll likely want error or warning only, for less-chatty logs.


πŸͺ Session engine πŸͺ

The session engine is configured in the engines section.

session: Simple

engines:
  session:
    Simple:
      cookie_name: dance.set
      cookie_duration: '24 hours'
      cookie_same_site: Lax
      is_secure: 1
      is_http_only: 1

See Dancer2::Core::Role::SessionFactory for more detailed documentation for these options, or the particular session engine for other supported options.

cookie_name

The name of the cookie to store the session ID in. Defaults to dancer.session. This can be overridden by certain session engines.

cookie_domain

The domain of the cookie. By default there is no domain defined for the cookie.

cookie_path

The path of the cookie. By default there is no path defined for the cookie.

cookie_duration

The session expiry time in seconds, or as e.g. 2 hours (see expires in Dancer2::Core::Cookie). By default, there is no specific expiry time.

cookie_same_site

Restricts the session cookie to a first-party or same-site context. Valid values are Strict, Lax, or None.

Refer to RFC6265bis https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site for further details regarding same-site context.

is_secure

The user's session ID is stored in a cookie. If the is_secure setting is set to a true value, the cookie will be marked as secure, meaning it should only be sent over HTTPS connections. πŸ”’

is_http_only

This setting defaults to 1 and instructs the session cookie to be created with the HttpOnly option active, meaning that JavaScript will not be able to access its value. πŸ™ˆ


πŸ¦‹ auto_page (boolean) πŸ¦‹

For simple pages where you're not doing anything dynamic, but you still want to use the template engine to provide headers etc, you can use the auto_page feature to avoid needing to create a route for every single page. iconic.

With auto_page enabled, if the requested path doesn't match any specific route, Dancer2 will check in the views directory for a matching template, and use it to satisfy the request if it's found.

Simply enable auto_page in your config:

auto_page: 1

Then, if you request /foo/bar, Dancer2 will look in the views dir for /foo/bar.tt.

Dancer2 will honor your before_template_render code, and all default variables. They will be accessible and interpolated on automatically served pages.


🧚 dsl_class 🧚

For complex applications that require extended DSL keywords or other functionality, the DSL class used can be specified at import time or in the config settings.

dsl_class: 'My::DSL'

This is the same as specifying

use Dancer2 dsl => 'My::DSL'

in your module. dsl_class defaults to Dancer2::Core::DSL if not specified.


🌈 Environment variables 🌈

  • DANCER_CONFIG_READERS β€” Specifies which configuration reader classes can be used to load Dancer2 configuration.
  • DANCER_CONFDIR β€” Sets the configuration directory. This is only guaranteed to work with the default config reader.
  • DANCER_CONFIG_VERBOSE β€” Outputs a lot of debugging information when reading the configuration of the application. This is only guaranteed to work with the default config reader.
  • DANCER_ENVDIR β€” Sets the environment directory. This correlates to the envdir config option. This is only guaranteed to work with the default config reader.
  • PLACK_ENV β€” Sets the given environment. This can be overridden by DANCER_ENVIRONMENT.
  • DANCER_ENVIRONMENT β€” Sets the given environment. This takes higher precedence over PLACK_ENV. If neither PLACK_ENV or DANCER_ENVIRONMENT is set, the environment defaults to development.
  • DANCER_APPHANDLER β€” The DANCER_APPHANDLER configuration controls what the dance keyword does. If it is set to PSGI (which will automatically be set if PLACK_ENV is set), dance will return the PSGI application coderef. Otherwise (which is the default β€” Standalone), it runs the Plack standalone server with the application.
  • DANCER_PORT β€” Sets the port which will be used by the development server (if not run by plackup).
  • DANCER_SERVER β€” Sets the host the development server will be used by the development server (if not run by plackup).

Note: this might change in the future.

  • DANCER_STARTUP_INFO β€” Controls whether to display start up info.
  • DANCER_NO_SERVER_TOKENS
  • ...and this one, the one we were literally just talking about, controls whether to display the server tokens. πŸŽ€
  • DANCER_PUBLIC β€” sets the public directory location. that's where your static lil files live, bestie. πŸ“
  • DANCER_TRACES β€” sets the tracing flag, which sets Carp's $Verbose flag. so when stuff goes sideways you get the whole story. πŸ”
  • DANCER_VIEWS β€” sets the views (templates) directory. your templates are literally the moment. 🎭
  • DANCER_LOGGER β€” sets the logger engine. pick your fave, she'll be logging everything. πŸ“
  • DANCER_CHARSET β€” sets the default charset. 🌈
  • DANCER_CONTENT_TYPE β€” sets the default content type. and if you don't set it? it defaults to text/html, no cap. 🫢

✨ SEE ALSO ✨

Dancer2 β€” go say hi, she's the whole reason we're here. πŸ’–


πŸ’œ AUTHOR πŸ’œ

Dancer Core Developers β€” the collective icons behind all of this. absolute legends, every single one. πŸ‘‘


This software is copyright (c) 2026 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.

fr fr, free as in do-whatever-you-want-with-it (as long as you keep the same terms as Perl 5 itself). slay. πŸ’…

and that's the whole page, bestie β€” we did it πŸ¦‹ this was Dancer2...::Config(3) from the User Contributed Perl Documentation, shipped with perl v5.42.3, dated 2026-09-20. ty for reading, ily, go build something iconic ✨🌸

πŸ“¦ where this page comes from