Acme-CPANModulesBundle-Import-PerlDancerAdvent-2018
view release on metacpan or search on metacpan
devdata/http_advent.perldancer.org_2018_13 view on Meta::CPAN
we've recommended. The new doc project aims to address this by detailing
important concepts in a clear and simple way.</p>
<h2><a name="performance_improvements"></a>Performance Improvements</h2>
<p>Several important performance improvements were made to Dancer2, the most
important of which being the migration from <code>MooX::Types</code> to <code>Type::Tiny</code>.
When <code>Type::Tiny::XS</code> is used, the boost is even more significant.</p>
<h2><a name="security_improvements"></a>Security Improvements</h2>
<p>Two important security features were added:</p>
<p>The session engine now requires a <code>validate_id()</code> method to be implemented in
the various session engines. This requirement shuts down an attack vector by
making session IDs conform to a known format.</p>
<p>SysPete implemented a <code>change_session_id</code> keyword to easily change the
current session ID. This is a common (and recommended) security practice,
especially when privilege level changes within an application.</p>
<h2><a name="author"></a>Author</h2>
<p>This article has been written by Jason Crome (CromeDome) for the Perl Dancer
Advent Calendar 2018.</p>
<h2><a name="copyright"></a>Copyright</h2>
devdata/http_advent.perldancer.org_2018_18 view on Meta::CPAN
sub description { 'Activating our application' }
sub opt_desc {
return (
[ 'directory|d', 'Application directory' ],
# More options...
);
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
$opts->{'directory'}
or $self->usage_error('You did not provide a directory');
path( $opt->{'directory'} )->is_dir
or $self->usage_error('Path provided is not a directory');
}
sub execute {
my ( $self, $opt, $args ) = @_;
devdata/http_advent.perldancer.org_2018_22 view on Meta::CPAN
<pre class="prettyprint">use Dancer2::Plugin::ParamTypes;
register_type_check(...);
# Indented to make it more readable
get '/:id' => with_types [
[ 'route', 'id', 'Int' ],
'optional => [ 'query', 'action', 'Str' ],
] => sub {
my $id = route_parameters->{'id'};
# do something with $id because we know it exists and validated
if ( my $action = query_parameters->{'action'} ) {
# if it exists, we know it's validated
}
};</pre>
<h2><a name="reusability__reusability__reusability"></a>Reusability, reusability, reusability</h2>
<p><a href="https://metacpan.org/module/Dancer2::Plugin::ParamTypes">Dancer2::Plugin::ParamTypes</a> was built with a company code-abase in
mind, where you would like to have common types available. You could
easily accomplish that by subclassing it.</p>
<pre class="prettyprint">package Dancer2::Plugin::MyCommonTypes;
use Dancer2::Plugin;
devdata/http_advent.perldancer.org_2018_22 view on Meta::CPAN
[ 'route', 'entity', 'Str' ],
[ 'route', 'id', 'PositiveInt' ],
[ 'body', 'message', 'Str' ],
'optional' => [ 'body', 'sid', 'SHA1' ],
] => sub {
my ( $entity, $id ) = @{ route_parameters() }{qw< id entity >};
my $message = body_parameters->{'message'};
my $sid = body_parameters->{'sid'} || '';
# everything is validated and required parameters are checked
...
};</pre>
<h2><a name="could_i_do_more_with_it"></a>Could I do more with it?</h2>
<p>Absolutely!</p>
<h3><a name="handle_multiple_sources"></a>Handle multiple sources</h3>
<p>Normally, you would dictate to a user how they should send their
paramters (in the query, in the body, or as part of the path - in the
( run in 0.242 second using v1.01-cache-2.11-cpan-4d50c553e7e )