note
radiantmatrix
<p>This is kind of cool, but I've been severely bitten by source filters in the past, and continue to have a number of personal stylistic issues with using them. What I'd like to see (and if someone knows of a CPAN module that does this, I'd be grateful) is something that would allow subs to be written thusly:
<code>
use Verifier;
my $verify = new Verifier (on_failure => sub { die(join (',',@_)) })
sub foobar {
## The '-' in front of hashref means $bar is an optional paramater
my ($foo, $bar) = $verify->type ( \@_, qw/scalar -hashref/);
print "Using $foo:\n";
return $foo unless %$bar;
for (keys %$bar) { print "$_ => $$bar{$_}\n" }
return $$bar{'result'};
}
</code>
<p>That is, I'd really like to see verification of parameter types handled by a verifier object rather than by a source filter. Yes, I know it's not quite the same thing; but by eval'ing the type verifier call, one could achieve the same basic functionality.
<p><b>Update:</b> It turns out, thanks to a mention by [dragonchild] and [xdg], that [cpan://Params::Validate] does just the above. An example of the above code, but using that CPAN module, can be found [id://412703|a bit further down] in this discussion.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-375088">
<p align=right>
<font color='#0000d8'>r</font><font color='#0000b1'>a</font><font color='#00008a'>d</font><font color='#000063'>i</font><font color='#00003c'>a</font><font color='#000015'>n</font><font color='#000000'>t</font><font color='#000039'>m</font><font color='#000060'>a</font><font color='#000087'>t</font><font color='#0000ae'>r</font><font color='#0000d5'>i</font><font color='#0000fc'>x</font><font color='#000024'>
</font><br />
<tt><small>require <a href="?node_id=375088#disclaimer">General::Disclaimer</a>;<br />
s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}</small></tt>
</p>
</div></div>
412554
412554