diff options
| author | Fuji, Goro <gfuji@cpan.org> | 2010-10-13 11:02:57 +0900 |
|---|---|---|
| committer | Fuji, Goro <gfuji@cpan.org> | 2010-10-13 11:02:57 +0900 |
| commit | ef0874feba7ac35a5cd4a6fd8763abf2cb1de40e (patch) | |
| tree | 07ac2b798e58a19479e0b2fa17ab3b786ae5437c /perl/lib | |
| parent | 14aa1420f0142f49beb6114599c27f665b34a075 (diff) | |
| download | msgpack-python-ef0874feba7ac35a5cd4a6fd8763abf2cb1de40e.tar.gz | |
perl: tweaks for PreferInteger
Diffstat (limited to 'perl/lib')
| -rw-r--r-- | perl/lib/Data/MessagePack/PP.pm | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/perl/lib/Data/MessagePack/PP.pm b/perl/lib/Data/MessagePack/PP.pm index 3aedf4c..30b963b 100644 --- a/perl/lib/Data/MessagePack/PP.pm +++ b/perl/lib/Data/MessagePack/PP.pm @@ -214,15 +214,18 @@ sub _pack { if ( $Data::MessagePack::PreferInteger ) { if ( $value =~ /^-?[0-9]+$/ ) { # ok? - my $value2 = 0 + $value; - if ( $value > 0xFFFFFFFF or $value < '-'.0x80000000 or # <- needless but for XS compat - 0 + $value != B::svref_2object( \$value2 )->int_value - ) { - local $Data::MessagePack::PreferInteger; # avoid for PV => NV - return _pack( "$value" ); + # checks whether $value is in (u)int32 + my $ivalue = 0 + $value; + if (!( + $ivalue > 0xFFFFFFFF + or $ivalue < '-'.0x80000000 # for XS compat + or $ivalue != B::svref_2object(\$ivalue)->int_value + )) { + return _pack( $ivalue ); } - return _pack( $value + 0 ); + # fallthrough } + # fallthrough } utf8::encode( $value ) if utf8::is_utf8( $value ); |
