source: for-distributions/trunk/bin/windows/perl/lib/DBM_Filter/encode.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 1.3 KB
Line 
1package DBM_Filter::encode ;
2
3use strict;
4use warnings;
5use Carp;
6
7our $VERSION = '0.01';
8
9BEGIN
10{
11 eval { require Encode; };
12
13 croak "Encode module not found.\n"
14 if $@;
15}
16
17
18sub Filter
19{
20 my $encoding_name = shift || "utf8";
21
22 my $encoding = Encode::find_encoding($encoding_name) ;
23
24 croak "Encoding '$encoding_name' is not available"
25 unless $encoding;
26
27 return {
28 Store => sub {
29 $_ = $encoding->encode($_)
30 if defined $_ ;
31 },
32 Fetch => sub {
33 $_ = $encoding->decode($_)
34 if defined $_ ;
35 }
36 } ;
37}
38
391;
40
41__END__
42
43=head1 DBM_Filter::encode
44
45=head1 SYNOPSIS
46
47 use SDBM_File; # or DB_File, or GDBM_File, or NDBM_File, or ODBM_File
48 use DBM_Filter ;
49
50 $db = tie %hash, ...
51 $db->Filter_Push('encode' => 'iso-8859-16');
52
53=head1 DESCRIPTION
54
55This DBM filter allows you to choose the character encoding will be
56store in the DBM file. The usage is
57
58 $db->Filter_Push('encode' => ENCODING);
59
60where "ENCODING" must be a valid encoding name that the Encode module
61recognises.
62
63A fatal error will be thrown if:
64
65=over 5
66
67=item 1
68
69The Encode module is not available.
70
71=item 2
72
73The encoding requested is not supported by the Encode module.
74
75=back
76
77=head1 SEE ALSO
78
79L<DBM_Filter>, L<perldbmfilter>, L<Encode>
80
81=head1 AUTHOR
82
83Paul Marquess [email protected]
84
Note: See TracBrowser for help on using the repository browser.