1#!/usr/bin/perl -w 2 3use strict; 4use Test::More; 5eval "use JSON::Any"; 6 7if ($@) { 8 plan skip_all => "$@"; 9} 10else { 11 plan no_plan => 1; 12} 13 14SKIP: { 15 eval { require JSON; }; 16 skip "JSON not installed: $@", 1 if $@; 17 18 $ENV{JSON_ANY_ORDER} = qw(JSON); 19 JSON::Any->import(); 20 skip "JSON not installed: $@", 1 if $@; 21 is_deeply( $ENV{JSON_ANY_ORDER}, qw(JSON) ); 22 is( JSON::Any->handlerType, 'JSON' ); 23} 24 25SKIP: { 26 eval { require JSON::XS; }; 27 skip "JSON::XS not installed: $@", 1 if $@; 28 29 $ENV{JSON_ANY_ORDER} = qw(XS); 30 31 JSON::Any->import(); 32 is( JSON::Any->handlerType, 'JSON::XS' ); 33 34 my ($json); 35 ok( $json = JSON::Any->new() ); 36 eval { $json->encode("�") }; 37 ok( $@, 'trapped a failure' ); 38 undef $@; 39 $ENV{JSON_ANY_CONFIG} = 'allow_nonref=1'; 40 ok( $json = JSON::Any->new() ); 41 ok( $json->encode("dahut"), qq["dahut"] ); 42 is( $@, undef, 'no failure' ); 43} 44