Skip Menu |

This queue is for tickets about the Function-Parameters CPAN distribution.

Report information
The Basics
Id: 123911
Status: open
Priority: 0/
Queue: Function-Parameters

People
Owner: Nobody in particular
Requestors: brianski [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Feature request: ability to check types with one sub call
Currently Function::Parameters calls type validation routines for each argument listed, eg per B::Deparse: sub doit : method { use warnings; use strict; BEGIN { $^H{'Function::Parameters/config'} = 'HASH(0x7f8ae731dee8)'; } Function::Parameters::_croak('Too few arguments for method doit (expected 3, got ' . @_ . ')') if @_ < 3; Function::Parameters::_croak('Too many arguments for method doit (expected 3, got ' . @_ . ')') if @_ > 3; my $self = shift(); my($times, $base_str) = @_; Function::Parameters::_croak('In method doit: parameter 1 ($times): ' . (\'Int')->get_message($times)) unless (\'Int')->check($times); Function::Parameters::_croak('In method doit: parameter 2 ($base_str): ' . (\'Str')->get_message($base_str)) unless (\'Str')->check($base_str); return $base_str x $times; } It'd be nice to have a way for a type checking library to specify a string which can be eval'd in to code at compile time, to avoid the overhead of calling the check sub on each argument. In other words, to generate code more like this: sub doit : method { use warnings; use strict; BEGIN { $^H{'Function::Parameters/config'} = 'HASH(0x7f8ae731dee8)'; } Function::Parameters::_croak('Too few arguments for method doit (expected 3, got ' . @_ . ')') if @_ < 3; Function::Parameters::_croak('Too many arguments for method doit (expected 3, got ' . @_ . ')') if @_ > 3; my $self = shift(); my($times, $base_str) = @_; Function::Parameters::_croak('In method doit: parameter 1 ($times): ' . (\'Int')->get_message($times)) unless (($_=$times)//1) && defined && /^-?\d+$/; Function::Parameters::_croak('In method doit: parameter 2 ($base_str): ' . (\'Str')->get_message($base_str)) unless (($_=$base_str)//1) && defined && !ref; return $base_str x $times; } Maybe ask the type-checking class to implement a check_str() routine for this?
Use `inline_check` method if that exists, falling back to `_inline_check` if that exists. This should give you inlining support for Type::Tiny, Specio, and MooseX::Types.