H.Merijn Brand wrote:
> This rocks!
> 
> my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
>     RaiseError        => 1,
>     PrintError        => 1,
> 
>     f_dir     => ".",
>     f_schema  => undef,
>     f_ext     => ".csv/r",
>     f_encoding        => "utf8",
>     });
> 
> Any objections to me committing that?

Looks good to me and I'm pleased you are using encoding and not just
":utf8" as the former is validating utf-8 encoding and the latter does not.


> --8<---
> --- /pro/3gl/CPAN/DBI-svn/lib/DBD/File.pm       2009-12-03 20:58:35.000000000 
> +0100
> +++ /pro/lib/perl5/site_perl/5.12.0/i686-linux-64int-ld/DBD/File.pm     
> 2010-04-21 16:06:12.000000000 +0200
> @@ -163,6 +163,7 @@ sub connect ($$;$$$)
>             f_schema    => 1, # schema name
>             f_tables    => 1, # base directory
>             f_lock      => 1, # Table locking mode
> +           f_encoding  => 1, # Encoding of the file
>             };
>          $this->{sql_valid_attrs} = {
>             sql_handler           => 1, # Nano or S:S
> @@ -724,7 +725,14 @@ sub open_table ($$$$$)
>             $safe_drop or croak "Cannot open $file: $!";
>             }
>         }
> -    $fh and binmode $fh;
> +    if ($fh) {
> +       if (my $enc = $data->{Database}{f_encoding}) {
> +           binmode $fh, ":encoding($enc)";
> +           }
> +       else {
> +           binmode $fh;
> +           }
> +       }
>      if ($locking and $fh) {
>         my $lm = defined $data->{Database}{f_lock}
>                       && $data->{Database}{f_lock} =~ m/^[012]$/
> @@ -961,6 +969,11 @@ But see L</"NOWN BUGS"> below.
> 
>  =back
> 
> +=item f_encoding
> +
> +With this attribute, you can set the encoding in which the file is opened.
> +This is implemented using C<binmode $fh, ":encoding(<f_encoding>)">.
> +
>  =head2 Driver private methods
> 
>  =over 4
> -->8---
> 

Martin
-- 
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Reply via email to