* Ovid <publiustemp-moduleautho...@yahoo.com> [2010-04-07 09:05]: > Presumably the format should try to determine the number of > conversions in the format and perhaps the alias could generate > a sub with a corresponding prototype like 'sub > throw_io_read($$)'. That might give you a touch of compile-time > safety. Haven't really thought too carefully about this, > though.
I think the best approach would be to tie String::Formatter into Exception::Class, specifically its `require_named_input` and `named_replace` options. To produce its message, an exception class would pass its declared fields as format inputs. Then resulting interface would look like this: use Exception::Class ( 'MyException', 'IOOpenRead' => { isa => 'MyException', alias => 'throw_io_open', fields => [ qw( file mode errno ) ], format => 'Cannot open %{file} for %{mode}ing: %{errno}', }, ); You’d use that like so: open my $fh, '<', $filename or throw_io_open file => $filename, mode => 'read', errno => $!; Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>