summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/DBM_Filter
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2010-05-12 16:54:37 +0000
committerNorbert Preining <preining@logic.at>2010-05-12 16:54:37 +0000
commit661c41a09e39a182865e0b51e34cc995a0dc96e8 (patch)
tree2f79bb1406e22fdcb2587be8ffda6c0c609d7932 /Master/tlpkg/tlperl/lib/DBM_Filter
parentb645030efc22e13c2498a1522083634ab91b2de1 (diff)
move tlperl.straw to tlperl
git-svn-id: svn://tug.org/texlive/trunk@18210 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/DBM_Filter')
-rwxr-xr-xMaster/tlpkg/tlperl/lib/DBM_Filter/compress.pm53
-rwxr-xr-xMaster/tlpkg/tlperl/lib/DBM_Filter/encode.pm86
-rwxr-xr-xMaster/tlpkg/tlperl/lib/DBM_Filter/int32.pm50
-rwxr-xr-xMaster/tlpkg/tlperl/lib/DBM_Filter/null.pm52
-rwxr-xr-xMaster/tlpkg/tlperl/lib/DBM_Filter/utf8.pm51
5 files changed, 292 insertions, 0 deletions
diff --git a/Master/tlpkg/tlperl/lib/DBM_Filter/compress.pm b/Master/tlpkg/tlperl/lib/DBM_Filter/compress.pm
new file mode 100755
index 00000000000..b9f7dea92bf
--- /dev/null
+++ b/Master/tlpkg/tlperl/lib/DBM_Filter/compress.pm
@@ -0,0 +1,53 @@
+package DBM_Filter::compress ;
+
+use strict;
+use warnings;
+use Carp;
+
+our $VERSION = '0.02';
+
+BEGIN
+{
+ eval { require Compress::Zlib; Compress::Zlib->import() };
+
+ croak "Compress::Zlib module not found.\n"
+ if $@;
+}
+
+
+
+sub Store { $_ = compress($_) }
+sub Fetch { $_ = uncompress($_) }
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBM_Filter::compress - filter for DBM_Filter
+
+=head1 SYNOPSIS
+
+ use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File
+ use DBM_Filter ;
+
+ $db = tie %hash, ...
+ $db->Filter_Push('compress');
+
+=head1 DESCRIPTION
+
+This DBM filter will compress all data before it is written to the database
+and uncompressed it on reading.
+
+A fatal error will be thrown if the Compress::Zlib module is not
+available.
+
+=head1 SEE ALSO
+
+L<DBM_Filter>, L<perldbmfilter>, L<Compress::Zlib>
+
+=head1 AUTHOR
+
+Paul Marquess pmqs@cpan.org
+
diff --git a/Master/tlpkg/tlperl/lib/DBM_Filter/encode.pm b/Master/tlpkg/tlperl/lib/DBM_Filter/encode.pm
new file mode 100755
index 00000000000..fedb6928116
--- /dev/null
+++ b/Master/tlpkg/tlperl/lib/DBM_Filter/encode.pm
@@ -0,0 +1,86 @@
+package DBM_Filter::encode ;
+
+use strict;
+use warnings;
+use Carp;
+
+our $VERSION = '0.02';
+
+BEGIN
+{
+ eval { require Encode; };
+
+ croak "Encode module not found.\n"
+ if $@;
+}
+
+
+sub Filter
+{
+ my $encoding_name = shift || "utf8";
+
+ my $encoding = Encode::find_encoding($encoding_name) ;
+
+ croak "Encoding '$encoding_name' is not available"
+ unless $encoding;
+
+ return {
+ Store => sub {
+ $_ = $encoding->encode($_)
+ if defined $_ ;
+ },
+ Fetch => sub {
+ $_ = $encoding->decode($_)
+ if defined $_ ;
+ }
+ } ;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBM_Filter::encode - filter for DBM_Filter
+
+=head1 SYNOPSIS
+
+ use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File
+ use DBM_Filter ;
+
+ $db = tie %hash, ...
+ $db->Filter_Push('encode' => 'iso-8859-16');
+
+=head1 DESCRIPTION
+
+This DBM filter allows you to choose the character encoding will be
+store in the DBM file. The usage is
+
+ $db->Filter_Push('encode' => ENCODING);
+
+where "ENCODING" must be a valid encoding name that the Encode module
+recognises.
+
+A fatal error will be thrown if:
+
+=over 5
+
+=item 1
+
+The Encode module is not available.
+
+=item 2
+
+The encoding requested is not supported by the Encode module.
+
+=back
+
+=head1 SEE ALSO
+
+L<DBM_Filter>, L<perldbmfilter>, L<Encode>
+
+=head1 AUTHOR
+
+Paul Marquess pmqs@cpan.org
+
diff --git a/Master/tlpkg/tlperl/lib/DBM_Filter/int32.pm b/Master/tlpkg/tlperl/lib/DBM_Filter/int32.pm
new file mode 100755
index 00000000000..d8fa5424af4
--- /dev/null
+++ b/Master/tlpkg/tlperl/lib/DBM_Filter/int32.pm
@@ -0,0 +1,50 @@
+package DBM_Filter::int32 ;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.02';
+
+# todo get Filter to figure endian.
+
+sub Store
+{
+ $_ = 0 if ! defined $_ || $_ eq "" ;
+ $_ = pack("i", $_);
+}
+
+sub Fetch
+{
+ no warnings 'uninitialized';
+ $_ = unpack("i", $_);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBM_Filter::int32 - filter for DBM_Filter
+
+=head1 SYNOPSIS
+
+ use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File
+ use DBM_Filter ;
+
+ $db = tie %hash, ...
+ $db->Filter_Push('int32');
+
+=head1 DESCRIPTION
+
+This DBM filter is used when interoperating with a C/C++ application
+that uses a C int as either the key and/or value in the DBM file.
+
+=head1 SEE ALSO
+
+L<DBM_Filter>, L<perldbmfilter>
+
+=head1 AUTHOR
+
+Paul Marquess pmqs@cpan.org
+
diff --git a/Master/tlpkg/tlperl/lib/DBM_Filter/null.pm b/Master/tlpkg/tlperl/lib/DBM_Filter/null.pm
new file mode 100755
index 00000000000..ffa10e92f21
--- /dev/null
+++ b/Master/tlpkg/tlperl/lib/DBM_Filter/null.pm
@@ -0,0 +1,52 @@
+package DBM_Filter::null ;
+
+use strict;
+use warnings;
+
+our $VERSION = '0.02';
+
+sub Store
+{
+ no warnings 'uninitialized';
+ $_ .= "\x00" ;
+}
+
+sub Fetch
+{
+ no warnings 'uninitialized';
+ s/\x00$// ;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBM_Filter::null - filter for DBM_Filter
+
+=head1 SYNOPSIS
+
+ use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File
+ use DBM_Filter ;
+
+ $db = tie %hash, ...
+ $db->Filter_Push('null');
+
+=head1 DESCRIPTION
+
+This filter ensures that all data written to the DBM file is null
+terminated. This is useful when you have a perl script that needs
+to interoperate with a DBM file that a C program also uses. A fairly
+common issue is for the C application to include the terminating null
+in a string when it writes to the DBM file. This filter will ensure that
+all data written to the DBM file can be read by the C application.
+
+
+=head1 SEE ALSO
+
+L<DBM_Filter>, L<perldbmfilter>
+
+=head1 AUTHOR
+
+Paul Marquess pmqs@cpan.org
diff --git a/Master/tlpkg/tlperl/lib/DBM_Filter/utf8.pm b/Master/tlpkg/tlperl/lib/DBM_Filter/utf8.pm
new file mode 100755
index 00000000000..677e66156b6
--- /dev/null
+++ b/Master/tlpkg/tlperl/lib/DBM_Filter/utf8.pm
@@ -0,0 +1,51 @@
+package DBM_Filter::utf8 ;
+
+use strict;
+use warnings;
+use Carp;
+
+our $VERSION = '0.02';
+
+BEGIN
+{
+ eval { require Encode; };
+
+ croak "Encode module not found.\n"
+ if $@;
+}
+
+sub Store { $_ = Encode::encode_utf8($_) if defined $_ }
+
+sub Fetch { $_ = Encode::decode_utf8($_) if defined $_ }
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBM_Filter::utf8 - filter for DBM_Filter
+
+=head1 SYNOPSIS
+
+ use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File
+ use DBM_Filter ;
+
+ $db = tie %hash, ...
+ $db->Filter_Push('utf8');
+
+=head1 DESCRIPTION
+
+This Filter will ensure that all data written to the DBM will be encoded
+in UTF-8.
+
+This module uses the Encode module.
+
+=head1 SEE ALSO
+
+L<DBM_Filter>, L<perldbmfilter>, L<Encode>
+
+=head1 AUTHOR
+
+Paul Marquess pmqs@cpan.org
+