The reason I'm here, though, is to ask: how would you design something like this (i.e., the first paragraph), and why?

:)

I'd perform some OOAD

You can't analyze design through the peephole that is your question; its too abstract?

A method that returns a String frog or Squirrel nuts

Sometimes a user may want just the String, but sometimes a user wants the nuts

Its almost as if its a good idea to return some kind of Object thats a string by default, but also an object you can ->chew cause its nuts

Sounds like a different kind of contextual return to me

As a case study on contextual return we can learn from the functional/methodial CGI's param , the classic demonstration that context sensitive return is too much cognitive load for the new and old alike, providing millions of pitfalls, and zero benefits

->non_idempotent_string

->non_idempotent_nuts

->non_idempotent_string_nuts

sub non_dempotent_string { my( $string, undef ) = shift->non_idempotent_string_nuts (@_); return $string; }

I think thats it, more methods .... is it?


In reply to Re: OO design: returning string and/or special value (peephole Object) by Anonymous Monk
in thread OO design: returning string and/or special value by wanna_code_perl

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.