# ABSTRACT: Dancer2 DSL Keyword Reference package Dancer2::Manual::Keywords; __END__ =pod =encoding UTF-8 =head1 NAME Dancer2::Manual::Keywords - Dancer2 DSL Keyword Reference =head1 VERSION version 2.0.0 =head1 Dancer2 Keyword Guide This guide categorizes all Dancer2 keywords with descriptions, usage guidance, and relationships with other keywords. Each entry links to the relevant section in the L. =head1 Routing Keywords =head2 L Defines a route that responds to any HTTP method. B: Handle routes that accept multiple methods (e.g., C and C). B: All HTTP methods. =head2 L Defines a route that responds to HTTP C requests. B: Delete resources. B: L, L, L, L, L, L =head2 L Defines a route that responds to HTTP C requests. Automatically creates a C route. B: Fetch static resources or perform read-only actions. B: L, L, L, L, L, L =head2 L Defines a route that responds to HTTP C requests. B: Check available HTTP methods for a resource. B: All HTTP methods. =head2 L Defines a route that responds to HTTP C requests, often for partial updates. B: Partially update existing resources. B: L, L, L, L, L, L =head2 L Defines a route that responds to HTTP C requests, typically for form submissions or resource creation. B: Submit forms, upload files, or create resources. B: L, L, L, L, L, L =head2 L Defines a common path prefix for grouped routes. B: Organize routes logically under a shared prefix. B: All HTTP methods. =head2 L Defines a route that responds to HTTP C requests, often for updating resources. B: Update existing resources in an idempotent way. B: L, L, L, L, L, L =head2 L Retrieves a list value captured by a wildcard parameter in routes. B: Use with wildcard routes to capture arbitrary path segments. B: L =head1 URL and Route Helper Keywords =head2 L Constructs a URI for a given path and query parameters. B: Generate URLs for links and redirects. B: L =head2 L Constructs a URI for a named route. B: Generate URLs based on route names and parameters. B: Use L with named routes to ensure consistency even if route paths change. B: L =head1 Request Handling Keywords =head2 L Retrieves parameters specifically from the request body. B: Handle C or C data. B: L, L, L. =head2 L Accesses all regex capture groups from a route pattern. B: Extract parts of a URL matched by a regex route. B: L =head2 context Deprecated. Use L instead. B: L =head2 L Retrieves a parameter from the request (query, body, or route parameters). B: Not recommended. Use L, L, or L for clarity. B: Avoid using L in new code to prevent confusion between parameter sources. Instead, use more specific keywords. B: L, L, L, L =head2 L Returns all parameters from the request as a hash reference. B: Retrieve all request parameters at once. B: Prefer specific keywords like L for clarity in code. B: L, L, L, L =head2 L Retrieves parameters specifically from the query string. B: Handle parameters in the query string (e.g., for searches). B: L, L, L =head2 L Provides access to the current HTTP request object. B: Get details about the incoming request (headers, method, path). B: L, L, L =head2 request_data Retrieves the raw data from the request body. If a serializer is set, data will be automatically deserialized. B: Access the unprocessed body content of the request, especially when dealing with custom or non-standard payloads. B: L, L, L =head2 L Fetches the value of a specific header from the incoming request. B: Obtain information from request headers, such as 'User-Agent' or 'Authorization'. B: L, L =head2 L Retrieves parameters from the route pattern. B: Handle named or wildcard route parameters. B: L, L, L =head2 L Uploads a file and makes it accessible as a L object. If you named multiple files with the same name, C keyword returns an array of L objects: post '/some/route' => sub { my ($file1, $file2) = upload('files_input'); # $file1 and $file2 are Dancer2::Core::Request::Upload objects }; You can also access the raw hashref of parsed uploads via the current request object: post '/some/route' => sub { my $all_uploads = request->uploads; # $all_uploads->{'file_input_foo'} is a Dancer2::Core::Request::Upload object # $all_uploads->{'files_input'} is an arrayref of Dancer2::Core::Request::Upload objects }; B: To handle file uploads from client requests. B: L, L =head1 Response Handling Keywords =head2 L Sets the content of the response. This B works within a delayed response. This will crash: get '/' => sub { content 'Hello, world!'; }; But this will work just fine: get '/' => sub { delayed { content 'Hello, world!'; }; }; B: Directly set content of an asynchronous response. B: L =head2 L Sets the C header of the response. B: Specify the MIME type of the response. B: L =head2 L Deserializes a JSON string to a Perl data structure. Does not trigger serialization hooks. B: When you need to translate incoming JSON to a Perl hashref. B: L, L =head2 L Initiates an asynchronous response. Requires a Plack/PSGI server capable of serving requests asynchronously. B: When starting an asynchronous reponse. B: L, L =head2 L Finalizes an asynchronous repsonse and closes the connection. Can only be run within the streaming response callback. B: When finishing delivery of data asynchronously. B: L, L =head2 L Serializes a data structure to a UTF-8 encoded binary JSON string. Calling this keyword will not trigger the application's serializer hooks. B: When needing to translate a Perl data structure to JSON. B: L, L =head2 L Flushes content headers when streaming a response. This is necessary when C is called multiple times. B: When streaming large amounts of data (such as video) asynchronously. B: L, L =head2 L Forwards the request to another route handler. B: Internally redirect to another route within the app. B: L =head2 L Deserializes a L structure. B: When you need to turn a L structure into a Perl hashref. B: L, L =head2 L Deserializes a JSON string into a Perl data structure. Does not account for UTF-8 characters. B: Decode JSON data from the client. L is likely what you want. B: L =head2 L Deserializes a YAML structure. B: When you need to turn YAML into a Perl hashref. B: L, L =head2 L Halts request processing and sends a response immediately. B: Stop processing and return a response early. B: Combine L with L to ensure appropriate HTTP response codes are sent. B: L, L =head2 C
Deprecated. Use L instead. B: L. =head2 C Deprecated. Use L instead. B: L. =head2 L Passes control to the next matching route. B: Skip the current route and try the next one. B: L =head2 C Deprecated. Use L instead. B: Don't. Use L. B: L. =head2 L Adds a new value to an existing response header without replacing its current value. B: Append additional values to headers like 'Set-Cookie' or 'X-Forwarded-For'. B: L, L =head2 L Redirects the client to a different location. B: Redirect users to another route or external URL. B: L =head2 L Provides access to the current response object. B: Manipulate the outgoing response (headers, status, content). B: L, L
, L
=head2 L Sets or retrieves a specific header in the outgoing response. B: Modify or access response headers before sending them to the client. B: L, L =head2 L Returns a hash reference of all headers set in the response. B: Inspect or manipulate multiple response headers simultaneously. B: L, L =head2 L Manually serializes and sends the response in a specific format. B: Control response serialization explicitly. B: C, C. =head2 L Immediately halts processing and sends an error response with a specific status code. B: To send a custom error response. B: L, L =head2 L Sends a file to the client. B: Send files from disk or in-memory data as a file. B: L =head2 L Sets the HTTP status code for the response. B: Specify response codes (e.g., 200, 404). B: Combine L with L for clearer error handling when sending error responses. B: L, L =head2 L Serializes a Perl data structure into a string using Data::Dumper. B: Convert complex data structures into a readable string format for debugging. B: L, L, L =head2 L Serializes a Perl data structure to JSON. Does not account or UTF-8 characters. B: Encode data to JSON format. B: L, L =head2 L Serializes a Perl data structure into a YAML string. B: Convert data structures into YAML format. B: L, L, L =head1 Session and Cookie Keywords =head2 L Retrieves the value of a specific cookie from the request. B: Access individual cookies. B: L, L =head2 L Retrieves all cookies from the request as a hash reference. B: Inspect or manage multiple cookies. B: L =head2 L Stores, retrieves, or removes data from the session. B: Persist user-specific data between requests. B: L, L =head1 Application Configuration Keywords =head2 L Returns an instance of the app. App is a L. B: When calling methods only available via the application object. B: L =head2 L Retrieves the entire application configuration as a hash reference. B: Access or inspect all configuration settings. B: L, L =head2 C Alias for L. B: Use L instead. B: L =head2 L Retrieve full version number of installed Dancer2. B: To help manage compatability and feature usage in your applications. B: L =head2 L Retrieves major version number of Dancer2. B: To help manage compatability and feature usage in your applications. B: L =head2 L Function to help initialize and configure your Dancer2 app. B: When you need to run initialization or setup code once at the start of your application. B: L =head2 C Provides access to the Dancer2 runner object, which manages the application's execution. B: Control or inspect the application's runtime environment. B: L, L =head2 L Sets a configuration value for the application. B: Change configuration dynamically at runtime. B: L, L =head2 L Retrieves a configuration value. B: Access app configuration values. B: L, L =head2 C Initiates the Dancer2 application; typically called internally. B: Rarely used directly; see L instead. B: L, L =head2 L Sets a variable in the application context. B: Store temporary data accessible in routes and templates. B: L =head2 L Retrieves the application context variables. B: Access data stored with L. B: L =head1 Hooks =head2 L Declares a hook to run custom code at specific stages in the request/response lifecycle. B: Modify requests or responses, or perform actions at predefined lifecycle points. B: L, L =head1 Template Keywords =head2 L Renders a view with the provided data. B: Generate HTML or other formats dynamically. B: L =head1 Logging Keywords =head2 L Logs a message at the debug level. B: Detailed debugging and diagnostic messages. B: Use appropriate logging levels to maintain clear and actionable logs. B: L, L, L, L =head2 L Logs a message at the error level. B: Log errors that need immediate attention. B: Use appropriate logging levels to maintain clear and actionable logs. B: L, L, L, L =head2 L Logs a message at the info level. B: General informational messages. B: Use appropriate logging levels to maintain clear and actionable logs. B: L, L, L, L =head2 L Logs a message at a specified level. B: Log messages with custom or dynamic levels. B: L, L, L, L =head2 L Provides access to the logger object. B: Advanced logging scenarios. B: L, L, L, L, L =head2 L Logs a message at the warning level. B: Logging non-critical issues that may need attention. B: Use appropriate logging levels to maintain clear and actionable logs. B: L, L, L, L =head1 Miscellaneous Keywords =head2 dance Alias to the L keyword. B: This keyword has been superseded by L. B: Use L instead. B: L =head2 dirname Given a path, return the directory name. B: When you need to extract the directory name given a path. B: L =head2 dsl Provides access to the DSL (Domain Specific Language) object. B: When writing plugins or extending Dancer2's capabilities. B: None. =head2 engine Given a namespace, return the current engine object. For example: my $template_engine = engine 'template'; B: When you need to manually interact with one of the underlying engines in Dancer2. B: L, L, L =head2 C Returns a false value. B: Explicitly return a false value in your application. B: L =head2 mime Provide access to your application's instance of L. B: When querying or changing your application's MIME settings. B: L =head2 path Concatenates multiple paths together without worrying about the underlying operating system. It cleans the path aesthetically, but does not verify its existence. B: When you need to generate a filesystem path within your application. B: L =head2 psgi_app Provides the same functionality as L, but uses the deprecated Dispatcher engine. B: This keyword has been superseded by L. B: Use L instead. B: L. =head2 L Returns the PSGI application code reference for the current Dancer2 app. B: Integrate the Dancer2 application with other PSGI-compatible frameworks or servers. B: L, L =head2 C Returns a true value. B: Explicitly return a true value in your application. B: L =head1 AUTHOR Dancer Core Developers =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2025 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. =cut