[dancer-users] Unit testing plugins

Steve Dondley sdondley at gmail.com
Mon Nov 19 00:38:41 GMT 2018

Ive been messing around with figuring out how to unit test plugins. I came
up with something that works but that is very messy and hacky and so it
feels like I'm way off the beaten path. Can someone set me straight on
whether there is an easier way to peek into the inner data structures of a

Here's what I came up with to dump the contents of my plugin's "html_cache"

my $app = Dancer2::Core::App->new();
$app->plugins->[0]->menu_item( { title => 'blah' }, $app->add_route(
    method => 'get',
    regexp => '/test',
    code => sub { $app->template('index.tt', shift) } ));

my $req = Dancer2::Core::Request->new( env => {
        SERVER_NAME       => 'localhost',
        SERVER_PORT       => 8000,
  }  );
my $route = $app->routes->{get}->[0];
$req->{route} = $route;
$req->{cookies} = {  };
$app->{request} = $req;
print Dumper $app->plugins->[0]->html_cache;


Prometheus Labor Communications, Inc.

UnionConnect Phone App for Labor Unions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20181118/b8832939/attachment.html>

More information about the dancer-users mailing list