summaryrefslogtreecommitdiff
path: root/perl/lib/Data
diff options
context:
space:
mode:
authormakamaka <makamaka.donzoko@gmail.com>2010-09-01 11:59:01 +0900
committermakamaka <makamaka.donzoko@gmail.com>2010-09-01 11:59:01 +0900
commita0705a6c67e852154e92bb16876ac9e950a8f044 (patch)
treef6e18f11d88d1d4326e4e679207e1724071d1e4f /perl/lib/Data
parent712b8eec3d90f7e61908cb32c4433ee38a5f1848 (diff)
downloadmsgpack-python-a0705a6c67e852154e92bb16876ac9e950a8f044.tar.gz
added PP backend switch into Data::MessagePack
Diffstat (limited to 'perl/lib/Data')
-rw-r--r--perl/lib/Data/MessagePack.pm15
-rw-r--r--perl/lib/Data/MessagePack/PP.pm33
2 files changed, 28 insertions, 20 deletions
diff --git a/perl/lib/Data/MessagePack.pm b/perl/lib/Data/MessagePack.pm
index 276353a..a3f8264 100644
--- a/perl/lib/Data/MessagePack.pm
+++ b/perl/lib/Data/MessagePack.pm
@@ -1,7 +1,6 @@
package Data::MessagePack;
use strict;
use warnings;
-use XSLoader;
use 5.008001;
our $VERSION = '0.15';
@@ -12,7 +11,19 @@ our $false = do { bless \(my $dummy = 0), "Data::MessagePack::Boolean" };
sub true () { $true }
sub false () { $false }
-XSLoader::load(__PACKAGE__, $VERSION);
+if ( !__PACKAGE__->can('pack') ) { # this idea comes from Text::Xslate
+ if ( $ENV{ PERL_DATA_MESSAGEPACK } !~ /\b pp \b/xms ) {
+ eval {
+ require XSLoader;
+ XSLoader::load(__PACKAGE__, $VERSION);
+ };
+ die $@ if $@ && $ENV{ PERL_DATA_MESSAGEPACK } =~ /\b xs \b/xms; # force XS
+ }
+ if ( !__PACKAGE__->can('pack') ) {
+ print "PP\n";
+ require 'Data/MessagePack/PP.pm';
+ }
+}
1;
__END__
diff --git a/perl/lib/Data/MessagePack/PP.pm b/perl/lib/Data/MessagePack/PP.pm
index f4f1060..ecb97b4 100644
--- a/perl/lib/Data/MessagePack/PP.pm
+++ b/perl/lib/Data/MessagePack/PP.pm
@@ -2,21 +2,9 @@ package Data::MessagePack::PP;
use 5.008000;
use strict;
-use B ();
-use Scalar::Util qw( blessed );
use Carp ();
-our $VERSION = '0.03';
-
-
-# copied from Data::MessagePack
-our $true = do { bless \(my $dummy = 1), "Data::MessagePack::Boolean" };
-our $false = do { bless \(my $dummy = 0), "Data::MessagePack::Boolean" };
-
-sub true () { $true }
-sub false () { $false }
-
-our $PreferInteger;
+our $VERSION = '0.15';
# See also
# http://redmine.msgpack.org/projects/msgpack/wiki/FormatSpec
@@ -24,6 +12,13 @@ our $PreferInteger;
# http://frox25.no-ip.org/~mtve/wiki/MessagePack.html : reference to using CORE::pack, CORE::unpack
+package
+ Data::MessagePack;
+
+use Scalar::Util qw( blessed );
+use strict;
+use B ();
+
BEGIN {
# for pack and unpack compatibility
if ( $] < 5.010 ) {
@@ -160,11 +155,11 @@ sub _pack {
elsif ( $flags & B::SVf_POK ) { # raw / check needs before dboule
- if ( $PreferInteger ) {
+ if ( $Data::MessagePack::PreferInteger ) {
if ( $value =~ /^-?[0-9]+$/ ) { # ok?
my $value2 = 0 + $value;
if ( 0 + $value != B::svref_2object( \$value2 )->int_value ) {
- local $PreferInteger; # avoid for PV => NV
+ local $Data::MessagePack::PreferInteger; # avoid for PV => NV
return _pack( "$value" );
}
return _pack( $value + 0 );
@@ -346,7 +341,8 @@ sub _unpack {
# Data::MessagePack::Unpacker
#
-package Data::MessagePack::PP::Unpacker;
+package
+ Data::MessagePack::Unpacker;
use strict;
@@ -530,7 +526,7 @@ __END__
=head1 NAME
-Data::MessagePack::PP - the pure perl version of Data::MessagePack
+Data::MessagePack::PP - Pure Perl version of Data::MessagePack
=head1 LIMITATION
@@ -540,9 +536,10 @@ In Perl 5.8.x, it requires L<Data::Float> and cannot unpack int64 and float (pac
=head1 SEE ALSO
+L<http://msgpack.sourceforge.jp/>,
L<Data::MessagePack>,
+L<Data::Float>,
L<http://frox25.no-ip.org/~mtve/wiki/MessagePack.html>,
-L<Data::Float>
=head1 AUTHOR