I like the subroutine idea for specifying hints. @_ could be the return values, and $_ aliased to $_[0]. Perhaps something like
autodie::hints->set_hints_for(
\&foo,
scalar => sub { ! $_ },
list => sub { ! @_ or @_ == 1 and ! defined },
);
autodie::hints->set_hints_for(
\©,
any => sub { ! $_ },
);
autodie::hints->set_hints_for(
'open',
any => sub { ! defined },
);
would work.
This makes it easy to define common behaviours and to compose them in an arbitrary way.
use autodie::hints qw/ DEFAULT_SCALAR DEFAULT_LIST /;
autodie::hints->set_hints_for(
\&foo,
scalar => DEFAULT_SCALAR,
list => DEFAULT_LIST,
);
use autodie::hints qw/ COND1 COND2 COND3 /;
autodie::hints->set_hints_for(
\&foo,
any => sub { &COND1 and &COND2 or &COND3 },
);
If access to e.g. the arguments to the function is needed (for e.g.
unlink) then that would have to be provided some other way, for instance via a localized global variable in
autodie::hints.
Just an idea ...
lodin
-
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.