Acme-CPANModulesBundle-Import-PerlDancerAdvent-2018
view release on metacpan or search on metacpan
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:
a) place your modifications in the Public Domain or otherwise make them
devdata/http_advent.perldancer.org_2018_17 view on Meta::CPAN
sasl_password: 'nevairbe'</pre>
<p>In development you want to <b>prevent</b> email going out to <b>real users</b>.</p>
<p>This can be done with the <a href="https://metacpan.org/pod/Email::Sender::Transport::Redirect">Redirect</a> transport:</p>
<pre class="prettyprint">plugins:
Email:
transport:
Sendmail:
redirect_address: racke@perl.dance</pre>
<p>All email will be send to the specificied address, but with extra headers added with the original recipients:</p>
<pre class="prettyprint">X-Intercepted-To: "Bar" <bar@perl.dance>
X-Intercepted-Cc: "Baz" <baz@perl.dance></pre>
<p>Note: it's the presence of the <code>redirect_address</code> parameter which tells the
plugin you want mails redirected to that address, this will work with whatever
transport you wish to use.</p>
<h3><a name="preseed_headers"></a>Preseed headers</h3>
<p>If you have a standard email address and/or you want to have extra email headers, you can specify these in the
configuration as well:</p>
devdata/http_advent.perldancer.org_2018_18 view on Meta::CPAN
# matches a certain naming convention
my $app_name = $opt->{'application'};
$app_name =~ /^My::Company::App::/
or $self->usage_error('App must be prefixed by "My::Company::App");
# Maybe check we are only scaffolding in a particular directory
cwd() eq '/opt/my_company/webapps/'
or $self->usage_error('Only create apps in our webapps directory');
# At this point, we can run the original scaffolding
$self->SUPER::execute( $opt, $args );
# Now we finished generating, but we can contineu customizing what we have
}
1;</pre>
<p>Writing your own generation on top of the existing generation allows
you to manage the input (including additional validation) and the
output, giving you full control over the scaffolding process.</p>
devdata/http_advent.perldancer.org_2018_22 view on Meta::CPAN
$self->register_type_check 'Str' => sub {...};
$self->register_type_check 'ShortStr' => sub {...};
$self->register_type_check 'PositiveInt' => sub {...};
$self->register_type_check 'SHA1' => sub {...};
# Maybe more?
...
}</pre>
<p>Now we have our own plugin that also provides <code>with_types</code> which uses
the original plugin with a set of registered type checks.</p>
<pre class="prettyprint">package MyApp;
use Dancer2;
use Dancer2::Plugin::MyCommonTypes;
post '/:entity/update/:id' => with_types [
[ 'route', 'entity', 'Str' ],
[ 'route', 'id', 'PositiveInt' ],
[ 'body', 'message', 'Str' ],
'optional' => [ 'body', 'sid', 'SHA1' ],
devdata/http_advent.perldancer.org_2018_23 view on Meta::CPAN
<p>With <a href="https://metacpan.org/module/Dancer2::Logger::Console::Colored">Dancer2::Logger::Console::Colored</a> you can do that. It's a drop-in replacement for the default
console logger, but with color. It will make the message appear in color depending on the levels. You can turn
it on by setting your logger in your environment config file:</p>
<pre class="prettyprint">logger: "Console::Colored"</pre>
<p>Your log will instantly become cheerful and seasonal according to this default configuration:</p>
<pre class="prettyprint"># config.yml (these are the defaults)
engines:
logger:
Console::Colored:
colored_origin: "cyan"
colored_levels:
core: "bold bright_white"
debug: "bold bright_blue"
info: "bold green"
warning: "bold yellow"
error: "bold yellow on_red"
colored_messages:
core: "bold bright_white"
debug: "bold bright_blue"
info: "bold green"
warning: "bold yellow"
error: "bold yellow on_red"</pre>
<img src="/images/2018/23/log-1.png">
<p>The <code>colored_origin</code> refers to the part of the message that shows the package that this
message originated in, as well as the file name and line.</p>
<pre class="prettyprint">>> Dancer2 v0.207000 server 28764 listening on http://0.0.0.0:3000
[main:28764] debug @2018-12-19 20:31:06> Hello World in test.pl l. 6
^^^^ ^^^^^^^ ^</pre>
<p>The <code>colored_levels</code> are the log levels themselves.</p>
<pre class="prettyprint">[main:28764] debug @2018-12-19 20:31:06> Hello World in test.pl l. 6
^^^^^</pre>
<p>And the <code>colored_messages</code> refer to the actual message.</p>
<pre class="prettyprint">[main:28764] debug @2018-12-19 20:31:06> Hello World in test.pl l. 6
( run in 0.320 second using v1.01-cache-2.11-cpan-1c8d708658b )