perl: cleanup PP

This commit is contained in:
gfx 2010-09-22 15:59:21 +09:00
parent 68b6fa46e6
commit 0a8a6ed168

View File

@ -1,20 +1,17 @@
package Data::MessagePack::PP; package Data::MessagePack::PP;
use 5.008001; use 5.008001;
use strict; use strict;
use warnings;
no warnings 'recursion';
use Carp (); use Carp ();
use B ();
# See also # See also
# http://redmine.msgpack.org/projects/msgpack/wiki/FormatSpec # http://redmine.msgpack.org/projects/msgpack/wiki/FormatSpec
# http://cpansearch.perl.org/src/YAPPO/Data-Model-0.00006/lib/Data/Model/Driver/Memcached.pm # http://cpansearch.perl.org/src/YAPPO/Data-Model-0.00006/lib/Data/Model/Driver/Memcached.pm
# http://frox25.no-ip.org/~mtve/wiki/MessagePack.html : reference to using CORE::pack, CORE::unpack # http://frox25.no-ip.org/~mtve/wiki/MessagePack.html : reference to using CORE::pack, CORE::unpack
package
Data::MessagePack;
use strict;
use B ();
BEGIN { BEGIN {
my $unpack_int64_slow; my $unpack_int64_slow;
my $unpack_uint64_slow; my $unpack_uint64_slow;
@ -120,6 +117,18 @@ BEGIN {
*unpack_int64 = $unpack_int64_slow || sub { return unpack( 'q>', substr( $_[0], $_[1], 8 ) ); }; *unpack_int64 = $unpack_int64_slow || sub { return unpack( 'q>', substr( $_[0], $_[1], 8 ) ); };
*unpack_uint64 = $unpack_uint64_slow || sub { return unpack( 'Q>', substr( $_[0], $_[1], 8 ) ); }; *unpack_uint64 = $unpack_uint64_slow || sub { return unpack( 'Q>', substr( $_[0], $_[1], 8 ) ); };
} }
# fixin package symbols
no warnings 'once';
sub pack :method;
sub unpack :method;
*Data::MessagePack::pack = \&pack;
*Data::MessagePack::unpack = \&unpack;
@Data::MessagePack::Unpacker::ISA = qw(Data::MessagePack::PP::Unpacker);
*true = \&Data::MessagePack::true;
*false = \&Data::MessagePack::false;
} }
sub _unexpected { sub _unexpected {
@ -130,10 +139,7 @@ sub _unexpected {
# PACK # PACK
# #
{ our $_max_depth;
no warnings 'recursion';
our $_max_depth;
sub pack :method { sub pack :method {
Carp::croak('Usage: Data::MessagePack->pack($dat [,$max_depth])') if @_ < 2; Carp::croak('Usage: Data::MessagePack->pack($dat [,$max_depth])') if @_ < 2;
@ -238,20 +244,19 @@ sub _pack {
} }
} # PACK
# #
# UNPACK # UNPACK
# #
{ my $p; # position variables for speed.
my $p; # position variables for speed.
sub unpack :method { sub unpack :method {
$p = 0; # init $p = 0; # init
_unpack( $_[1] ); my $data = _unpack( $_[1] );
if($p < length($_[1])) {
Carp::croak("Data::MessagePack->unpack: extra bytes");
}
return $data;
} }
@ -383,17 +388,12 @@ sub _unpack {
} }
} # UNPACK
# #
# Data::MessagePack::Unpacker # Data::MessagePack::Unpacker
# #
package package
Data::MessagePack::Unpacker; Data::MessagePack::PP::Unpacker;
use strict;
sub new { sub new {
bless { pos => 0 }, shift; bless { pos => 0 }, shift;
@ -404,10 +404,6 @@ sub execute_limit {
execute( @_ ); execute( @_ );
} }
{
my $p;
sub execute { sub execute {
my ( $self, $data, $offset, $limit ) = @_; my ( $self, $data, $offset, $limit ) = @_;
$offset ||= 0; $offset ||= 0;
@ -542,8 +538,6 @@ sub _count {
return 0; return 0;
} }
} # execute
sub data { sub data {
return Data::MessagePack->unpack( substr($_[0]->{ data }, 0, $_[0]->{pos}) ); return Data::MessagePack->unpack( substr($_[0]->{ data }, 0, $_[0]->{pos}) );