Funny, I'm coding a schema validator too at the moment and returning hash (more precisely, hashref) like {success=>1, data=>..., ...} is also my preferred way.

Compared to the ($success, $res) tuple, hash gives you more flexibility as you can add more keys laters should you need one.

I'm too lazy creating "result objects" and I think it's an overkill anyway. Oftentimes you just want to give the user an error code and the output without much behaviour at all, so object is not particularly necessary here.

Exception is actually very handy, but I often deal with cross-language, cross-computer communication and convention about remote exception is not that well defined (at least in Perl?). Also I've always had this feeling that Perl5 is not really "exception-based". I'd wait for Perl6 for that, but that's just me of course.

A simple data structure like hash, on the other hand, is supported by virtually any decent programming language (even bash nowadays, I've heard).

There's another style which you could try:

$success = validate($data, $output);

$output is an optional argument which if given will be filled with the output by validate(). Sometimes you don't need the output at all and just need the fail/success boolean status.


In reply to Re: How to return an appropriate error from module? by Anonymous Monk
in thread How to return an appropriate error from module? by zrajm

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.