# very naughty!
coerce 'ArrayRef'
=> from Str
- => via { [ split /,/ ] };
+ => via { [ split /,/ ] };
Instead, create a subtype and coerce that:
coerce 'My::ArrayRef'
=> from 'Str'
- => via { [ split /,/ ] };
+ => via { [ split /,/ ] };
=head2 Do not coerce class names directly
# also very naughty!
coerce 'HTTP::Headers'
=> from 'HashRef'
- => via { HTTP::Headers->new( %{$_} ) };
+ => via { HTTP::Headers->new( %{$_} ) };
Instead, we can create an "empty" subtype for the coercion:
coerce 'My::HTTP::Headers'
=> from 'HashRef'
- => via { HTTP::Headers->new( %{$_} ) };
+ => via { HTTP::Headers->new( %{$_} ) };
=head2 Use coercion instead of unions