[Maypole] Auto Increment Primary Keys (and Documentation)

Gordon Haverland ghaverla@materialisations.com
Thu, 27 Jan 2005 22:44:14 -0700


On Thursday 27 January 2005 04:53, Tony Bowden wrote:
> On Thu, Jan 27, 2005 at 10:57:44AM +0000, Dave Howorth wrote:
> >   my $brewery = Brewery->create({
> >   name => 'Anheuser Busch',
> >   })
> >
> >   my $beer = Beer->create({
> >   name    => 'Budweiser',
> >   brewery => $brewery,
> >   style   => 'lager',
> >   });
>
> Of course, in practice, you wouldn't do the second step like
> that. You'd use
>
>   my $beer = $brewery->add_to_beers({
>     name    => 'Budweiser',
>     style   => 'lager',
>   })
>
> But yes, you can just ask a newly created item for its
> auto-incremented id.

Hmmm, that looks like the kind of elegance that I think Maypole 
sites are supposed to have.  

$ grep 
add_to  /usr/local/src/.cpan/build/Maypole-2.08/lib/Maypole/Manual/*pod

Hmmm, no example of any add_to stuff in any of the PODs.  And I 
read ALL of the PODs just before Christmas as a "slight" 
editorial critique and submitted a patch to the documentation on 
stuff (minor stuff) I thought could get updated.

There are entirely too many large gaps in the documentation.  Just 
like this.  I've been working on this more or less steady for a 
month, and I am only just barely getting comfortable with writing 
anything beyond trivial and thinking that it might even work.

What am I working on in particular?  Well, I really don't want to 
see any sessions of my project get hijacked.  So, reading 
PerlMonks and other stuff, I happened across a comment by Randal 
Schwartz about "branding" a browser session.  So, I am putting 
the IP, user agent, sessionID, and a few other things, along with 
a HMAC_SHA1 digest of that data and a 160 bit random number into 
the values part of a cookie (session cookie).

So, one of those tables has the primary key, which is the session 
ID; and stores a copy of the bulk of the data I brand a browser 
with.  The other table is for all other parts of the session, and 
contains the session ID, access time and URL.

I do the write for the start of the session in the login process, 
and the checking for a valid session is attached to authenticate.  
But, I didn't know how to find the ID of that first record I 
wrote, short of searching the table for everything I just wrote.  
It seemed like some elegant solution should exist, but darned if 
I could find anything in Maypole, Class::DBI, .... etc 
documentation.

I think my project is getting better, but I am now on the 3rd 
rewrite of things because the code always gets so tangled up it 
is better to start anew, than try to fix what is there.  But it 
sure would be nice to get this to the point where people could 
start trying it out.  It hardly even limps in perldb/emacs.  :-(

Hopefully I'll be able to add a significant chunk of documentation 
now that Christmas has come and gone and the big chunk of 
Christmas changes seems to have been made.

Gord