X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalystX%2FDynamicComponent.pm;fp=lib%2FCatalystX%2FDynamicComponent.pm;h=a8e489cd3e2e193f8c3a41902ff41e8d9c52b376;hb=72b522424833b0e7ecf67dda4e307396cd0f25ce;hp=cb35da4d3c7e69d49c67e2a319a6c9db22cc9a21;hpb=d0fd9aa10ab432172cfc59154b6cbae8b7307fd8;p=catagits%2FCatalystX-DynamicComponent.git diff --git a/lib/CatalystX/DynamicComponent.pm b/lib/CatalystX/DynamicComponent.pm index cb35da4..a8e489c 100644 --- a/lib/CatalystX/DynamicComponent.pm +++ b/lib/CatalystX/DynamicComponent.pm @@ -4,6 +4,7 @@ use MooseX::Types::Moose qw/Str CodeRef HashRef ArrayRef/; use Catalyst::Utils; use Moose::Util::TypeConstraints; use List::MoreUtils qw/uniq/; +use Moose::Autobox; use namespace::autoclean; enum __PACKAGE__ . '::ResolveStrategy' => qw/ @@ -23,6 +24,9 @@ parameter 'pre_immutable_hook' => ( predicate => 'has_pre_immutable_hook', ); +my $coerceablearray = subtype ArrayRef; +coerce $coerceablearray, from Str, via { [ $_ ] }; + my %parameters = ( methods => { isa =>HashRef, @@ -30,12 +34,12 @@ my %parameters = ( resolve_strategy => 'merge', }, roles => { - isa => ArrayRef, + isa => $coerceablearray, coerce => 1, default => sub { [] }, resolve_strategy => 'merge', }, superclasses => { - isa => ArrayRef, + isa => $coerceablearray, coerce => 1, default => sub { [] }, resolve_strategy => 'replace', }, @@ -55,9 +59,15 @@ foreach my $name (keys %parameters) { # Code refs to implement the strategy types my %strategies = ( # Right hand precedence where appropriate - replace => sub { $_[1] ? $_[1] : $_[0]; }, + replace => sub { + $_[0] = [ $_[0] ] if $_[0] && !ref $_[0]; + $_[1] = [ $_[1] ] if $_[1] && !ref $_[1]; + $_[1] ? $_[1] : $_[0]; + }, merge => sub { - if (ref($_[0]) eq 'ARRAY') { + $_[0] = [ $_[0] ] if $_[0] && !ref $_[0]; + $_[1] = [ $_[1] ] if $_[1] && !ref $_[1]; + if (ref($_[0]) eq 'ARRAY' || ref($_[1]) eq 'ARRAY') { [ uniq( @{ $_[0] }, @{ $_[1] } ) ]; } else {