http://qs321.pair.com?node_id=749067


in reply to RFC: User subroutine hinting interface for autodie

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( \&copy, 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