Skip Menu |

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

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

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

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



Subject: Auto-reporting?
When using Types::Standard for CSV validation, I could add this to the Text::CSV_XS docs: --8<--- This hook can be used for validation: X<data_validation> =over 2 =item FAIL Die if any of the records does not validate a rule: after_parse => sub { $_[1][4] =~ m/^[0-9]{4}\s?[A-Z]{2}$/ or die "5th field does not have a valid Dutch zipcode"; } =item DEFAULT Replace invalid fields with a default value: after_parse => sub { $_[1][2] =~ m/^\d+$/ or $_[1][2] = 0 } =item SKIP Skip records that have invalid fields (only applies to L</getline_all>): after_parse => sub { $_[1][0] =~ m/^\d+$/ or return \"skip"; } =back One could also use modules like L<Types::Standard>: use Types::Standard -types; my $row_type = Tuple [ Str, Str, Int, Bool, Optional[Num] ]; my $row_check = $row_type->compiled_check; while (my $row = $csv->get_line ($fh)) { $row_check->($row) or die $row_type->get_message ($row); } or after_parse => sub { $row_check->($_[1]) } -->8--- In that last call, it would be easier to have automatic diagnostics --8<--- my $row_check = $row_type->compiled_check (auto_diag => 1); -->8--- or some variation of that
The type object overloads &{} to do precisely that. my $row_check = \&{ $row_type };
I think the coderef overload already does this, so rejecting.