root/Apache-DefaultCharset/trunk/lib/Apache/DefaultCharset.pm

Revision 744 (checked in by miyagawa, 18 years ago)

0.02

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package Apache::DefaultCharset;
2
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = 0.02;
6
7 require DynaLoader;
8 use base qw(DynaLoader);
9 __PACKAGE__->bootstrap($VERSION) if $ENV{MOD_PERL};
10
11 use overload q("") => sub { _get($_[0]->{r}) };
12
13 sub new {
14     my($class, $r) = @_;
15     bless { r => $r }, $class;
16 }
17
18 sub name {
19     my $self = shift;
20     if (@_ == 1) {
21         _set($self->{r}, @_);
22     } else {
23         return _get($self->{r});
24     }
25 }
26
27 package Apache;
28
29 sub add_default_charset_name {
30     my $r = shift;
31     if (@_ == 1) {
32         Apache::DefaultCharset::_set($r, @_);
33     } else {
34         return Apache::DefaultCharset::_get($r);
35     }
36 }
37
38 1;
39 __END__
40
41 =head1 NAME
42
43 Apache::DefaultCharset - AddDefaultCharset configuration from mod_perl
44
45 =head1 SYNOPSIS
46
47   use Apache::DefaultCharset;
48
49   # This module adds "add_default_charset_name" method
50   $charset = $r->add_default_charset_name;
51   $r->add_default_charset_name('euc-jp');
52
53   # via Apache::DefaultCharset object
54   $charset = Apache::DefaultCharset->new($r);
55   print "default_charset_name is ", $charset->name;
56   # or print "default charset is $charset"; will do (overload)
57   $charset->name('euc-jp');
58
59
60 =head1 DESCRIPTION
61
62 Apache::DefaultCharset is an XS wrapper for Apache Core's
63 C<AddDefaultCharset> configuration.
64
65 =head1 EXAMPLES
66
67 =head2 Unicode Handling
68
69 Suppose you develop multi-language web application, and transparently
70 decode native encodings into Unicode string inside Perl (5.8 or over
71 would be better). First you should add
72
73   AddDefaultCharset euc-jp
74
75 in your C<httpd.conf>, then leave off C<send_http_header> arguments
76 just to text/html. Then you can get the current configuration with
77 this module when you use C<Encode> or C<Text::Iconv> to decode the HTTP
78 request query into Unicode.
79
80 =head2 Modification of DefaultCharset
81
82 Suppose you want to add utf-8 for XML files, and Shift_JIS for HTML
83 files as HTTP charset attribute by default ("By default" means that if
84 you set C<content_type> explicitly in content-generation phase, that
85 will be prior to the defalut). This module enables you to write
86 C<PerlFixupHandler> to configure C<add_default_charset_name> in
87 run-time.
88
89 =head1 AUTHOR
90
91 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
92
93 This library is free software; you can redistribute it and/or modify
94 it under the same terms as Perl itself.
95
96 =head1 SEE ALSO
97
98 L<Apache::DefaultCharset>
99
100 mod_perl cookbook at http://www.modperlcookbook.org/
101
102 =cut
Note: See TracBrowser for help on using the browser.