Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New documentation draft: #1069

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
1,440 changes: 1,397 additions & 43 deletions lib/Dancer2.pm

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions lib/Dancer2/CLI/Gen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ option skel => (
format_doc => 'directory',
required => 0,
default => sub{
my $self = shift;
path( $self->parent_command->_dist_dir, 'skel' );
my $self = shift;
path( $self->parent_command->_dist_dir, 'skel' );
},
);

Expand All @@ -95,7 +95,7 @@ option git => (
default => 0,
);

option remote => (
option remote => (
is => 'ro',
short => 'r',
doc => 'URI for git repository (implies -g)',
Expand All @@ -108,8 +108,8 @@ option remote => (
sub BUILD {
my ( $self, $args ) = @_;

$self->osprey_usage( 1, qq{
Invalid application name. Application names must not contain single colons,
$self->osprey_usage( 1, qq{
Invalid application name. Application names must not contain single colons,
dots, hyphens or start with a number.
}) unless is_module_name( $self->application );

Expand Down Expand Up @@ -183,7 +183,7 @@ sub _check_git {

WARNING: Couldn't initialize a git repo despite being asked to do so.

To resolve this, cd to your application directory and run the following
To resolve this, cd to your application directory and run the following
commands:

git init
Expand All @@ -200,13 +200,13 @@ commands:
path( $gitignore )->copy( $app_path );

chdir File::Spec->rel2abs( $app_path ) or die "Can't cd to $app_path: $!";
if( _run_shell_cmd( 'git', 'init') != 0 or
_run_shell_cmd( 'git', 'add', '.') != 0 or
if( _run_shell_cmd( 'git', 'init') != 0 or
_run_shell_cmd( 'git', 'add', '.') != 0 or
_run_shell_cmd( 'git', 'commit', "-m 'Initial commit of $app_name by Dancer2'" ) != 0 ) {
print $git_error;
}
else {
if( $self->remote &&
if( $self->remote &&
_run_shell_cmd( 'git', 'remote', 'add', 'origin', $self->remote ) != 0 ) {
print $git_error;
print " git remote add origin " . $self->remote . "\n";
Expand Down Expand Up @@ -290,7 +290,7 @@ sub _build_file_list {
warn "File not found: $file" unless $file->exists; # Paranoia
next if $file->basename =~ m{^\.git(/|$)};
next if $file->is_dir;

my $filename = $file->relative( $from );
push @result, [ $file, path( $to, $filename )];
}
Expand All @@ -315,7 +315,7 @@ sub _copy_templates {
$to_dir->mkpath;
}

# Skeleton files whose names are prefixed with + need to be executable, but we must strip
# Skeleton files whose names are prefixed with + need to be executable, but we must strip
# that from the name when copying them
my $to_file = path( $to )->basename;
my $ex = ( $to_file =~ s/^\+// );
Expand Down Expand Up @@ -378,7 +378,7 @@ sub _process_template {
return $engine->render( \$template, $tokens );
}

# These are good candidates to move to Dancer2::CLI if other commands
# These are good candidates to move to Dancer2::CLI if other commands
# need them later.
sub _get_app_path {
my ( $self, $path, $appname ) = @_;
Expand Down Expand Up @@ -431,8 +431,8 @@ sub _run_shell_cmd {

my $exit_status = try {
my $pid = IPC::Open3::open3(
my $stdin,
my $stdout,
my $stdin,
my $stdout,
my $stderr = Symbol::gensym,
@cmds,
);
Expand Down
6 changes: 3 additions & 3 deletions lib/Dancer2/Cookbook.pod
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ In your C<config.yaml>:
Baz : 0

In your main route controller:

use Dancer2;
use Module::Runtime 'require_module';

Expand Down Expand Up @@ -737,8 +737,8 @@ Assuming we have the original user-creation form submitting a username and passw
use Dancer2::Plugin::Passphrase;
post '/register' => sub {
my $username = query_parameters->get('username');
my $password = passphrase(
query_parameters->get('password')
my $password = passphrase(
query_parameters->get('password')
)->generate;

# $password is now a hashed password object
Expand Down
4 changes: 2 additions & 2 deletions lib/Dancer2/Core/Role/ConfigReader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ sub _build_config_files {
if (my $ext = $ENV{DANCER_CONFIG_EXT}) {
if (grep { $ext eq $_ } @available_exts) {
@exts = $ext;
warn "Only looking for configs ending in '$ext'\n"
warn "Only looking for configs ending in '$ext'\n"
if $ENV{DANCER_CONFIG_VERBOSE};
} else {
warn "DANCER_CONFIG_EXT environment variable set to '$ext' which\n" .
Expand Down Expand Up @@ -155,7 +155,7 @@ sub _build_config {
$default,
map {
warn "Merging config file $_\n" if $ENV{DANCER_CONFIG_VERBOSE};
$self->load_config_file($_)
$self->load_config_file($_)
} @{ $self->config_files }
);

Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer2/Core/Role/SessionFactory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ argument and must return a hash reference of session data.
=head2 change_id

Changes the session ID of the corresponding session.

MySessionFactory->change_id(session => $session_object);

The method C<_change_id> must be implemented. It must take C<$old_id> and
Expand Down
8 changes: 4 additions & 4 deletions lib/Dancer2/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ requests.
=head2 Route Handlers

The route action is the code reference declared. It can access parameters
through the specific L<route_parameters|/route_parameters>,
through the specific L<route_parameters|/route_parameters>,
L<query_parameters|/query_parameters>, and L<body_parameters|/body_parameters>
keywords, which return a L<Hash::MultiValue> object.
keywords, which return a L<Hash::MultiValue> object.
This hashref is a merge of the route pattern matches and the request params.

You can find more details about how params are built and how to access them
Expand Down Expand Up @@ -1399,7 +1399,7 @@ The objects are accessible within the route handlers using the C<upload>
keyword:

post '/upload' => sub {
my $upload = upload('file_input_name'); # upload object
my $upload = upload('file_input_name'); # upload object
$upload->copy_to('Uploads/');
};

Expand Down Expand Up @@ -2263,5 +2263,5 @@ For example, take the following example:

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

See L<Dancer2::Manual::Keywords/DSL Keywords manual> for a complete list of
See L<Dancer2::Manual::Keywords/DSL Keywords manual> for a complete list of
keywords provided by Dancer2.
4 changes: 2 additions & 2 deletions lib/Dancer2/Manual/Deployment.pod
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,13 @@ The following modules can be used to speed up an app in Dancer2:

If you generated your application with C<dancer2 gen>, you can easily install
these with the following command:

cpanm --installdeps . --with-feature=accelerate

To build them, you will need access to a C compiler, and using these modules
will prevent you from fatpacking your application.

These modules are installed by default when building a Docker container
These modules are installed by default when building a Docker container
containing your application.

=cut
Expand Down
14 changes: 7 additions & 7 deletions lib/Dancer2/Manual/Keywords.pod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ route's regular expression.
}x
, sub {
my $value_for = captures;
"i don't want to $value_for->{action} " .
"i don't want to $value_for->{action} " .
"the $value_for->{object} $value_for->{id} !"
};

Expand Down Expand Up @@ -162,7 +162,7 @@ Deprecated. Use L<app> instead.

=head2 dance

Alias for the C<start> keyword. L<to_app> is preferable.
Alias for the C<start> keyword. L<to_app> is preferable.

=head2 dancer_app

Expand Down Expand Up @@ -202,9 +202,9 @@ Defines a route for HTTP B<DELETE> requests to the given URL:

=head2 delayed

Stream a response asynchronously. For more information, please see
L<Dancer2::Manual/Delayed responses (Async/Streaming)>, or
L<this article|https://advent.perldancer.org/2020/22> in the 2020 Dancer
Stream a response asynchronously. For more information, please see
L<Dancer2::Manual/Delayed responses (Async/Streaming)>, or
L<this article|https://advent.perldancer.org/2020/22> in the 2020 Dancer
Advent Calendar.

=head2 dirname
Expand All @@ -215,7 +215,7 @@ Returns the dirname of the path given:

=head2 done

Close the streaming connection. Can only be called within a streaming
Close the streaming connection. Can only be called within a streaming
response callback.

=head2 dsl
Expand Down Expand Up @@ -689,7 +689,7 @@ Returns request header(s).

=head2 response

Returns the current response object, which is of type
Returns the current response object, which is of type
L<Dancer2::Core::Route::REQUEST>.

=head2 response_header
Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer2/Manual/Migration.pod
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ The session keyword has multiple states:
=item * No arguments

Without any arguments, the session keyword returns a L<Dancer2::Core::Session>
object, which has methods for L<read|Dancer2::Core::Session/read>,
object, which has methods for L<read|Dancer2::Core::Session/read>,
L<write|Dancer2::Core::Session/write>, and L<delete|Dancer2::Core::Session/delete>.

my $session = session;
Expand Down
20 changes: 10 additions & 10 deletions lib/Dancer2/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ Calls to C<plugin_keywords> are cumulative.
For perl 5.12 and higher, keywords can also be defined by adding the C<:PluginKeyword> attribute
to the function you wish to export.

For Perl 5.10, the export triggered by the sub attribute comes too late in the
game, and the keywords won't be exported in the application namespace.
For Perl 5.10, the export triggered by the sub attribute comes too late in the
game, and the keywords won't be exported in the application namespace.

sub foo :PluginKeyword { ... }

Expand Down Expand Up @@ -937,7 +937,7 @@ do the following in a test:
};

flibble(45); # plugin keyword called which causes config read

set plugins => {
FooBar => {
wibble => 0, # this will NOT change plugin config
Expand Down Expand Up @@ -979,16 +979,16 @@ don't want anything imported via empty parentheses when C<use>ing the module:
It's easy to use plugins from within a plugin:

package Dancer2::Plugin::SourPuss;
use Dancer2::Plugin;
use Dancer2::Plugin::Polite;
sub my_keyword { my $smiley = smiley(); }

use Dancer2::Plugin;
use Dancer2::Plugin::Polite;

sub my_keyword { my $smiley = smiley(); }

1;

This does not export C<smiley()> into your application - it is only available
from within your plugin. However, from the example above, you can wrap
from within your plugin. However, from the example above, you can wrap
DSL from other plugins and make it available from your plugin.

=head2 Utilizing other plugins
Expand Down Expand Up @@ -1035,7 +1035,7 @@ Or using their alias:

$plugin->app->execute_hook( 'on_route_exception' );

B<Note:> If your plugin consumes a plugin that declares any hooks, those hooks
B<Note:> If your plugin consumes a plugin that declares any hooks, those hooks
are added to your application, even though DSL is not.

=head2 Writing Test Gotchas
Expand Down
12 changes: 6 additions & 6 deletions lib/Dancer2/Policy.pod
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ removals will double in length. After six months with no warning, a user's ban
length is reset. Removals, like warnings, are public.

The list of moderators consists of all active core developers. This includes,
in alphabetical order, Alberto Simões, David Precious, Jason Crome, Mickey
Nasriachi, Peter Mottram, Russell Jenkins, Sawyer X, Stefan Hornburg (Racke),
in alphabetical order, Alberto Simões, David Precious, Jason Crome, Mickey
Nasriachi, Peter Mottram, Russell Jenkins, Sawyer X, Stefan Hornburg (Racke),
Steven Humphrey, and Yanick Champoux.

This list might additionally grow to active members of the community who have
Expand All @@ -80,10 +80,10 @@ As a core principle, abuse is never tolerated. One cannot berate, insult,
debase, deride, put down, or vilify anyone, or act towards anyone in a way
intending to hurt them.

The community specifically considers as abuse any attempts to otherize anyone
by any individual characteristic, including, but not limited to, their
technical skill, knowledge or by their age, colour, disability, gender,
language, national or social origin, political or other opinion, race,
The community specifically considers as abuse any attempts to otherize anyone
by any individual characteristic, including, but not limited to, their
technical skill, knowledge or by their age, colour, disability, gender,
language, national or social origin, political or other opinion, race,
religion, sex, or sexual orientation.

The community aims to maintain a safe space for everyone, in any forum it
Expand Down
10 changes: 5 additions & 5 deletions lib/Dancer2/Template/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ To use this engine, you may configure L<Dancer2> via C<config.yaml>:

=head1 DESCRIPTION

This template engine is primarily to serve as a migration path for users of
L<Dancer>. It should be fine for development purposes, but you would be
This template engine is primarily to serve as a migration path for users of
L<Dancer>. It should be fine for development purposes, but you would be
better served by using L<Dancer2::Template::TemplateToolkit> or one of the
many alternatives available on CPAN to power an application with Dancer2
in production environment.
many alternatives available on CPAN to power an application with Dancer2
in production environment.

C<Dancer2::Template::Simple> is written in pure Perl and has no C bindings
C<Dancer2::Template::Simple> is written in pure Perl and has no C bindings
to accelerate the template processing.

=head1 SYNTAX
Expand Down
18 changes: 9 additions & 9 deletions lib/Dancer2/Template/TemplateToolkit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,26 @@ A subclass to use the aforementioned L<Template::Stash::AutoEscaping> might look

package Dancer2::Template::TemplateToolkit::AutoEscaping;
# or MyApp::

use Moo;
use Template::Stash::AutoEscaping;

extends 'Dancer2::Template::TemplateToolkit';

around '_build_engine' => sub {
my $orig = shift;
my $self = shift;

my $tt = $self->$orig(@_);

# replace the stash object
$tt->service->context->{STASH} = Template::Stash::AutoEscaping->new(
$self->config->{STASH}
);

return $tt;
};

1;

You can then use this new subclass in your config file instead of C<template_toolkit>.
Expand Down Expand Up @@ -208,11 +208,11 @@ used. Cached templates are automatically updated when you update the original te

By default, cached templates are saved in the same directory as your template. To save
cached templates in a different directory, you can set the C<COMPILE_DIR> property in your
Dancer2 configuration file.
Dancer2 configuration file.

Please see L<Template::Manual::Config/Caching_and_Compiling_Options> for further
details and more caching options.

=head1 SEE ALSO

L<Dancer2>, L<Dancer2::Core::Role::Template>, L<Template::Toolkit>.
Loading