Changeset 2192

Show
Ignore:
Timestamp:
04/18/07 05:58:06
Author:
miyagawa
Message:

Checking in changes prior to tagging of version 0.08. Changelog diff is:

=== Changes
==================================================================
--- Changes (revision 5674)
+++ Changes (local)
@@ -1,5 +1,10 @@

Revision history for Perl extension Template::Provider
Encoding

+0.08 Tue Apr 17 13:52:40 PDT 2007
+ - Applied patch http://www.cpanforum.com/posts/2177 so the
+ default encoding other than 'utf-8' can be set
+ (Thanks to Nobuaki ITO)
+

0.07 Sun Oct 22 21:41:03 JST 2006

- Added dependency for Template-Toolkit

(Thanks to Andreas Koenig)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Template-Provider-Encoding/trunk/Changes

    r2047 r2192  
    11Revision history for Perl extension Template::Provider::Encoding 
     2 
     30.08  Tue Apr 17 13:52:40 PDT 2007 
     4        - Applied patch http://www.cpanforum.com/posts/2177 so the 
     5          default encoding other than 'utf-8' can be set 
     6          (Thanks to Nobuaki ITO) 
    27 
    380.07  Sun Oct 22 21:41:03 JST 2006 
  • Template-Provider-Encoding/trunk/MANIFEST.SKIP

    r1733 r2192  
    1010\.gz$ 
    1111\.cvsignore 
     12\.shipit 
  • Template-Provider-Encoding/trunk/lib/Template/Provider/Encoding.pm

    r2047 r2192  
    22 
    33use strict; 
    4 our $VERSION = '0.07'; 
     4our $VERSION = '0.08'; 
    55 
    66use base qw( Template::Provider ); 
    77use Encode; 
     8 
     9sub _init { 
     10    my ($self, $params) = @_; 
     11 
     12    $self = $self->SUPER::_init($params); 
     13    $self->{DEFAULT_ENCODING} = $params->{DEFAULT_ENCODING} || 'utf8'; 
     14    $self->{ENCODE_CHECK}     = $params->{ENCODE_CHECK} || Encode::FB_DEFAULT; 
     15    return $self; 
     16} 
    817 
    918sub _load { 
     
    1221 
    1322    unless (Encode::is_utf8($data->{text})) { 
    14         my $encoding = $data->{text} =~ /^\[% USE encoding '([\w\-]+)'/ 
    15             ? $1 : 'utf-8'; 
    16         $data->{text} = Encode::decode($encoding, $data->{text}); 
     23        my $decoder = $self->detect_encoding($data); 
     24        $data->{text} = $decoder->decode($data->{text}, $self->{ENCODE_CHECK}); 
    1725    } 
    1826 
    1927    return ($data, $error); 
     28} 
     29 
     30sub detect_encoding { 
     31    my ($self, $data) = @_; 
     32 
     33    my $encoding = $data->{text} =~ /^\[% USE encoding '([\w\-]+)'/ 
     34        ? $1 : $self->{DEFAULT_ENCODING}; 
     35    return Encode::find_encoding($encoding); 
    2036} 
    2137