Skip to content

Commit

Permalink
Die when setting multiple fields with multiple plugin_keyword values
Browse files Browse the repository at this point in the history
  • Loading branch information
nfg committed Dec 5, 2016
1 parent 48e056d commit 3344b59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 11 additions & 4 deletions lib/Dancer2/Plugin.pm
Expand Up @@ -342,8 +342,17 @@ sub _exporter_plugin {
our \@EXPORT = ( ':app' );
around has => sub {
my( \$orig, \$name, \@args ) = \@_;
\$orig->( ${caller}->_p2_has( \$_, \@args) )
my( \$orig, \$name, \%args ) = \@_;
if (ref \$name eq 'ARRAY'
&& exists \$args{'plugin_keyword'}
&& ref \$args{'plugin_keyword'} eq 'ARRAY') {
Carp::croak('Setting "plugin_keyword" to an array is disallowed'
. ' when defining multiple attributes simultaneously');
}
\$orig->( ${caller}->_p2_has( \$_, \%args) )
for ref \$name ? @\$name : \$name;
};
Expand Down Expand Up @@ -818,8 +827,6 @@ You can also turn an attribute of the plugin into a keyword.
plugin_keyword => [ 'baz', 'bazz' ], # keywords will be 'baz' and 'bazz'
);
=head3 Accessing the plugin configuration
The plugin configuration is available via the C<config()> method.
Expand Down
14 changes: 13 additions & 1 deletion t/plugin2/from-config.t
@@ -1,7 +1,7 @@
use strict;
use warnings;

use Test::More tests => 7;
use Test::More tests => 8;

{
package Dancer2::Plugin::FromConfig;
Expand Down Expand Up @@ -43,6 +43,15 @@ has [qw(seven eight)] => (
plugin_keyword => 1,
);

eval {
has [qw(nine ten)] => (
is => 'ro',
from_config => 1,
plugin_keyword => ['nine', 'ten'],
);
};
our $plugin_keyword_exception = $@;

plugin_keywords qw/ one three four five /;

}
Expand Down Expand Up @@ -74,6 +83,9 @@ plugin_keywords qw/ one three four five /;
Test::More::is six() => 'AH!', 'from_config a coderef, no override';
Test::More::is seven() => 'sept', 'from_config, defined two fields at once #1';
Test::More::is eight() => 'huit', 'from_config, defined two fields at once #2';
Test::More::ok $Dancer2::Plugin::FromConfig::plugin_keyword_exception,
"defining two fields simultaneously with multiple plugin_keyword values"
. " is disallowed";
}


Expand Down

0 comments on commit 3344b59

Please sign in to comment.