Dancer2

 view release on metacpan or  search on metacpan

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


        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
is expected to be in internal Perl representation.

Therefore, all serializers, for example, should deserialize to the Perl
representation. Templates, in turn, encode to UTF-8 if requested by the
user, or by default.

One side-effect of this is that C<from_yaml> will call L<YAML>'s C<Load>
function with decoded input.

=back

=head3 Templating engine changes

If you are migrating from Dancer1 and are using an application based
on L<Dancer::Template::Simple>, the L<Dancer2::Template::Simple> engine is
no longer part of the core Dancer2 distribution. It is available to
install as a separate distribution from CPAN.

In Dancer1, the following were equivalent for Template::Toolkit:

    template 'foo/bar'
    template '/foo/bar'

In Dancer2, when using L<Dancer2::Template::TemplateToolkit>, the version with
the leading slash will try to locate C</foo/bar> relative to your filesystem
root, not relative to your Dancer application directory.

The L<Dancer2::Template::Simple> engine is unchanged in this respect.

Whereas in Dancer1, template engines have the methods:

    $template_engine->view('foo.tt')
    $template_engine->view_exists('foo.tt')

In Dancer2, you should instead write:

    $template_engine->view_pathname('foo.tt')
    $template_engine->pathname_exists($full_path)

You may not need these unless you are writing a templating engine.

=head3 Serializers

You no longer need to implement the C<loaded> method. It is simply
unnecessary.

=head3 Sessions

Now the L<Simple|Dancer2::Session::Simple> session engine is turned on
by default, unless you specify a different one.

=head2 Configuration

=head3 C<public_dir>

You cannot set the public directory with C<setting> now. Instead you
will need to call C<config>:

    # before
    setting( 'public_dir', 'new_path/' );

    # after
    config->{'public_dir'} = 'new_path';

=head3 confdir

You cannot set the configuration directory (C<confdir>) with C<setting>
now. You can use an environment variable, however:



( run in 0.845 second using v1.01-cache-2.11-cpan-39bf76dae61 )