Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 89691
Status: rejected
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: bpj [...] melroch.se
Cc:
AdminCc:

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



Subject: Types::Standard: please add StrLen (string with length) type
Date: Tue, 22 Oct 2013 12:41:56 +0200
To: bug-Type-Tiny [...] rt.cpan.org
From: BPJ <bpj [...] melroch.se>
First off, thanks for a great distribution! One thing I sorely miss in Types::Standard is a type for a string with length -- at first I thought Str required length > 0 because Params::Util::_STRING and Data::Util::is_string which I've used before check for non-zero length, and got bitten. I'm hardly the only one who needs to check for a non-zero-length string on a regular basis, so I think a StrLen (string with length) type would be in order, and ideally I'd not complain if it took optional parameters for min and max length but defaulted to length > 0; I guess one could achive this with StrMatch[ qr{ \A .{1,} \z }msx ] or the like, but with a less than intuitive error message I'm afraid. TIA, /bpj
Either of these should work: StrMatch[qr/./] Str&~Enum[""] There's also Types::XSD::Lite, which is in a separate CPAN distribution but allows options like maxLength and minLength, a la: use Types::XSD::Lite qw(String); String[ minLength => 1 ]
StrMatch works, even if it's not an especially attractive solution. Types::XSD and Types::XSD::Lite also have a String type constraint which accepts maximum and minimum lengths.