diff --git a/perl/Changes b/perl/Changes index 189990a8..a8a4298c 100644 --- a/perl/Changes +++ b/perl/Changes @@ -1,3 +1,9 @@ + +0.1x + + - added PP version. + (makamaka) + 0.15 - better argument validation. diff --git a/perl/lib/Data/MessagePack.pm b/perl/lib/Data/MessagePack.pm index 276353a2..a3f8264e 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 f4f1060f..ecb97b46 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 and cannot unpack int64 and float (pac =head1 SEE ALSO +L, L, +L, L, -L =head1 AUTHOR