|Don't ask to ask, just ask|
I'm writing an XS interface to a library and could use some advice on how to return error information.
The routines in the library return 0 if the call succeeded or a status value if there was an error. The library contains a routine to convert the status codes into strings that can be displayed for a user.
My interface routines mostly collect the information into a hash and return a reference to the caller. In case of error I'm returning an empty list. I would like to make the error information available to the caller because it could be very meaningful in certain cases (e.g., 'end of file' vs. other I/O error conditions).
I can't really return the status in $! since it isn't an errno value. I can return the error text in $@ but then the programmer would have to parse the error text rather than acting on an error code.
I'm contemplating replacing my simple handle object with a structure that can contain the handle and the last status returned by a library call using that handle. I could then add an XS routine to return that status to the calling program. The user could call the status fetch routine if one of the other calls returned undef. But this still doesn't help the open call that creates the handle (if the handle doesn't exist yet, I can't use it to hold status).
In reply to Returning external library status codes from an XS routine by pfaut