Apache-DefaultCharset
view release on metacpan or search on metacpan
Apache-Test/lib/Apache/TestCharset.pm view on Meta::CPAN
package Apache::TestCharset;
use strict;
use Apache::DefaultCharset;
sub handler {
my $r = shift;
my $charset = Apache::DefaultCharset->new($r);
$r->send_http_header;
$r->print("charset:$charset\n");
$r->print("charset_r:", $r->add_default_charset_name, "\n");
}
1;
Apache-Test/lib/Apache/TestCharsetModify.pm view on Meta::CPAN
package Apache::TestCharsetModify;
use strict;
use Apache::DefaultCharset;
sub handler {
my $r = shift;
my $charset = Apache::DefaultCharset->new($r);
$charset->name('euc-kr');
$r->send_http_header('text/html');
$r->print("charset:$charset");
}
1;
Revision history for Perl extension Apache::DefaultCharset
0.02 Mon Sep 2 17:30:08 JST 2002
* Add add_default_charset_name() into Apache package
0.01 Fri May 31 04:47:01 2002
- original version
DefaultCharset.xs view on Meta::CPAN
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#define CORE_PRIVATE
#include "mod_perl.h"
char *
_get(Apache r) {
core_dir_config *conf = ap_get_module_config(r->per_dir_config, &core_module);
return conf->add_default_charset_name;
}
void
_set(Apache r, char *charset) {
core_dir_config *conf = ap_get_module_config(r->per_dir_config, &core_module);
conf->add_default_charset_name = charset;
return;
}
MODULE = Apache::DefaultCharset PACKAGE = Apache::DefaultCharset
PROTOTYPES: DISABLE
char *
_get(r)
Apache r;
CODE:
RETVAL = _get(r);
OUTPUT:
RETVAL
void
_set(r, charset)
Apache r;
char *charset;
CODE:
_set(r, charset);
NAME
Apache::DefaultCharset - AddDefaultCharset configuration from mod_perl
SYNOPSIS
use Apache::DefaultCharset;
# This module adds "add_default_charset_name" method
$charset = $r->add_default_charset_name;
$r->add_default_charset_name('euc-jp');
# via Apache::DefaultCharset object
$charset = Apache::DefaultCharset->new($r);
print "default_charset_name is ", $charset->name;
# or print "default charset is $charset"; will do (overload)
$charset->name('euc-jp');
DESCRIPTION
Apache::DefaultCharset is an XS wrapper for Apache Core's
"AddDefaultCharset" configuration.
EXAMPLES
Unicode Handling
Suppose you develop multi-language web application, and transparently
decode native encodings into Unicode string inside Perl (5.8 or over
AddDefaultCharset euc-jp
in your "httpd.conf", then leave off "send_http_header" arguments just
to text/html. Then you can get the current configuration with this
module when you use "Encode" or "Text::Iconv" to decode the HTTP request
query into Unicode.
Modification of DefaultCharset
Suppose you want to add utf-8 for XML files, and Shift_JIS for HTML
files as HTTP charset attribute by default ("By default" means that if
you set "content_type" explicitly in content-generation phase, that will
be prior to the defalut). This module enables you to write
"PerlFixupHandler" to configure "add_default_charset_name" in run-time.
AUTHOR
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
SEE ALSO
the Apache::DefaultCharset manpage
lib/Apache/DefaultCharset.pm view on Meta::CPAN
my $self = shift;
if (@_ == 1) {
_set($self->{r}, @_);
} else {
return _get($self->{r});
}
}
package Apache;
sub add_default_charset_name {
my $r = shift;
if (@_ == 1) {
Apache::DefaultCharset::_set($r, @_);
} else {
return Apache::DefaultCharset::_get($r);
}
}
1;
__END__
=head1 NAME
Apache::DefaultCharset - AddDefaultCharset configuration from mod_perl
=head1 SYNOPSIS
use Apache::DefaultCharset;
# This module adds "add_default_charset_name" method
$charset = $r->add_default_charset_name;
$r->add_default_charset_name('euc-jp');
# via Apache::DefaultCharset object
$charset = Apache::DefaultCharset->new($r);
print "default_charset_name is ", $charset->name;
# or print "default charset is $charset"; will do (overload)
$charset->name('euc-jp');
=head1 DESCRIPTION
Apache::DefaultCharset is an XS wrapper for Apache Core's
C<AddDefaultCharset> configuration.
=head1 EXAMPLES
=head2 Unicode Handling
lib/Apache/DefaultCharset.pm view on Meta::CPAN
AddDefaultCharset euc-jp
in your C<httpd.conf>, then leave off C<send_http_header> arguments
just to text/html. Then you can get the current configuration with
this module when you use C<Encode> or C<Text::Iconv> to decode the HTTP
request query into Unicode.
=head2 Modification of DefaultCharset
Suppose you want to add utf-8 for XML files, and Shift_JIS for HTML
files as HTTP charset attribute by default ("By default" means that if
you set C<content_type> explicitly in content-generation phase, that
will be prior to the defalut). This module enables you to write
C<PerlFixupHandler> to configure C<add_default_charset_name> in
run-time.
=head1 AUTHOR
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
use strict;
use Apache::Test;
use Apache::TestRequest;
plan tests => 4, have_lwp;
{
my $body = GET_BODY "/euc-jp/index.html";
ok($body, qr/charset:euc-jp/);
ok($body, qr/charset_r:euc-jp/);
}
{
my $body = GET_BODY "/utf-8/index.html";
ok($body, qr/charset:utf-8/);
ok($body, qr/charset_r:utf-8/);
}
use strict;
use Apache::Test;
use Apache::TestRequest;
plan tests => 2, have_lwp;
{
my $head = GET_HEAD "/mod";
ok($head, qr@Content-Type: text/html; charset=euc-kr@);
my $body = GET_BODY "/mod";
ok($body, qr/charset:euc-kr/);
}
( run in 0.360 second using v1.01-cache-2.11-cpan-4d50c553e7e )