package Dancer2::Manual::Tutorial; # ABSTRACT: A step-by-step guide to get you dancing __END__ =pod =encoding UTF-8 =head1 NAME Dancer2::Manual::Tutorial - A step-by-step guide to get you dancing =head1 VERSION version 2.1.0 =head1 Dancer2 Tutorial In this tutorial, you're going to end up with a working blog application, constructed from simple examples and demonstrations of techniques used in Dancer2 applications. If you'd like to see the finished product, you can clone the git repository containing the code used in this tutorial: git clone https://github.com/PerlDancer/DLBlog.git =head1 Introduction - the Danceyland Blog Danceyland wants to share information about happenings at the park on an ongoing basis, and feel the best medium for doing so is by publishing a blog. Your task is to construct a blog engine to facilitate this using Dancer2 and other Perl modules. =head2 What You'll Learn By the end of this tutorial, you'll know how to: =over =item * Scaffold a new Dancer2 app =item * Design and construct routes for an application =item * Work with sessions, templates, and databases =item * Extend your Dancer2 applications with plugins =item * Add authentication to Dancer2 applications =item * Perform a basic app deployment =back =head2 Prerequisites =over =item * Linux, BSD, or Windows with WSL and a Linux distribution installed (Strawberry Perl on Windows may work, but is not guaranteed) =item * SQLite 3, installed via your operating system's package manager =back =head1 Setting Up Your Environment =head2 Installing Dancer2 cpan Dancer2 or cpanm Dancer2 =head2 Creating Your First App dancer2 gen -a DLBlog Output: + DLBlog + DLBlog/.dancer + DLBlog/config.yml + DLBlog/cpanfile + DLBlog/Makefile.PL + DLBlog/MANIFEST.SKIP + DLBlog/t + DLBlog/t/002_index_route.t + DLBlog/t/001_base.t + DLBlog/environments + DLBlog/environments/production.yml + DLBlog/environments/development.yml + DLBlog/bin + DLBlog/bin/app.psgi + DLBlog/views + DLBlog/views/index.tt + DLBlog/public + DLBlog/public/dispatch.cgi + DLBlog/public/404.html + DLBlog/public/favicon.ico + DLBlog/public/500.html + DLBlog/public/dispatch.fcgi + DLBlog/lib + DLBlog/lib/DLBlog.pm + DLBlog/views/layouts + DLBlog/views/layouts/main.tt + DLBlog/public/images + DLBlog/public/images/perldancer.jpg + DLBlog/public/images/perldancer-bg.jpg + DLBlog/public/javascripts + DLBlog/public/javascripts/jquery.js + DLBlog/public/css + DLBlog/public/css/style.css + DLBlog/public/css/error.css Your new application is ready! To run it: cd DLBlog plackup bin/app.psgi To access your application, point your browser to http://localhost:5000 If you need community assistance, the following resources are available: - Dancer website: https://perldancer.org - Twitter: https://twitter.com/PerlDancer/ - GitHub: https://github.com/PerlDancer/Dancer2/ - Mailing list: https://lists.perldancer.org/mailman/listinfo/dancer-users - IRC: irc.perl.org#dancer Happy Dancing! Make sure to change to your new project directory to begin work: cd DLBlog =head2 Understanding Directory Structure Your application directory now contains several subdirectories: =over =item bin Contains the PSGI file that starts your application. Can be used for other utilities and scripts for your application. =item environments Configuration information. One file per environment (such as C and C). =item lib Your core application code. This is where you'll put your models, controllers, and other code. =item public Contains static files such as images, CSS, and JavaScript. Also contains instance scripts for CGI and FastCGI. =item t Tests for your application. =item views Contains templates and layouts. =back =head2 Using Plackup for Development plackup -r bin/app.psgi This autorestarts your application when changes are made to your code. This is ideal during development, but should not be used in a production setting. =head1 Configuring Our Application By default, new Dancer2 applications use L. While this works well for some types of apps, it's not well suited to applications like the Danceyland Blog. Instead, we'll configure this application to use L, a mainstay of Perl templating. To enable Template Toolkit, you'll need to edit your F: # template engine # tiny: default basic template engine # template_toolkit: TT #template: "tiny" template: "template_toolkit" engines: template: template_toolkit: # Note: start_tag and end_tag are regexes start_tag: '<%' end_tag: '%>' YAML files, such as your application config, support the same comment characters as Perl. L is disabled by commenting that line in your config file, and the default TT config is used by uncommenting the C