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
would work.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 }, );
This makes it easy to define common behaviours and to compose them in an arbitrary way.
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.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 }, );
Just an idea ...
lodin
|
---|
In Section
Meditations