Created
August 26, 2013 10:42
-
-
Save anonymous/6340200 to your computer and use it in GitHub Desktop.
Funny Mojo::JSON FLAGS handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
no warnings 'uninitialized'; | |
use Mojo::JSON; | |
use Data::Dump 'pp'; | |
use B; | |
my $data = { 'string' => 'Mojolicious', 'number' => 42, }; | |
# run as: | |
# perl flagsbug.pl | |
# perl flagsbug.pl pp | |
# perl flagsbug.pl num | |
# The first one is OK, the pp one exhibits the problem, | |
# the num one shows why the problem appears... | |
my $flags = B::svref_2object(\$data->{string})->FLAGS; | |
printf("Original: flags: %08x, SVp_IOK: %08x, SVp_NOK: %08x, flags&(IOK|NOK): %08x\n", | |
$flags, B::SVp_IOK, B::SVp_NOK, $flags & (B::SVp_IOK | B::SVp_NOK)); | |
if ($ARGV[0] eq "pp") { | |
pp($data); | |
} elsif ($ARGV[0] eq "num") { | |
no warnings 'numeric'; | |
if ($data->{string} + 0 eq $data->{string}) { | |
print "String is a number\n"; | |
} else { | |
print "String is not a number\n"; | |
} | |
} | |
$flags = B::svref_2object(\$data->{string})->FLAGS; | |
printf("Possibly modified: flags: %08x, SVp_IOK: %08x, SVp_NOK: %08x, flags&(IOK|NOK): %08x\n", | |
$flags, B::SVp_IOK, B::SVp_NOK, $flags & (B::SVp_IOK | B::SVp_NOK)); | |
print Mojo::JSON->new->encode($data), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment