feedback please: module to set $! to an arbitrary string

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm proposing to upload a module to allow people to put arbitrary
strings in $!, without breaking $!'s normal errno catching behaviour.
I couldn't find an existing module to do that, pointers welcome.

I've written it, it seems to work (I still need to write proper tests
and make sure it plays nicely with %! and so on) but I'm not totally
happy with the name, any suggestions ?

First draft of the POD:

=head1 NAME

Errno::AnyString - put arbitrary strings in $!


  use Errno::AnyString;

  $! = [1234, "my hovercraft is full of eels"];
  my $n = 0 + $!; # $n now contains 1234
  my $s = "$!";   # $s now contains "my hovercraft is full of eels"

  open my $fh, "<", "/no/such/file";
  $n = 0 + $!; # $n now contains the numeric error code for ENOENT
  $s = "$!";   # $s now contains "no such file or directory"


C<Errno::AnyString> allows you to place an arbitrary error message and
numeric error code in the special C<$!> variable, without disrupting C<
$!>'s ability to pick up the result of the next system call that sets

It is useful if you are writing code that reports errors by setting C<
$!>, and none of the standard system error messages fit.

If C<Errno::AnyString> is loaded, C<$!> behaves as normal unless a
reference to a 2-element array is assigned to it, in which case the
elements of the array set the numeric error code and the error string.
The next operation that sets C<errno> will replace these values, just
like when you've assigned a number to C<$!> without
C<Errno::AnyString> loaded.

Internally, it works by replacing C<$!>'s symbol table entry with a
tied scalar that holds a reference to the real magical C<$!> scalar.


Re: feedback please: module to set $! to an arbitrary string

David Taylor wrote:
Quoted text here. Click to load it

Errno::AssignDual comes to my mind, or Errno::SetText.

I can see why assigning a listref to $! is intriguing, yet I'd also
like a way to only assign the text portion of $! and leave the numeric
portion untouch, even if that doesn't read as nice.
Some quick'n'dirty XS code:

        char *errtext
        SV * dollarexcl = get_sv("!", 0);
        if( NULL != dollarexcl ) {
            sv_setpv(dollarexcl, errtext);


Site Timeline