The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 011
MANIFEST 02
META.json 34
META.yml 23
Makefile.PL 320
README 219
lib/JSON/MaybeXS.pm 332
t/cpanel.t 22
t/lib/is_bool.pm 021
t/pp.t 02
t/preload_cpanel.t 02
t/preload_xs.t 02
t/xs.t 22
xt/json_pm.t 024
14 files changed (This is a version diff) 17146
@@ -1,5 +1,16 @@
 Revision history for JSON-MaybeXS
 
+1.002005 - 2014-10-12
+ - fix "can I haz XS?" logic precedence in Makefile.PL
+ - added the ':all' export tag
+ - removed dependency on Safe::Isa
+ - repository moved to git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git
+
+1.002004 - 2014-10-11
+ - support use of PUREPERL_ONLY in Makefile.PL to avoid adding an XS
+   dependency
+ - new is_bool() interface
+
 1.002003 - 2014-10-07
  - document how to use booleans
 
@@ -4,11 +4,13 @@ maint/Makefile.PL.include
 Makefile.PL
 MANIFEST			This list of files
 t/cpanel.t
+t/lib/is_bool.pm
 t/none.t
 t/pp.t
 t/preload_cpanel.t
 t/preload_xs.t
 t/xs.t
+xt/json_pm.t
 META.yml                                 Module YAML meta-data (added by MakeMaker)
 META.json                                Module JSON meta-data (added by MakeMaker)
 README                                   README file (added by Distar)
@@ -34,6 +34,7 @@
          },
          "requires" : {
             "JSON::PP" : "2.27202",
+            "Scalar::Util" : "0",
             "perl" : "5.006"
          }
       },
@@ -52,9 +53,9 @@
       },
       "repository" : {
          "type" : "git",
-         "url" : "https://github.com/karenetheridge/JSON-MaybeXS.git",
-         "web" : "https://github.com/karenetheridge/JSON-MaybeXS"
+         "url" : "git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git",
+         "web" : "http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/JSON-MaybeXS.git"
       }
    },
-   "version" : "1.002003"
+   "version" : "1.002005"
 }
@@ -25,8 +25,9 @@ recommends:
   Cpanel::JSON::XS: '2.3310'
 requires:
   JSON::PP: '2.27202'
+  Scalar::Util: '0'
   perl: '5.006'
 resources:
   bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS
-  repository: https://github.com/karenetheridge/JSON-MaybeXS.git
-version: '1.002003'
+  repository: git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git
+version: '1.002005'
@@ -11,9 +11,10 @@ my %WriteMakefileArgs = (
     'meta-spec' => { version => 2 },
     dynamic_config => 1,
     resources => {
+    # r/w: p5sagit@git.shadowcat.co.uk:JSON-MaybeXS.git
       repository => {
-        url => 'https://github.com/karenetheridge/JSON-MaybeXS.git',
-        web => 'https://github.com/karenetheridge/JSON-MaybeXS',
+        url => 'git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git',
+        web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/JSON-MaybeXS.git',
         type => 'git',
       },
       bugtracker => {
@@ -35,6 +36,7 @@ my %WriteMakefileArgs = (
       },
       runtime => {
         requires => {
+          'Scalar::Util' => '0',
           'JSON::PP' => '2.27202',
           # we may also add a runtime prereq for Cpanel::JSON::XS, on the
           # installer's machine
@@ -70,7 +72,9 @@ for (qw(configure build test runtime)) {
 # we require Cpanel::JSON::XS, except if JSON::XS is already installed.
 # (we also always recommend Cpanel::JSON::XS, just to make sure.)
 $WriteMakefileArgs{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'
-    if can_xs() && !eval { require JSON::XS; 1; };
+    if not parse_args()->{PUREPERL_ONLY}
+        and not eval { require JSON::XS; 1; }
+        and can_xs();
 
 $WriteMakefileArgs{MIN_PERL_VERSION} = delete $WriteMakefileArgs{PREREQ_PM}{perl} || 0;
 
@@ -101,6 +105,19 @@ delete $WriteMakefileArgs{LICENSE}
 
 WriteMakefile(%WriteMakefileArgs);
 
+
+sub parse_args {
+  # copied from EUMM
+  require ExtUtils::MakeMaker;
+  require Text::ParseWords;
+  ExtUtils::MakeMaker::parse_args(
+    my $tmp = {},
+    Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''),
+    @ARGV,
+  );
+  return $tmp->{ARGS} || {};
+}
+
 # can we locate a (the) C compiler
 sub can_cc {
   my @chunks = split(/ /, $Config::Config{cc}) or return;
@@ -28,14 +28,19 @@ DESCRIPTION
     mutators, so we provide our own "new" method that supports that.
 
 EXPORTS
-    All of "encode_json", "decode_json" and "JSON" are exported by default.
+    "encode_json", "decode_json" and "JSON" are exported by default;
+    "is_bool" is exported on request.
 
     To import only some symbols, specify them on the "use" line:
 
-      use JSON::MaybeXS qw(encode_json decode_json); # functions only
+      use JSON::MaybeXS qw(encode_json decode_json is_bool); # functions only
 
       use JSON::MaybeXS qw(JSON); # JSON constant only
 
+    To import all available symbols, use ":all":
+
+      use JSON::MaybeXS ':all';
+
   encode_json
     This is the "encode_json" function provided by the selected
     implementation module, and takes a perl data structure which is
@@ -60,6 +65,18 @@ EXPORTS
 
       my $data_structure = $json_obj->decode($json_text); # etc.
 
+  is_bool
+      $is_boolean = is_bool($scalar)
+
+    Returns true if the passed scalar represents either "true" or "false",
+    two constants that act like 1 and 0, respectively and are used to
+    represent JSON "true" and "false" values in Perl.
+
+    Since this is a bare sub in the various backend classes, it cannot be
+    called as a class method like the other interfaces; it must be called as
+    a function, with no invocant. It supports the representation used in all
+    JSON backends.
+
 CONSTRUCTOR
   new
     With JSON::PP, JSON::XS and Cpanel::JSON::XS you are required to call
@@ -4,7 +4,7 @@ use strict;
 use warnings FATAL => 'all';
 use base qw(Exporter);
 
-our $VERSION = '1.002003';
+our $VERSION = '1.002005';
 
 sub _choose_json_module {
     return 'Cpanel::JSON::XS' if $INC{'Cpanel/JSON/XS.pm'};
@@ -31,6 +31,8 @@ BEGIN {
 }
 
 our @EXPORT = qw(encode_json decode_json JSON);
+our @EXPORT_OK = qw(is_bool);
+our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_OK ] );
 
 sub JSON () { our $JSON_Class }
 
@@ -42,6 +44,16 @@ sub new {
   return $new;
 }
 
+use Scalar::Util ();
+
+sub is_bool {
+  die 'is_bool is not a method' if $_[1];
+
+  Scalar::Util::blessed($_[0])
+    and ($_[0]->isa('JSON::XS::Boolean')
+      or $_[0]->isa('JSON::PP::Boolean'));
+}
+
 1;
 
 =head1 NAME
@@ -77,14 +89,19 @@ we provide our own C<new> method that supports that.
 
 =head1 EXPORTS
 
-All of C<encode_json>, C<decode_json> and C<JSON> are exported by default.
+C<encode_json>, C<decode_json> and C<JSON> are exported by default; C<is_bool>
+is exported on request.
 
 To import only some symbols, specify them on the C<use> line:
 
-  use JSON::MaybeXS qw(encode_json decode_json); # functions only
+  use JSON::MaybeXS qw(encode_json decode_json is_bool); # functions only
 
   use JSON::MaybeXS qw(JSON); # JSON constant only
 
+To import all available symbols, use C<:all>:
+
+  use JSON::MaybeXS ':all';
+
 =head2 encode_json
 
 This is the C<encode_json> function provided by the selected implementation
@@ -110,6 +127,18 @@ and that object can then be used normally:
 
   my $data_structure = $json_obj->decode($json_text); # etc.
 
+=head2 is_bool
+
+  $is_boolean = is_bool($scalar)
+
+Returns true if the passed scalar represents either C<true> or
+C<false>, two constants that act like C<1> and C<0>, respectively
+and are used to represent JSON C<true> and C<false> values in Perl.
+
+Since this is a bare sub in the various backend classes, it cannot be called as
+a class method like the other interfaces; it must be called as a function, with
+no invocant.  It supports the representation used in all JSON backends.
+
 =head1 CONSTRUCTOR
 
 =head2 new
@@ -5,8 +5,6 @@ use JSON::MaybeXS;
 
 unless ( eval { require Cpanel::JSON::XS; 1 } ) {
     plan skip_all => 'No Cpanel::JSON::XS';
-    done_testing;
-    exit;
 }
 
 is( JSON, 'Cpanel::JSON::XS', 'Correct JSON class' );
@@ -21,4 +19,6 @@ is( \&decode_json,
     'Correct encode_json function'
 );
 
+require 't/lib/is_bool.pm';
+
 done_testing;
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+use Test::More;
+use JSON::MaybeXS;
+
+my $data = JSON::MaybeXS->new->decode('{"foo": true, "bar": false, "baz": 1}');
+ok(
+    JSON::MaybeXS::is_bool($data->{foo}),
+    JSON() . ': true decodes to a bool',
+);
+ok(
+    JSON::MaybeXS::is_bool($data->{bar}),
+    JSON() . ': false decodes to a bool',
+);
+ok(
+    !JSON::MaybeXS::is_bool($data->{baz}),
+    JSON() . ': int does not decode to a bool',
+);
+
+1;
@@ -17,4 +17,6 @@ is(
   'Correct encode_json function'
 );
 
+require 't/lib/is_bool.pm';
+
 done_testing;
@@ -16,4 +16,6 @@ is(
   'Correct encode_json function'
 );
 
+require 't/lib/is_bool.pm';
+
 done_testing;
@@ -9,4 +9,6 @@ is( JSON, 'JSON::XS', 'Correct JSON class' );
 is( \&encode_json, \&JSON::XS::encode_json, 'Correct encode_json function' );
 is( \&decode_json, \&JSON::XS::decode_json, 'Correct encode_json function' );
 
+require 't/lib/is_bool.pm';
+
 done_testing;
@@ -7,8 +7,6 @@ use JSON::MaybeXS;
 
 unless ( eval { require JSON::XS; 1 } ) {
     plan skip_all => 'No JSON::XS';
-    done_testing;
-    exit;
 }
 
 is( JSON, 'JSON::XS', 'Correct JSON class' );
@@ -16,4 +14,6 @@ is( JSON, 'JSON::XS', 'Correct JSON class' );
 is( \&encode_json, \&JSON::XS::encode_json, 'Correct encode_json function' );
 is( \&decode_json, \&JSON::XS::decode_json, 'Correct encode_json function' );
 
+require 't/lib/is_bool.pm';
+
 done_testing;
@@ -0,0 +1,24 @@
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+
+unless ( eval { require JSON; 1 } ) {
+    plan skip_all => 'No JSON';
+}
+
+my $data = JSON->new->decode('{"foo": true, "bar": false, "baz": 1}');
+
+ok(
+    JSON::is_bool($data->{foo}),
+    'JSON.pm: true decodes to a bool',
+);
+ok(
+    JSON::is_bool($data->{bar}),
+    'JSON.pm:: false decodes to a bool',
+);
+ok(
+    !JSON::is_bool($data->{baz}),
+    'JSON.pm: int does not decode to a bool',
+);
+
+done_testing;