|
|
ru.cgi.perl- RU.CGI.PERL ------------------------------------------------------------------ From : Dmitry Tsigelnik 2:5020/400 17 Dec 2003 12:33:41 To : Alexey Mahotkin Subject : Re: TT2 -------------------------------------------------------------------------------- Alexey Mahotkin пишет: AM> Мой, что ли, патч? У меня всё читает в правильной кодировке. Покажи, как AM> ты зовёшь HTML::Template и где взял патч? AM> --alexm То что читает не в той кодировке, жаловался мой начальник, сам я tmpl_include c этим патчем не использовал. Этот? - --- Template.pm 2003/04/30 15:51:51 1.1.1.1 +++ Template.pm 2003/05/28 13:04:24 1.5 @@ -628,6 +628,16 @@ =item * +perlio_layer - if set then do the additional binmode() call to set the +PerlIO layer (in Perl 5.8.0+). Usually used to handle templates in +UTF-8. Example: + + my $template = HTML::Template->new( filename => 'file.tmpl', + perlio_layer => ':utf8', + ); + +=item * + search_path_on_include - if set to a true value the module will search from the top of the array of paths specified by the path option on every <TMPL_INCLUDE> and use the first matching template found. The @@ -1583,15 +1593,9 @@ $options->{filepath} = $filepath; } - confess("HTML::Template->new() : Cannot open included file $options->{filename} : $!") - unless defined(open(TEMPLATE, $filepath)); + $self->{template} = $self->_read_template_file($filepath, $options- >{filename}, $options); $self->{mtime} = $self->_mtime($filepath); - # read into scalar, note the mtime for the record - $self->{template} = ""; - while (read(TEMPLATE, $self->{template}, 10240, length($self-> {template}))) {} - close(TEMPLATE); - } elsif (exists($options->{scalarref})) { # copy in the template text $self->{template} = ${$options->{scalarref}}; @@ -1621,6 +1625,28 @@ return $self; } +sub _read_template_file { + my $self = shift; + my $filepath = shift; + my $filename = shift; + my $options = shift; + + confess("HTML::Template->new() : Cannot open included file $filename : $!") + unless defined(open(TEMPLATE, $filepath)); + + if ($options->{perlio_layer}) { + binmode TEMPLATE, $options->{perlio_layer} + or confess ("HTML::Template->new() : Cannot set PerlIO layer on $filename: $!"); + } + + # read into scalar + my $template = ""; + while (read(TEMPLATE, $template, 10240, length($template))) {} + close(TEMPLATE); + + return $template; +} + # handle calling user defined filters sub _call_filters { my $self = shift; @@ -1907,7 +1933,8 @@ (.*) # $19 => $post - text that comes after the tag $/sx) { - $which = uc($1); # which tag is it + $which = $1; + $which = uc($which); # which tag is it $escape = defined $5 ? $5 : defined $15 ? $15 : 0; # escape set? @@ -2177,14 +2204,9 @@ } die "HTML::Template->new() : Cannot open included file $filename : file not found." unless defined($filepath); - die "HTML::Template->new() : Cannot open included file $filename : $!" - unless defined(open(TEMPLATE, $filepath)); - - # read into the array - my $included_template = ""; - while(read(TEMPLATE, $included_template, 10240, length ($included_template))) {} - close(TEMPLATE); - + + my $included_template = $self->_read_template_file($filepath, $filename, $options); + # call filters if necessary $self->_call_filters(\$included_template) if @{$options->{filter}}; -------------------- Dmitry Tsigelnik -- Отправлено через сервер Форумы@mail.ru - http://talk.mail.ru --- ifmail v.2.15dev5.1 * Origin: Talk.ru (2:5020/400) Вернуться к списку тем, сортированных по:
Архивное /ru.cgi.perl/64882d8a16c6.html, оценка из 5, голосов 10
|