Thanks for the overload suggestion. I can see where I could use it, carefully of course, for autoincrementing or autodecrementing the current row.

I am, though, plowing ahead with a variation of what I suggested above. The My::DB::TIEHASH method tests for the need to load one row or many rows based on a few cases: if there's a "WHERE" clause defined in the parameter -where=>'active = 1' in the tie constructor (any "WHERE" existing assumes multiple rows), or if data passed in through -data has an array of hashes in it instead of a plain hash (many rows).

Right now, my sample code usage goes as follows:

... tie %th, 'My::DB::User', {-where=>'active=1'}; for (my $i=0; $i < $th{'_ROWCOUNT_'}; $i++) { $th{'_CURRENTROW_'} = $i; print "$th{'username'} has been an active member since $th{'create +d'}\n"; }

I do see a situation where overload could be useful, though. The whole for loop could be avoided by overloading ++ and -- to manipulate $th{'_CURRENTROW_'} like so:

... while ($th{'_CURRENTROW_'} < $th{'_ROWCOUNT_'}) { #do something, then: $th{'_CURRENTROW_'}++; }

I should look into this. I may not need to overload depending on how autoincrement acts on the tied hash already ; I need to test this. As far as my API is concerned, I think it's working out rather well in this case. I can see where it can become a ball of mud, but I'm fighting to keep it simple. Of course, I've not gotten into making the variant subclasses of My::DB for all the remaining tables yet....

(Ph) Phaysis (Shawn)
If idle hands are the tools of the devil, are idol tools the hands of god?


In reply to Re: Re: Tied hashes and arrays, yeah. But tied typeglobs? by Phaysis
in thread Tied hashes and arrays, yeah. But tied typeglobs? by Phaysis

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.