summaryrefslogtreecommitdiff
path: root/perl/lib/Data/MessagePack
diff options
context:
space:
mode:
authorgfx <gfuji@cpan.org>2010-09-22 15:59:21 +0900
committergfx <gfuji@cpan.org>2010-09-22 15:59:21 +0900
commit0a8a6ed168dfd9338c2e97fd6b87b88ef39644ef (patch)
tree396fe082d754ca832e292fab10b94b6d750d567c /perl/lib/Data/MessagePack
parent68b6fa46e61490c3f5fdca71b3e1dc90ebb4a02d (diff)
downloadmsgpack-python-0a8a6ed168dfd9338c2e97fd6b87b88ef39644ef.tar.gz
perl: cleanup PP
Diffstat (limited to 'perl/lib/Data/MessagePack')
-rw-r--r--perl/lib/Data/MessagePack/PP.pm54
1 files changed, 24 insertions, 30 deletions
diff --git a/perl/lib/Data/MessagePack/PP.pm b/perl/lib/Data/MessagePack/PP.pm
index 8234b49..5dccc0b 100644
--- a/perl/lib/Data/MessagePack/PP.pm
+++ b/perl/lib/Data/MessagePack/PP.pm
@@ -1,20 +1,17 @@
package Data::MessagePack::PP;
use 5.008001;
use strict;
+use warnings;
+no warnings 'recursion';
+
use Carp ();
+use B ();
# See also
# 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://frox25.no-ip.org/~mtve/wiki/MessagePack.html : reference to using CORE::pack, CORE::unpack
-
-package
- Data::MessagePack;
-
-use strict;
-use B ();
-
BEGIN {
my $unpack_int64_slow;
my $unpack_uint64_slow;
@@ -120,6 +117,18 @@ BEGIN {
*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 ) ); };
}
+
+ # 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 {
@@ -130,10 +139,7 @@ sub _unexpected {
# PACK
#
-{
- no warnings 'recursion';
-
- our $_max_depth;
+our $_max_depth;
sub pack :method {
Carp::croak('Usage: Data::MessagePack->pack($dat [,$max_depth])') if @_ < 2;
@@ -238,20 +244,19 @@ sub _pack {
}
-} # PACK
-
-
#
# UNPACK
#
-{
-
- my $p; # position variables for speed.
+my $p; # position variables for speed.
sub unpack :method {
$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
#
package
- Data::MessagePack::Unpacker;
-
-use strict;
+ Data::MessagePack::PP::Unpacker;
sub new {
bless { pos => 0 }, shift;
@@ -404,10 +404,6 @@ sub execute_limit {
execute( @_ );
}
-
-{
- my $p;
-
sub execute {
my ( $self, $data, $offset, $limit ) = @_;
$offset ||= 0;
@@ -542,8 +538,6 @@ sub _count {
return 0;
}
-} # execute
-
sub data {
return Data::MessagePack->unpack( substr($_[0]->{ data }, 0, $_[0]->{pos}) );