<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Rob Kinyon wrote:
<blockquote
 cite="mid:70384420903050917j69e76d90h70c10035719dae9d@mail.gmail.com"
 type="cite">
  <pre wrap="">On Thu, Mar 5, 2009 at 12:07, David Ihnen <a class="moz-txt-link-rfc2396E" href="mailto:davidi@norchemlab.com">&lt;davidi@norchemlab.com&gt;</a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Nothing is actually a plugin that impliments the 'Nothing' design pattern -
that is - instead of returning null when referencing a row in an empty
resultset (particularly -&gt;single and -&gt;first, which I use many times when
NOT looping over results, hence resulting in undef dereference errors on
empty) it instead returns a magical 'Nothing' object which has
characteristics like - (-&gt;is_nothing === 1, -&gt;id === 0, @list = $rs-&gt;method
=== (), $row = $rs-&gt;method === bless({}, Nothing).  The result - no need to
if-then on empty resultsets when grabbing data.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
So, the following are different:
    my $x = $rs-&gt;method;
    my ($y) = $rs-&gt;method;

That's sucky.
  </pre>
</blockquote>
interesting point.  If I had the Want module, I could easily return
nothings if you have a specified number expected (1 in this case), or
empty list if you expect infinite - since ($y) = $rs-&gt;method is
different contextually than @y = $rs-&gt;method - which would make that
not sucky.<br>
<blockquote
 cite="mid:70384420903050917j69e76d90h70c10035719dae9d@mail.gmail.com"
 type="cite">
  <blockquote type="cite">
    <pre wrap="">I wanted to use the Want module to change the return considering the context
called in, but that module is, sadly, not compatible with mod_perl.  If it
was, I could give back undefined, blessed ref, array ref, or hash ref
depending on its context, which would be cool.  Dang segfaults...
    </pre>
  </blockquote>
  <pre wrap="">Context-awareness, while cool, is kinda like operator overloading and
monkeypatching.</pre>
</blockquote>
Yes, it is. <br>
<blockquote
 cite="mid:70384420903050917j69e76d90h70c10035719dae9d@mail.gmail.com"
 type="cite">
  <pre wrap=""> It's something you should have in that section of your
toolbox that has the "Write 500 words as to why you should be allowed
to use me" essay requirement.
  </pre>
</blockquote>
Well, in this case in order to cleanly express 'Nothing', which has
different meanings in different contexts, I need to be able to detect
that context so that I can be different for those contexts.  Within the
limits of this particular design pattern, I think it is justifiable.  
So though it is a bit sucky and constrains the implimentation patterns
(my $y = $rs-&gt;method SHOULD be equal to my ($y) = $rs-&gt;method),
but in my case the former is what you want) without the Want module...
I think that the pattern has good benefits in being able to cut down on
the if-then hooey.  How I hate if-then/tertiaries/logical
operators/other repetitive code just to see if there's something there
to operate on.<br>
<br>
At least with AUTOLOAD handling miscellaneous calls, I don't have to
create special nothing hard-types one-to-parent-class as I would in
Java/C++ that behave appropriately.  A nothing row that returns a
nothing date-object, etc.<br>
<br>
David<br>
<br>
<br>
</body>
</html>