ANNOUNCE: Tie::SentientHash -- first public release 
Author Message
 ANNOUNCE: Tie::SentientHash -- first public release

The first public release of Tie::SentientHash can be downloaded from


The man page is appended below.

I have been using this module on my own projects for a while now but
it should still be regarded as beta quality software.  Any comments or
bug reports would be very welcome.

Andrew Ford,  Director       Ford & Mason Ltd           +44 1531 829900 (tel)

http://www.*-*-*.com/  Compton Green, Redmarley   +44 385 258278 (mobile)
http://www.*-*-*.com/      Gloucester, GL19 3JB, UK  

       Tie::SentientHash - Perl module implementing intelligent

         use Tie::SentientHash;

         $hashref = new Tie::SentientHash $meta_data, $initial_data;
         $untiedhash = $hashref->export;
         $metadata   = $hashref->_metadata;

         $hashref->{key} = 'value';
         $hashref->{key1}{key2} = $value;
         $value2 = $hashref->{key};
         undef $hashref;

       The Tie::SentientHash package provides intelligent
       objects.  The objects are represented as hashes which:

       *    provide read-only elements

       *    provide 'special' elements that are handled by user-
            supplied functions

       *    disallow changes to the data as specified by metadata

       *    track changes and call a 'commit changes' function
            when the object is destroyed

       References to scalars, arrays and hashes can be stored in
       hash elements in which case the referenced object is tied
       to an internal class of the appropriate type
       (Tie::SentientHash::NestedHash, ::NestedArray or
       ::NestedScalar), so that changes to the nested data
       structures can be tracked.

       The constructor is invoked with two hash references: the
       first contains metadata and the second the initial data
       values.  The metadata hash may contain the following

           a list of hash entries that are read-only (read-only
           elements cannot be modified -- except by special
           element handlers -- or deleted and are not deleted
           when the CLEAR method is called)

           a hash of name/subroutine-refs pairs that specifies
           elements that are handled specially (special elements
           also cannot be deleted).  The user function is called
           both for STORE (with four arguments) and for FETCH
           (with three arguments).  The arguments are: a
           reference to the metadata hash, a reference to the
           data hash, the element key and if the funtion is being
           called for a STORE operation, the value to be stored.
           SPECIAL elements can be used to implement calculated

           flag to indicate that the class should keep track of
           the keys of modified (top-level) hash elements

           a reference to a subroutine to commit changes (called
           with a reference to the data hash and a reference to
           the metadata hash)

           forbid inserts into hash and sub-hashes/arrays

           forbid deletes from hash

           forbid any changes

       Trying to change an object in a way that is forbidden by
       the metadata will cause the module to croak.

       Changes are only tracked at the top level.

       I use Tie::SentientHash as the basis for implementing
       persistent objects in my CGI/mod_perl scripts.  The
       details of reading and writing the objects from and to the
       database is handled by a class, but neither the class nor
       the high level code needs to keep track of whether the
       object has been changed in any way.

       For example if you had a pay per view system of some kind
       you could have a script that contained the following

          sub pay_per_view ($$) {

            my $cust = load Customer $cust_id;
            $cust->{CREDIT} -= $cost;

       The customer object would be implemented in a module
       sketched out below.  A commit function is specified on the
       call to create a new sentient object, and that function
       will be called when $cust goes out of scope at the end of
       the pay_per_view function and can write the modified
       object back to the database.  If none of the attributes
       had been modified then the commit function would not be

          package Customer;

          sub load ($$) {

            my $data = {};

            # read customer data from a database into $data

            my $meta = { COMMIT_SUB     => \&_commit,
                         READONLY       => [ qw( CUST_ID ) ],
                         FORBID_INSERTS => 1 };

            return bless new Tie::SentientHash($meta, $data), $class;

          sub _commit ($$) {

            # As we have been called, something has changed.  The names of
            # the modified fields are the keys of $meta->{MODIFIED}.  We had
            # better write the data back out to the database.


       Full array semantics are only supported for Perl version


See Also

       Copyright 1999 Ford & Mason Ltd. All rights reserved.

       This library is free software; you can redistribute it
       and/or modify it under the same terms as Perl itself.

Tue, 04 Dec 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. ANNOUNCE: VMS::Process 1.03 (First public release)

2. ANNOUNCE: VMS::System 1.03 (First public release)

3. ANNOUNCE: Devel::StackTrace 0.7 (first public release)

4. ANNOUNCE: Exception::Class 0.6 (first public release)

5. ANNOUNCE: Tie::SentientHash 0.54

6. Envy 2.06 (first public release)

7. HTML::Subtext 1.03 (first public release)

8. HTML::Stream 1.19 (first public release) available on the CPAN

9. Tie::SentientHash 0.53

10. ANNOUNCE - Tie::RangeHash v0.60 released

11. ANNOUNCE: Tie::Scalar::Transactional 0.01 Released

12. ANNOUNCE: Tie::RangeHash v0.42 released


Powered by phpBB® Forum Software