Changeset e68fca


Ignore:
Timestamp:
01/13/08 14:34:25 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master, ketama-compat
Children:
dad4cc
Parents:
ccd211
git-author:
Tomash Brechko <tomash.brechko@…> (01/13/08 14:34:25)
git-committer:
Tomash Brechko <tomash.brechko@…> (01/13/08 14:34:25)
Message:

Add utf8 constructor parameter.

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • Changes

    r823293 re68fca  
    3131        script/compare.pl was removed.  Instead script/benchmark.pl 
    3232        takes an optional last argument "compare". 
     33 
     34        New 'utf8' parameter for constructor. 
    3335 
    3436 
  • MANIFEST

    r823293 re68fca  
    1818t/pod-coverage.t 
    1919t/pod.t 
     20t/utf8.t 
    2021lib/Cache/Memcached/Fast.pm 
    2122src/Makefile.PL 
  • TODO

    rccd211 re68fca  
    2222 
    2323- Add test for noreply, do not list it in MANIFEST. 
    24  
    25 - utf8 => 1 (in utf8 branch). 
    2624 
    2725- tainted_in, tainted_out parameters. 
  • lib/Cache/Memcached/Fast.pm

    rabe4dc re68fca  
    4141      ketama_points => 150, 
    4242      nowait => 1, 
     43      utf8 => ($^V >= 5.008001 ? 1 : 0), 
    4344  }); 
    4445 
     
    130131use constant F_STORABLE => 0x1; 
    131132use constant F_COMPRESS => 0x2; 
     133use constant F_UTF8     => 0x4; 
    132134 
    133135 
     
    166168use fields qw( 
    167169    _xs servers 
    168     compress_threshold compress_ratio compress_methods 
     170    compress_threshold compress_ratio compress_methods utf8 
    169171); 
    170172 
     
    392394 
    393395 
     396=item I<utf8> (B<experimental, Perl 5.8.1 and later only>) 
     397 
     398  utf8 => 1 
     399  (default: disabled) 
     400 
     401The value is a boolean which enables (true) or disables (false) the 
     402conversion of Perl character strings to octet sequences in UTF-8 
     403encoding on store, and the reverse conversion on fetch (when the 
     404retrieved data is marked as being UTF-8 octet sequence).  See 
     405L<perlunicode|perlunicode>. 
     406 
     407 
    394408=back 
    395409 
     
    415429    } 
    416430 
     431    if ($conf->{utf8}) { 
     432        if ($^V >= 5.008001) { 
     433            $self->{utf8} = 1; 
     434        } else { 
     435            carp "'utf8' may be enabled only for Perl >= 5.8.1, disabled"; 
     436        } 
     437    } 
     438 
    417439    $self->{_xs} = new Cache::Memcached::Fast::_xs($conf); 
    418440 
     
    473495        $flags |= F_STORABLE; 
    474496    } else { 
    475         $val_ref = \$_[0]; 
     497        if ($self->{utf8} and utf8::is_utf8($_[0])) { 
     498            # We have to copy the value because we will modify it in place. 
     499            my $octets = $_[0]; 
     500            utf8::encode($octets); 
     501            $flags |= F_UTF8; 
     502            $val_ref = \$octets; 
     503        } else { 
     504            $val_ref = \$_[0]; 
     505        } 
    476506    } 
    477507 
     
    519549        }; 
    520550        return if $@; 
     551    } elsif ($_[1] & F_UTF8 and $self->{utf8}) { 
     552        return unless utf8::decode(${$_[0]}); 
    521553    } 
    522554 
     
    14891521 
    14901522 
    1491 =head1 UTF-8 and tainted data 
    1492  
    1493 Current implementation does not preserve UTF-8 flag on scalars. 
    1494 Storing UTF-8 string and retrieving it back would return the same byte 
    1495 sequence, but UTF-8 flag will be forgotten.  See L<utf8|utf8>. 
    1496  
    1497 Likewise, tainted flag is neither tested nor preserved, storing 
    1498 tainted data and retrieving it back would clear tainted flag.  See 
    1499 L<perlsec|perlsec>. 
     1523=head1 Tainted data 
     1524 
     1525In current implementation tainted flag is neither tested nor 
     1526preserved, storing tainted data and retrieving it back would clear 
     1527tainted flag.  See L<perlsec|perlsec>. 
    15001528 
    15011529 
     
    15651593Development of this module is sponsored by S<Monashev Co. Ltd.> 
    15661594 
     1595Thanks to Peter J. Holzer for enlightening on UTF-8 support. 
     1596 
    15671597 
    15681598=head1 WARRANTY 
  • t/Memd.pm

    r9a7c3a re68fca  
    2929        ketama_points => 150, 
    3030        nowait => 1, 
     31        utf8 => ($^V >= 5.008001 ? 1 : 0), 
    3132    ); 
    3233 
Note: See TracChangeset for help on using the changeset viewer.