<div dir="ltr"><div dir="ltr">OK, I think I found a decent solution. I turned the app into an object that I can pass to the the full qualified name of plugin's method.<div><br></div><div><span style="color:rgb(0,0,0);font-family:monospace;font-size:medium;white-space:pre-wrap">package TestApp;
use Dancer2;
use Dancer2::Plugin::Menu;
use Data::Dumper qw 'Dumper';
get '/' => sub { return 'hello' };
get '/test' => sub { return 'hi' };
sub new {
my $class = __PACKAGE__;
return bless {}, $class;
}
my $app = new();
Dancer2::Plugin::Menu::_do_stuff($app);</span><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 9, 2018 at 10:29 AM Steve Dondley <<a href="mailto:sdondley@gmail.com">sdondley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">I'm trying to test the internal methods of a plugin in the context of a running test app. The following doesn't work but should give you an idea of what I want to accomplish:<div><br></div><div><div><font face="monospace, monospace">use Plack::Test;</font></div><div><font face="monospace, monospace">use HTTP::Request::Common;</font></div><div><font face="monospace, monospace">{ package TestApp;</font></div><div><font face="monospace, monospace"> use Dancer2;</font></div><div><font face="monospace, monospace"> use Dancer2::Plugin::Menu;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> get '/' => sub { return template 'index' };</font></div><div><font face="monospace, monospace"> get '/test' => sub {</font></div><div><font face="monospace, monospace"> template '<a href="http://index.tt" target="_blank">index.tt</a>', {</font></div><div><font face="monospace, monospace"> html => 'hi',</font></div><div><font face="monospace, monospace"> },</font></div><div><font face="monospace, monospace"> };</font></div><div><font face="monospace, monospace"> build_menu;</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">my $test = Plack::Test->create( TestApp->to_app );</font></div><div><font face="monospace, monospace">my $res;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">my $menu = Dancer2::Plugin::Menu->new(app => $test);</font></div><div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"># test the return value of plugin method</font></div><div><font face="monospace, monospace">my $result = $menu->_convert_routes_to_array;</font></div></div><div><br></div><div><div><font face="monospace, monospace">cmp_deeply($result, [ '/', '/test' ], 'returns array of menu paths');</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">Is there a way to do this?</font></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_4795385689161425993gmail-m_366670175584462381gmail_signature"><div dir="ltr"><div>Prometheus Labor Communications, Inc.<br><a href="http://prometheuslabor.com" target="_blank">http://prometheuslabor.com</a><br>413-572-1300<br><br>UnionConnect Phone App for Labor Unions<br><a href="http://unionconnect.com" target="_blank">http://unionconnect.com</a></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Prometheus Labor Communications, Inc.<br><a href="http://prometheuslabor.com" target="_blank">http://prometheuslabor.com</a><br>413-572-1300<br><br>UnionConnect Phone App for Labor Unions<br><a href="http://unionconnect.com" target="_blank">http://unionconnect.com</a></div></div></div>