Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I think you're asking writers of code you're calling to consider the code around it, which is code you're writing. Why don't you read the documentation for code you call and be prepared for it to return what it's documented to return? The code you write is your responsibility, not the responsibility of those providing properly documented libraries to you.

If you want to introduce a code shim around the library call that allows you to handle the undef differently and return something else, then feel free to do that. Don't try to call out the library's implementors as doing the wrong thing. They told you what their code does. You chose to call it. From there your code is your responsibility, not theirs.

Given the opportunity to write code that does it the same way as Sys::Info::OS or another way, choose either. Then document what your code returns and why. Then people can decide whether to use your code or not, and perhaps can blame you for their code doing the wrong thing after they ignore its documentation.

I just read the documentation for the module, and it doesn't promise that the name method returns a defined value nor does it clearly say it may return undef. I'm sure the author would appreciate a POD patch. Meanwhile, there are is_linux, is_bsd, is_windows, and is_unknown methods to test in a boolean manner for each of those. Have you tried those methods? Are you depending upon code you're unsure of working the way you're using it?

If you read the fairly simple code of Sys::Info::OS to understand what it does, you'd see it's checking against Sys::Info::Constants's OSID value for those boolean methods. In the name method, it's deferring to Sys::Info::Driver::Linux::OS in the case of Linux, which in turn defers in its private _populate_os_version method to Sys::Info::Driver::Linux::OS::Distribution. That module does a best guess by reading the conventional (and LSB-required) informational files in /etc and /proc to determine the system name, version, edition, and more. The synopsis of Sys::Info::Driver::Linux::OS::Distribution very clearly shows that its name method returns a false value if it can't determine the OS. The description clearly states which distributions it does currently support, and welcomes patches.

This document describes version C<0.7903> of C<Sys::Info::Driver::Linux::OS::Distribution> released on C<8 May 2013>. This is a simple module that tries to guess on what linux distribution we are running by looking for release's files in /etc. It now looks for 'lsb-release' first as that should be the most correct and adds ubuntu support. Secondly, it will look for the distro specific files. It currently recognizes slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet, gentoo, ubuntu and redflag. It has function to get the version for debian, suse, redhat, gentoo, slackware, redflag and ubuntu(lsb). People running unsupported distro's are greatly encouraged to submit patches.

Instead of complaining about the author who did all that work so you could use a single method not returning exactly what you think it should, why don't you either do the work yourself, handle the return value properly for what you're getting, or contribute to his project? Patches are "greatly encouraged" and I think you've volunteered to submit some quite well.


In reply to Re: A question about method return values and error checking by mr_mischief
in thread A question about method return values and error checking by wee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found