Skip to content

Commit

Permalink
Finished plugins and keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason A. Crome committed Nov 3, 2024
1 parent fcba4f7 commit df01e4a
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions lib/Dancer2/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1657,44 +1657,69 @@ for testing your app, making it easier to simulate interactions:

For more in-depth coverage of testing in Dancer2, check out L<Dancer2::Manual::Testing>.

=head1 Plugins

Danceyland is full of exciting rides and attractions, but sometimes you
need to add something extra—a little popcorn stand or a souvenir shop.
That’s where plugins come in!

=head2 What Are Plugins?

Plugins in Dancer2 are reusable modules that extend your app's
functionality. Whether it's connecting to a database, handling
authentication, or integrating with third-party services, plugins make
it easy to add features to your Dancer2 app without reinventing the
wheel.

=head2 Why Do We Need Plugins?

Plugins allow you to add functionality without having to reinvent the
wheel. Need authentication? Validation? Plugins are there to help you
focus on building the fun stuff, while they handle the heavy lifting.

Examples:

=over 4

=item Dancer2::Plugin::Auth::Tiny

L<Dancer2::Plugin::Auth::Tiny> provides a simple and easy way to protect
your routes with minimal authentication logic. For example, you can
restrict access to certain routes with this plugin.

=item Dancer2::Plugin::DataTransposeValidator

L<Dancer2::Plugin::DataTransposeValidator> allows you to validate
incoming data using L<Data::Transpose>, giving you flexibility when
handling forms and other user inputs.

=back

=head1 TODO find a spot for this, it's important
=head2 How to Write a Plugin?

When Dancer2 is imported to a script, that script becomes a webapp, and at
this point, all the script has to do is declare a list of B<routes>. A
route handler is composed by an HTTP method, a path pattern and a code
block. C<strict>, C<warnings> and C<utf8> pragmas are also imported with
Dancer2.
Writing a plugin for Dancer2 is as simple as creating a module that hooks
into the Dancer2 app lifecycle. It’s a fun ride! For detailed guidance on
writing plugins, refer to the Extending document.

TODO: link to be added

=head1 Complete Guide to Keywords

Danceyland has its own lingo that makes it easy to construct and
interact with your park, and with other developers working on the park.
Dancer2 provides you with a DSL (Domain-Specific Language) which makes
implementing your web application trivial.
it easy to implement, maintain, and extend your applications. You've
already learned many of these keywords, but there are additional ones
that provide even greater functionality.

See L<Dancer2::Manual::Keywords/DSL Keywords manual> for a complete list of
keywords provided by Dancer2.


For example, take the following example:

use Dancer2;

get '/hello/:name' => sub {
my $name = route_parameters->get('name');
};
dance;

C<get> and C<route_parameters> are keywords provided by Dancer2.

See L<Dancer2::Manual::Keywords/DSL Keywords manual> for a complete list of
keywords provided by Dancer2.

=head1 Plugins

Expand Down

0 comments on commit df01e4a

Please sign in to comment.