1use strict; 2use warnings; 3 4use Test::More; 5 6BEGIN { 7 package Dancer2::Plugin::InsidePlugin; 8 9 use Dancer2::Plugin; 10 11 has inside => ( 12 is => 'ro', 13 lazy => 1, 14 default => sub { 15 my $app = shift; 16 return $app->plugin->config->{ja}; 17 }, 18 ); 19} 20 21BEGIN { 22 package Dancer2::Plugin::TestPlugin; 23 24 use Dancer2::Plugin; 25 26 has inside_plugin => ( 27 is => 'ro', 28 default => sub { 29 scalar $_[0]->app->with_plugin( 'InsidePlugin' ) 30 }, 31 handles => [ 'inside' ], 32 ); 33} 34 35{ 36 package MyApp; 37 38 use Dancer2; 39 40 use Dancer2::Plugin::TestPlugin; 41 42 set plugins => { 43 InsidePlugin => { 44 'ja' => 'da', 45 }, 46 TestPlugin => { 47 'nein' => 'ne', 48 } 49 }; 50} 51 52# check whether both plugins are registered 53my $app = MyApp::app(); 54my $plugins = $app->plugins; 55my $plugin_ct = scalar(@$plugins); 56 57ok ($plugin_ct == 2, 'Test number of plugins.') 58 || diag "Found $plugin_ct plugins instead of 2."; 59 60my $test_plugin = $app->with_plugin('TestPlugin'); 61my $inside_plugin = $test_plugin->inside_plugin; 62 63isa_ok( $test_plugin, 'Dancer2::Plugin::TestPlugin' ); 64isa_ok( $inside_plugin, 'Dancer2::Plugin::InsidePlugin' ); 65 66# test configuration values 67is $test_plugin->config->{nein} => 'ne', 'Test config of TestPlugin.' 68 or diag "Found instead of expected 'ne': ", $test_plugin->config->{nein}; 69 70is $inside_plugin->config->{ja} => 'da', 'Test config of InsidePlugin.' 71 or diag "Found instead of expected 'da': ", $inside_plugin->config->{ja}; 72 73done_testing; 74