Changeset 855

Show
Ignore:
Timestamp:
02/26/03 15:39:44
Author:
miyagawa
Message:

0.19: optimization and refactoring

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PHP-Session/trunk/Changes

    r854 r855  
    11Revision history for Perl extension PHP::Session 
    22 
     30.19  Tue Feb 25 19:21:10 JST 2003 
     4        - Optimized decoder using static method 
     5 
    360.18  Tue Feb 25 18:42:40 JST 2003 
    4         - Fixed test fails due to 5.8 MakeMaker bug (warnings disabled by default) 
     7        - Fixed test failures due to 5.8 MakeMaker bug (warnings disabled by default) 
    58 
    690.17  Tue Feb 25 16:43:05 JST 2003 
     
    1215        * Fixed bug that encodes strings like "20030224203445" as integer 
    1316          (Thanks to PIA) 
    14         * Fixed parser bug that string like qq(A\";B) is not restored corretly 
     17        * Fixed parser bug that string like qq(A\";B) is not restored correctly 
    1518 
    16190.15  Tue Jan 28 23:22:38 JST 2003 
  • PHP-Session/trunk/lib/PHP/Session.pm

    r854 r855  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.18
     5$VERSION = 0.19
    66 
    77use vars qw(%SerialImpl); 
  • PHP-Session/trunk/lib/PHP/Session/Serializer/PHP.pm

    r854 r855  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.18
     5$VERSION = 0.19
    66 
    77sub _croak { require Carp; Carp::croak(@_) } 
     
    121121sub change_state { 
    122122    my($self, $state) = @_; 
    123     $self->{state} = PHP::Session::Serializer::PHP::State->new($state); 
     123    $self->{state} = "PHP::Session::Serializer::PHP::State::$state"; # optimization 
     124#    $self->{state} = PHP::Session::Serializer::PHP::State->new($state); 
     125 
    124126} 
    125127 
     
    136138sub pop_stack { 
    137139    my $self = shift; 
    138     my $val = pop @{$self->{stack}}; 
    139     return $val; 
     140    pop @{$self->{stack}}; 
    140141} 
    141142 
     
    215216} 
    216217 
    217 package PHP::Session::Serializer::PHP::State; 
    218  
    219 sub new { 
    220     my($class, $name) = @_; 
    221     bless {}, "$class\::$name"; 
    222 } 
    223  
    224218package PHP::Session::Serializer::PHP::State::VarName; 
    225 use base qw(PHP::Session::Serializer::PHP::State); 
    226219 
    227220sub parse { 
     
    237230 
    238231package PHP::Session::Serializer::PHP::State::VarType; 
    239 use base qw(PHP::Session::Serializer::PHP::State); 
    240  
    241 my %re = ( 
    242     string  => 's:(\d+):', 
    243     integer => 'i:(-?\d+);', 
    244     double  => 'd:(-?\d+(?:\.\d+)?);', 
    245     array   => 'a:(\d+):', 
    246     object  => 'O:(\d+):', 
    247     null    => '(N);', 
    248     boolean => 'b:([01]);', 
     232 
     233my @re = ( 
     234    's:(\d+):',                 # string 
     235    'i:(-?\d+);',               # integer 
     236    'd:(-?\d+(?:\.\d+)?);',     # double 
     237    'a:(\d+):',                 # array 
     238    'O:(\d+):',                 # object 
     239    '(N);',                     # null 
     240    'b:([01]);',                # boolean 
    249241); 
    250242 
    251243sub parse { 
    252244    my($self, $decoder) = @_; 
    253     my $re = join "|", @re{qw(string integer double array object null boolean)}
     245    my $re = join "|", @re
    254246    $decoder->{buffer} =~ s/^(?:$re)// or $decoder->weird; 
    255     if (defined $1) { 
     247    if (defined $1) {          # string 
    256248        $decoder->push_stack($1); 
    257249        $decoder->change_state('String'); 
    258250    } 
    259     elsif (defined $2) { 
     251    elsif (defined $2) {       # integer 
    260252        $decoder->process_value($2); 
    261253    } 
    262     elsif (defined $3) { 
     254    elsif (defined $3) {       # double 
    263255        $decoder->process_value($3); 
    264256    } 
    265     elsif (defined $4) { 
     257    elsif (defined $4) {       # array 
    266258        $decoder->start_array($4); 
    267259        $decoder->change_state('ArrayStart'); 
    268260    } 
    269     elsif (defined $5) { 
     261    elsif (defined $5) {       # object 
    270262        $decoder->push_stack($5); 
    271263        $decoder->change_state('ClassName'); 
    272264    } 
    273     elsif (defined $6) { 
     265    elsif (defined $6) {       # null 
    274266        $decoder->process_value(undef); 
    275267    } 
    276     elsif (defined $7) { 
     268    elsif (defined $7) {       # boolean 
    277269        $decoder->process_value($7); 
    278270    } 
     
    280272 
    281273package PHP::Session::Serializer::PHP::State::String; 
    282 use base qw(PHP::Session::Serializer::PHP::State); 
    283274 
    284275sub parse { 
     
    290281 
    291282package PHP::Session::Serializer::PHP::State::ArrayStart; 
    292 use base qw(PHP::Session::Serializer::PHP::State); 
    293283 
    294284sub parse { 
     
    303293 
    304294package PHP::Session::Serializer::PHP::State::ArrayEnd; 
    305 use base qw(PHP::Session::Serializer::PHP::State); 
    306295 
    307296sub parse { 
     
    313302 
    314303package PHP::Session::Serializer::PHP::State::ClassName; 
    315 use base qw(PHP::Session::Serializer::PHP::State); 
    316304 
    317305sub parse {