The main enhancements over the standard DBM Filter hooks are:
=over 4
=item *
A cleaner interface.
=item *
The ability to easily apply multiple filters to a single DBM file.
=item *
The ability to create "canned" filters. These allow commonly used filters
to be packaged into a stand-alone module.
=back
=head1 METHODS
This module will arrange for the following methods to be available via
the object returned from the C<tie> call.
=head2 $db->Filter_Push()
=head2 $db->Filter_Key_Push()
=head2 $db->Filter_Value_Push()
Add a filter to filter stack for the database, C<$db>. The three formats
vary only in whether they apply to the DBM key, the DBM value or both.
=over 5
=item Filter_Push
The filter is applied to I<both> keys and values.
=item Filter_Key_Push
The filter is applied to the key I<only>.
=item Filter_Value_Push
The filter is applied to the value I<only>.
=back
=head2 $db->Filter_Pop()
Removes the last filter that was applied to the DBM file associated with
C<$db>, if present.
=head2 $db->Filtered()
Returns TRUE if there are any filters applied to the DBM associated
with C<$db>. Otherwise returns FALSE.
=head1 Writing a Filter
Filters can be created in two main ways
=head2 Immediate Filters
An immediate filter allows you to specify the filter code to be used
at the point where the filter is applied to a dbm. In this mode the
Filter_*_Push methods expects to receive exactly two parameters.
my $db = tie %hash, 'SDBM_File', ...
$db->Filter_Push( Store => sub { },
Fetch => sub { });
The code reference associated with C<Store> will be called before any
key/value is written to the database and the code reference associated
with C<Fetch> will be called after any key/value is read from the
database.
For example, here is a sample filter that adds a trailing NULL character
to all strings before they are written to the DBM file, and removes the
trailing NULL when they are read from the DBM file
my $db = tie %hash, 'SDBM_File', ...
$db->Filter_Push( Store => sub { $_ .= "\x00" ; },
Fetch => sub { s/\x00$// ; });
Points to note:
=over 5
=item 1.
Both the Store and Fetch filters manipulate C<$_>.
=back
=4= |