[Templates-cvs] cvs commit: Template2/lib Template.pm

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/02/01 09:05:17

  Modified:    lib      Template.pm
  Log:
  * added ENCODING option
  
  Revision  Changes    Path
  2.83      +14 -6     Template2/lib/Template.pm
  
  Index: Template.pm
  ===================================================================
  RCS file: /template-toolkit/Template2/lib/Template.pm,v
  retrieving revision 2.82
  retrieving revision 2.83
  diff -u -r2.82 -r2.83
  --- Template.pm	2006/02/01 08:54:11	2.82
  +++ Template.pm	2006/02/01 09:05:17	2.83
  @@ -17,7 +17,7 @@
   #   modify it under the same terms as Perl itself.
   #
   # REVISION
  -#   $Id: Template.pm,v 2.82 2006/02/01 08:54:11 abw Exp $
  +#   $Id: Template.pm,v 2.83 2006/02/01 09:05:17 abw Exp $
   #
   #========================================================================
    
  @@ -61,8 +61,18 @@
       my $options = (@opts == 1) && UNIVERSAL::isa($opts[0], 'HASH')
           ? shift(@opts) : { @opts };
       
  -    $options->{ binmode } = $BINMODE 
  -        unless defined $options->{ binmode };
  +    unless (defined $options->{ binmode }) {
  +        my $enc = $options->{ encoding } || $self->{ ENCODING };
  +        if ($enc) {
  +            # express encoding as a Perl IO layer
  +            # e.g. 'utf-8' => ':utf8',
  +            $enc =~ s/\W//;
  +            $options->{ binmode } = ":$enc";
  +        }
  +        else {
  +            $options->{ binmode } = $BINMODE;
  +        }
  +    }
   
       # we're using this for testing in t/output.t and t/filter.t so 
       # don't remove it if you don't want tests to fail...
  @@ -193,9 +203,7 @@
           }
           elsif (open(FP, ">$where")) { 
               # binmode option can be 1 or a specific layer, e.g. :utf8
  -            my $bm = $options->{ binmode  } 
  -                  || $options->{ encoding }
  -                  || $self->{ ENCODING };
  +            my $bm = $options->{ binmode  };
               if ($bm && +$bm == 1) { 
                   binmode FP;
               }