Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/Dancer2/Core/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,15 @@ sub _get_config_for_engine {
defined $config->{'engines'} && defined $config->{'engines'}{$engine}
or return {};

# try both camelized name and regular name
# try name, camelized name and fully-qualified name (without plus)
my $full_name = $name;
my $was_fully_qualified = ( $full_name =~ s/^\+// ); # strip any leading '+'
my $engine_config = {};
foreach my $engine_name ( $name, Dancer2::Core::camelize($name) ) {
foreach my $engine_name (
$name,
Dancer2::Core::camelize($name),
( $was_fully_qualified ? $full_name : () )
) {
if ( defined $config->{'engines'}{$engine}{$engine_name} ) {
$engine_config = $config->{'engines'}{$engine}{$engine_name};
last;
Expand Down
3 changes: 2 additions & 1 deletion lib/Dancer2/Core/Factory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ sub create {

$type = Dancer2::Core::camelize($type);
$name = Dancer2::Core::camelize($name);
my $component_class = "Dancer2::${type}::${name}";
my $was_fully_qualified = ( $name =~ s/^\+// ); # strip any leading '+'
my $component_class = ( $was_fully_qualified ) ? $name : "Dancer2::${type}::${name}";

eval { use_module($component_class); 1; }
or croak "Unable to load class for $type component $name: $@";
Expand Down
9 changes: 8 additions & 1 deletion t/app.t
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,23 @@ is_deeply(
'Empty configuration for nonexistent engine',
);

# TODO: not such an intelligent check, this one...
# TODO: not such an intelligent check, these ones...
# set configuration for an engine
$app->config->{'engines'}{'template'}{'Tiny'}{'hello'} = 'world';
$app->config->{'engines'}{'template'}{'Some::Other::Template::Namespace'}{'hello'} = 'world';

is_deeply(
$app->_get_config_for_engine( template => 'Tiny', $app->config ),
{ hello => 'world' },
'_get_config_for_engine can find the right configuration',
);

is_deeply(
$app->_get_config_for_engine( template => '+Some::Other::Template::Namespace', $app->config ),
{ hello => 'world' },
'_get_config_for_engine can find the right configuration',
);

is(
File::Spec->canonpath( $app->caller ),
File::Spec->catfile(t => 'app.t'),
Expand Down
16 changes: 10 additions & 6 deletions t/classes/Dancer2-Core-Factory/new.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use strict;
use warnings;
use Test::More tests => 5;
use Test::More tests => 7;

use_ok('Dancer2::Core::Factory');

my $factory = Dancer2::Core::Factory->new;
isa_ok( $factory, 'Dancer2::Core::Factory' );
can_ok( $factory, 'create' );

my $template = Dancer2::Core::Factory->create(
'template', 'template_toolkit', layout => 'mylayout'
);
for my $class ('template_toolkit', '+Dancer2::Template::TemplateToolkit') {

my $template = Dancer2::Core::Factory->create(
'template', $class, layout => 'mylayout'
);

isa_ok( $template, 'Dancer2::Template::TemplateToolkit' );
is( $template->{'layout'}, 'mylayout', 'Correct layout set in the template' );
}

isa_ok( $template, 'Dancer2::Template::TemplateToolkit' );
is( $template->{'layout'}, 'mylayout', 'Correct layout set in the template' );