Are you suggesting postfix if should never be used?
Yes. Well, I have happily never used it for fifteen years. Conway made a convincing argument IMHO. In case you're interested, I would write your:
return encode_json(\%result) if lc($attrs{'format'}) eq 'json';
as:
lc($attrs{'format'}) eq 'json' and return encode_json(\%result);
... which is similar in style to the classic:
open(my $fh, '<', $file) or die "error opening '$file': $!";
with flow of control on the right. I guess my brain has got used to scanning the right of the screen for flow of control.

Curiously, the instant I glanced at your original code:

return encode_json(\%result) if lc($attrs{'format'}) eq 'json'; return $result{'message'} or "$result{'api-key'}:$result{'session'}";
my spidey sense went off. Ding! Ding! Ding! This reaction was pure instinct, far too quick to be based on any rational analysis. Every atom in my body screamed at me that this code is wrong! It was morning in Sydney Bod, so looking at your code woke me up nicely and got me going for the day. Thanks for that BTW. :)


In reply to Re^4: Useless use of string in return statement by eyepopslikeamosquito
in thread Useless use of string in return statement by Bod

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.