First, check out the docs to Tie::GHash at
http://www.cpan.org/CPAN/authors/id/L/LB/LBROCARD/Tie-GHash-0.10.readme

The story behind this module is interesting. This module was created
during Brian Ingerson's Inline talk at YAPC::NorthAmerica 2001 when he
asked me to code something fun using Inline, so blame him for this.

To be fair, I'd been thinking about the idea for this module for a
while. Perl hashes take up a lot of memory, and occasionally you'd
like to have huge hashes in memory (for Markov chains, say).

I had been aware that there were various different hash libraries
around, so I picked a random one which was likely to be installed on a
computer: the GNOME glib's ghash library. I checked out the API at
http://developer.gnome.org/doc/API/glib/glib-hash-tables.html docs and
it seemed fairly easy to use. I found an article at
http://www-106.ibm.com/developerworks/library/glib2.html explaining
the rest of the details, and everything looked sweet.

Now I needed to code up a basic Inline module (using the new
Inline::MakeMaker module).  I did a simple h2xs incantation, changed
the Makefile.PL to use Inline::MakeMaker and WriteInlineMakefile, set
up a module as documented in Inline.pod, and then read the Inline::C
cookbook to learn "How can I use Inline to make use of some shared
library?".

While I could have provided an object-oriented version to these
hashes, it was far better to make the hashes look just like Perl
internal hashes.  This can be acheived by tie-ing the hash - see the
perltie documentation.  Basically, all you need to do is set up
various functions such as TIEHASH, STORE, FETCH, etc. What's cute is
that with Inline I simply code these functions in C (there is a little
wrapping of the glib hash functions, but only a little).

Being a good little extreme programmer, I had already written a test
suite. With 511 tests. I built the module. It all worked. I worried.

This was now halfway through Brian's talk and there was a break, so I
showed him the code. He ooooh-ed and aaaaah-ed. I spent the rest of
his talk cleaning it up, writing documentation, improving the tests,
writing some benchmarks, writing to [EMAIL PROTECTED] about the name,
building the distribution, etc. I managed to upload it to CPAN just as
Brian was finishing his talk.

So there you go. One of the first modules on CPAN that uses Inline. So
who's next? ;-)

Leon
-- 
Leon Brocard.............................http://www.astray.com/
Iterative Software...........http://www.iterative-software.com/

... And now for something completely different...

Reply via email to