 |
|
| Computers Forum Index » Computer Languages (Perl - Modules) » feedback please: module to set $! to an arbitrary... |
|
Page 1 of 1 |
|
| Author |
Message |
| David Taylor... |
Posted: Tue Aug 04, 2009 1:33 pm |
|
|
|
Guest
|
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 $!
=head1 SYNOPSIS
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"
=head1 DESCRIPTION
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
C<errno>.
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.
=cut |
|
|
| Back to top |
|
|
|
| Christian Winter... |
Posted: Thu Aug 06, 2009 8:58 pm |
|
|
|
Guest
|
David Taylor wrote:
Quote: 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 ?
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:
void
ErrText(errtext)
char *errtext
CODE:
SV * dollarexcl = get_sv("!", 0);
if( NULL != dollarexcl ) {
sv_setpv(dollarexcl, errtext);
}
-Chris |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Tue Dec 01, 2009 10:22 am
|
|