Dancer2

 view release on metacpan or  search on metacpan

lib/Dancer2/Manual/Migration.pod  view on Meta::CPAN


=head2 Route parameters

The C<params> keyword which provides merged parameters used to allow body
parameters to override route parameters. Now route parameters take
precedence over query parameters and body parameters.

We have introduced C<route_parameters> to retrieve parameter values from
the route matching. Please refer to L<Dancer2::Manual> for more
information.

=head2 Tests

Dancer2 recommends the use of L<Plack::Test>.

For example:

    use strict;
    use warnings;
    use Test::More tests => 2;
    use Plack::Test;
    use HTTP::Request::Common;

    {
        package App::Test; # or whatever you want to call it
        get '/' => sub { template 'index' };
    }

    my $test = Plack::Test->create( App::Test->to_app );
    my $res  = $test->request( GET '/' );

    ok( $res->is_success, '[GET /] Successful' );
    like( $res->content, qr{<title>Test2</title>}, 'Correct title' );

Other modules that could be used for testing are:

=over 4

=item * L<Test::TCP>

=item * L<Test::WWW::Mechanize::PSGI>

=back

=head3 Logs

The C<logger_format> in the Logger role (L<Dancer2::Core::Role::Logger>)
is now C<log_format>.

C<read_logs> can no longer be used, as with L<Dancer2::Test>. Instead,
L<Dancer2::Logger::Capture> could be used for testing, to capture all
logs to an object.

For example:

    use strict;
    use warnings;
    use Test::More import => ['!pass'];
    use Plack::Test;
    use HTTP::Request::Common;
    use Ref::Util qw<is_coderef>;

    {
        package App;
        use Dancer2;

        set log       => 'debug';
        set logger    => 'capture';

        get '/' => sub {
            debug 'this is my debug message';
            return 1;
        };
    }

    my $app = Dancer2->psgi_app;
    ok( is_coderef($app), 'Got app' );

    test_psgi $app, sub {
        my $cb = shift;

        my $res = $cb->( GET '/' );
        is $res->code, 200;

        my $trap = App->dancer_app->logger_engine->trapper;

        is_deeply $trap->read, [
            { level => 'debug', message => 'this is my debug message' }
        ];
    };

=head2 Exports: Tags

The following tags are not needed in L<Dancer2>:

 use Dancer2 qw(:syntax);
 use Dancer2 qw(:tests);
 use Dancer2 qw(:script);

The C<plackup> command should be used instead. It provides a development
server and reads the configuration options in your command line utilities.

=head2 Engines

=over 4

=item * Engines receive a logging callback

Engines now receive a logging callback named C<log_cb>. Engines can use it
to log anything in run-time, without having to worry about what logging
engine is used.

This is provided as a callback because the logger might be changed in
run-time and we want engines to be able to always reach the current one
without having a reference back to the core application object.

The logger engine doesn't have the attribute since it is the logger itself.

=item * Engines handle encoding consistently

All engines are now expected to handle encoding on their own. User code



( run in 2.933 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )