Dancer2-Plugin-ParamTypes
view release on metacpan or search on metacpan
lib/Dancer2/Plugin/ParamTypes.pm view on Meta::CPAN
'default' => sub { +{} },
);
has 'type_actions' => (
'is' => 'ro',
'builder' => '_build_type_actions',
);
sub _build_type_actions {
my $self = shift;
Scalar::Util::weaken( my $plugin = $self );
return {
'error' => sub {
my ( $self, $details ) = @_;
my ( $type, $name ) = @{$details}{qw<type name>};
$plugin->dsl->send_error(
"Parameter $name must be $type",
HTTP_BAD_REQUEST(),
);
},
lib/Dancer2/Plugin/ParamTypes.pm view on Meta::CPAN
$params_to_check{$src}{$name} = {
'optional' => $is_optional,
'source' => $src,
'name' => $name,
'type' => $type,
'action' => $action,
};
}
# Couldn't prove yet that this is required, but it makes sense to me
Scalar::Util::weaken( my $plugin = $self );
return sub {
my @route_args = @_;
# Hash::MultiValue has "each" method which we could use to
# traverse it in the opposite direction (for each parameter sent
# we find the appropriate value and check it), but that could
# possibly introduce an attack vector of sending a lot of
# parameters to force longer loops. For now, the loop is based
# on how many parameters to added to be checked, which is a known
( run in 1.404 second using v1.01-cache-2.11-cpan-39bf76dae61 )