Showing the current time using templates



examples/dancer/show_time_using_template/app.psgi
package App;
use Dancer2;
use DateTime;

get '/' => sub {
    my $dt = DateTime->now;
    return template 'page', {
        timestamp => $dt->strftime( '%Y-%m-%d %H:%M:%S' ),
    };
};

App->to_app;

examples/dancer/show_time_using_template/views/page.tt
<h1>Hello World!</h1>
[% timestamp %]

examples/dancer/show_time_using_template/test.t
use strict;
use warnings;

use Test::More;
use Plack::Test;
use Plack::Util;
use HTTP::Request::Common;

my $app = Plack::Util::load_psgi './app.psgi';

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

is $res->status_line, '200 OK', 'Status';
like $res->content, qr{<h1>Hello World!</h1>};
like $res->content, qr{\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d};

done_testing();