Apache-PageKit
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
+ _change_hash( $charset, $_ );
} elsif ( $type eq 'ARRAY' ) {
- _change_array( $converter, $_ );
+ _change_array( $charset, $_ );
} else {
- $_ = $converter->convert($_) || die "Can not convert from default_input_charset to default_output_charset" if $_;
+ $_ = Encode::decode($charset, $_);
}
}
}
sub _change_hash {
- my ($converter, $href) = @_;
+ my ($charset, $href) = @_;
foreach ( values %$href ) {
my $type = ref $_;
if ( $type eq 'HASH' ) {
- _change_hash( $converter, $_ );
+ _change_hash( $charset, $_ );
} elsif ( $type eq 'ARRAY' ) {
- _change_array( $converter, $_ );
+ _change_array( $charset, $_ );
} else {
- $_ = $converter->convert($_) || die "Can not convert from default_input_charset to default_output_charset" if $_;
+ $_ = Encode::decode($charset, $_);
}
}
}
- my $converter = shift;
+ my $charset = shift;
for ( my $i = 1 ; $i <= $#_ ; $i += 2 ) {
my $type = ref $_[$i];
if ( $type eq 'HASH' ) {
- _change_hash( $converter, $_[$i] );
+ _change_hash( $charset, $_[$i] );
} elsif ( $type eq 'ARRAY' ) {
- _change_array( $converter, $_[$i] );
+ _change_array( $charset, $_[$i] );
} else {
- $_[$i] = $converter->convert($_[$i]) || die "Can not convert from default_input_charset to default_output_charset" if $_[$i];
+ $_[$i] = Encode::decode($charset, $_[$i]);
}
}
}
diff -Nur a/lib/Apache/PageKit/View.pm b/lib/Apache/PageKit/View.pm
--- a/lib/Apache/PageKit/View.pm 2005-01-01 20:42:57.141131208 +0100
+++ b/lib/Apache/PageKit/View.pm 2005-01-01 19:51:50.980258512 +0100
@@ -182,11 +182,13 @@
my $fif;
if(@{$view->{fillinform_objects}}){
$view->{pkit_pk}->{browser_cache} = 'no';
+ Encode::_utf8_off($output);
$fif = HTML::FillInForm->new();
$output = $fif->fill(scalarref => \$output,
fobject => $view->{fillinform_objects},
ignore_fields => $view->{ignore_fillinform_fields}
);
+ Encode::_utf8_on($output);
}
}
if($view->{can_edit} eq 'yes'){
@@ -206,15 +208,15 @@
# is the cache entry valid or changed on disc?
if(-f "$gzipped_filename"){
- open FH, "<$gzipped_filename" or return undef;
- binmode FH;
+ open my $fh, "<$gzipped_filename" or return undef;
+ binmode $fh;
# read mtime from first line
chomp($gzip_mtime = <FH>);
# read rest of gzipped content
- local $/ = undef;
- $gzipped_content = <FH>;
- close FH;
+ local $/;
+ $gzipped_content = <$fh>;
+ close $fh;
if($view->{reload} ne 'no'){
# is the cache entry valid or changed on disc?
my $mtime = ( stat($filename) )[9];
@@ -285,11 +287,11 @@
# creates gzipped file
sub _create_static_zip {
my ($view, $filename, $gzipped_filename) = @_;
- local $/ = undef;
- open FH, "<$filename" or return undef;
- binmode FH;
- my $content = <FH>;
- close FH;
+ local $/;
+ open my $fh, "<$filename" or return undef;
+ binmode $fh;
+ my $content = <$fh>;
+ close $fh;
$view->_html_clean(\$content);
@@ -301,11 +303,11 @@
if ($gzipped_content) {
my $mtime = (stat($filename))[9];
- if ( open GZIP, ">$gzipped_filename" ) {
- binmode GZIP;
- print GZIP "$mtime\n";
- print GZIP $gzipped_content;
- close GZIP;
+ if ( open my $gzip_fh, ">$gzipped_filename" ) {
+ binmode $gzip_fh;
+ print $gzip_fh "$mtime\n";
+ print $gzip_fh $gzipped_content;
+ close $gzip_fh;
} else {
warn "can not create gzip cache file $view->{cache_dir}/$gzipped_filename: $!";
}
@@ -457,12 +459,13 @@
# currently only XML::LibXSLT is supported
$template_ref = $view->{content}->generate_template($page_id, $component_id, $pkit_view, $view->{input_param_object}, $component_params);
} else {
- open TEMPLATE, "<$template_file" or die "can not read $template_file";
Makefile.PL view on Meta::CPAN
- my $default_input_charset = $view->{default_input_charset};
- unless ( lc $default_input_charset eq lc $default_output_charset) {
- eval {
- $converter = Text::Iconv->new( $default_input_charset, $default_output_charset );
- };
- if ($@) {
- (my $config_dir = $view->{content_dir}) =~ s!/Content$!/Config!;
- die "The conversion from ($default_input_charset => $default_output_charset) is not supported by Text::Iconv please check file ${config_dir}/Config.xml";
- }
- }
- else {
- unless ( /^utf-?8$/i =~ $default_output_charset) {
- eval {
- $converter = Text::Iconv->new( 'utf8', $default_output_charset);
- };
- if ($@) {
- (my $config_dir = $view->{content_dir}) =~ s!/Content$!/Config!;
- die "The conversion from ('utf8' => $default_output_charset) is not supported by Text::Iconv please check file ${config_dir}/Config.xml";
- }
- }
- }
- }
+ # my $template_file = $view->_find_template($pkit_view, $page_id);
+ my $lang_tmpl = $content->process_template($page_id, $template_ref);
# add used content file(s) to the mtimes hash
while( my ( $file, $mtime ) = each( %{ $content->{include_mtimes} } ) ) {
@@ -551,10 +525,6 @@
# go through content files (which have had content filled in)
while (my ($lang, $filtered_html) = each %$lang_tmpl){
- if ( $converter ) {
- $$filtered_html = $converter->convert($$filtered_html) || die "Can not convert page from 'something' to $default_output_charset" if $$filtered_html;
- }
-
my $exclude_params_set = $view->_preparse_model_tags($filtered_html);
$view->_html_clean($filtered_html);
@@ -612,7 +582,6 @@
}
sub _preparse_model_tags {
- use bytes;
my ( $view, $html_code_ref ) = @_;
my $exclude_params_set = {};
@@ -817,12 +786,14 @@
my $fif;
if ( @{ $view->{fillinform_objects} } ) {
$view->{pkit_pk}->{browser_cache} = 'no';
+ Encode::_utf8_off($output);
$fif = HTML::FillInForm->new();
$output = $fif->fill(
scalarref => \$output,
fobject => $view->{fillinform_objects},
ignore_fields => $view->{ignore_fillinform_fields}
);
+ Encode::_utf8_on($output);
}
}
if ( $view->{can_edit} eq 'yes' ) {
@@ -868,36 +839,7 @@
$$template_ref =~ s/$pkit_comment_re//sgi;
# my $template_file = $view->_find_template($pkit_view, $page_id);
- my ( $lang_tmpl, $skip_xpath_content ) = $content->process_template($page_id, $template_ref);
-
- # find the right converter for perl < 5.8.0
- # if we skip the xpath content, the string is in $default_input_charset.
- # otherwise it is in utf8 ( from libxml2 )
- my $converter;
- my $default_output_charset = $view->{default_output_charset};
- if ( $skip_xpath_content ) {
- my $default_input_charset = $view->{default_input_charset};
- unless ( lc $default_input_charset eq lc $default_output_charset) {
- eval {
- $converter = Text::Iconv->new( $default_input_charset, $default_output_charset );
- };
- if ($@) {
- (my $config_dir = $view->{content_dir}) =~ s!/Content$!/Config!;
- die "The conversion from ($default_input_charset => $default_output_charset) is not supported by Text::Iconv please check file ${config_dir}/Config.xml";
- }
- }
- else {
- unless ( /^utf-?8$/i =~ $default_output_charset) {
- eval {
- $converter = Text::Iconv->new( 'utf8', $default_output_charset);
- };
- if ($@) {
- (my $config_dir = $view->{content_dir}) =~ s!/Content$!/Config!;
- die "The conversion from ('utf8' => $default_output_charset) is not supported by Text::Iconv please check file ${config_dir}/Config.xml";
- }
- }
- }
- }
+ my $lang_tmpl = $content->process_template( $page_id, $template_ref );
# add used content file(s) to the mtimes hash
while ( my ( $file, $mtime ) = each( %{ $content->{include_mtimes} } ) ) {
@@ -907,12 +849,6 @@
# go through content files (which have had content filled in)
while ( my ( $lang, $filtered_html ) = each %$lang_tmpl ) {
- if ($converter) {
- $$filtered_html = $converter->convert($$filtered_html)
- || die "Can not convert page from 'something' to $default_output_charset"
- if $$filtered_html;
- }
-
my $exclude_params_set = $view->_preparse_model_tags($filtered_html);
$view->_html_clean($filtered_html);
@@ -959,7 +895,6 @@
}
sub _preparse_model_tags {
- use bytes;
my ( $view, $html_code_ref ) = @_;
my $exclude_params_set = {};
diff -Nur a/lib/Apache/PageKit.pm b/lib/Apache/PageKit.pm
( run in 1.011 second using v1.01-cache-2.11-cpan-39bf76dae61 )