Hmm, yeah, sounds like an interesting use case.
You might not even need Type::Params. The Tuple type from Types::Standard might be sufficient. Something like:
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);
}
If you've got Type::Tiny::XS installed, and your row specification is simple enough, you might even find that $row_type was able to generate $row_check as an xsub. (Off the top of my head, I don't think the one in the example is, as I don't think Optional is implemented in XS yet.)
If you end up with something cool, I would love to see and maybe incorporate it or something like it into the documentation.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|