Skip to content

Commit

Permalink
Use JSON::PP as an explicit fallback.
Browse files Browse the repository at this point in the history
As @pstadt noticed, it has been included in core since perl v5.13.9. So it
should make a safe fallback in case JSON::MaybeXS is not installed.
  • Loading branch information
guillaumeaubert committed Oct 27, 2014
1 parent 4d268b7 commit 1dc0684
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions t/31-enqueue-json.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,34 @@ use LocalTest;
use Queue::DBI;


# Only run this test if a JSON module is available.
# Important: only run this test if a JSON module is available.
my $json_module;

# Check if JSON::MaybeXS is installed, which allows using either
# Cpanel::JSON::XS, JSON::XS, or JSON::PP.
eval "use JSON::MaybeXS";
plan( skip_all => "JSON::MaybeXS is not installed." )
if $@;
if ( !$@ )
{
$json_module = 'JSON::MaybeXS';
}
else
{
# Fall back on JSON::PP if JSON::MaybeXS wasn't found, as it became a core
# module starting with perl v5.13.9.
eval "use JSON::PP";
$json_module = 'JSON::PP'
if !$@;
}
plan( skip_all => "Neither JSON::MaybeXS nor JSON::PP are installed." )
if !defined( $json_module );

diag( "Using $json_module for testing JSON serialization." );

# Start testing.
plan( tests => 12 );

my $dbh = LocalTest::ok_database_handle();
my $json = JSON::MaybeXS->new();
my $json = $json_module->new();

# Instantiate the queue object.
my $queue;
Expand Down

0 comments on commit 1dc0684

Please sign in to comment.