JSON-MaybeXS-1.004003/000750 000000 000000 00000000000 13753406177 014127 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/Changes000644 000000 000000 00000007124 13753406107 015424 0ustar00rootwheel000000 000000 Revision history for JSON-MaybeXS 1.004003 - 2020-11-13 - fix another test that fails when JSON::XS is installed, but below version 3.0 1.004002 - 2020-05-17 - fix test that fails when JSON::XS is installed, but below version 3.0 (RT#132578) 1.004001 - 2020-05-01 - document when is_bool became available - now favouring Cpanel::JSON::XS over JSON::XS in more situations (the former is always added to prereqs when a compiler is available, although JSON::XS is still used at runtime if new enough and Cpanel::JSON::XS is not installed). This makes boolean handling more predictable and consistent. 1.004000 - 2018-04-19 - added true and false subs so they can be used via JSON::MaybeXS rather than only JSON() exported sub. 1.003010 - 2018-01-28 - use bundled ExtUtils::HasCompiler rather than ExtUtils::CBuilder to detect compiler availability. - clarify exported JSON in documentation 1.003009 - 2017-02-27 - fix tests to no longer rely on . being in @INC (RT#120404) 1.003008 - 2016-10-03 - added an INSTALLATION section to documentation, to clarify the use of dynamic prerequisites in Makefile.PL - minimize prereqs listed in META.json to avoid giving the appearance of XS prerequisites, and confusing static inspection tools such as metacpan.org. 1.003007 - 2016-09-11 - no changes since 1.003006_001 1.003006_001 - 2016-06-28 - bump prereq on JSON::PP, to ensure we get the fix for parsing utf8-encoded values (in JSON::PP 2.27300) - we now always upgrade JSON::XS if it is installed and below version 3.0, due to changes in handling booleans - remove test dependency on Test::Without::Module (RT#115394) 1.003005 - 2015-03-22 - fix x_contributors metadata that was killing metacpan (see https://github.com/CPAN-API/cpan-api/issues/401) 1.003004 - 2015-03-14 - caveat added to documentation about type checking the object returned by new() (John SJ Anderson, RT#102733) 1.003003 - 2014-12-06 - ensure an old Cpanel::JSON::XS is upgraded if it is too old, as it will always be used in preference to JSON::XS - avoid "JSON::XS::Boolean::* redefined" warnings caused by an old JSON::XS loaded at the same time as a newer Cpanel::JSON::XS 1.003002 - 2014-11-16 - correctly fix boolean interoperability with older Cpanel::JSON::MaybeXS 1.003001 - 2014-11-13 - fix boolean interoperability with older Cpanel::JSON::MaybeXS 1.003_000 - 2014-10-30 - add :legacy tag to support legacy apps 1.002006 - 2014-10-22 - add some additional test diagnostics, to help find bad version combinations of JSON backends 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 1.002002 - 2014-04-23 - more metadata fiddling, to remove the Cpanel::JSON::XS dependency visible to static analyzers (the prequisites at install time remain unchanged) 1.002001 - 2014-04-23 - fix installation on older perls with an older ExtUtils::MakeMaker (RT#94964) 1.002000 - 2014-04-22 - Now also supports JSON::XS, when available: Cpanel::JSON::XS will only be installed when there is no XS backend already installed; Cpanel::JSON::XS will be used over JSON::XS when both are installed. 1.001000 - 2013-12-11 - Add a constructor for people who want to forget how silly the JSON API is 1.000000 - 2013-05-22 - Released on an unsuspecting world. JSON-MaybeXS-1.004003/LICENSE000660 000000 000000 00000043507 13753406177 015150 0ustar00rootwheel000000 000000 Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2020 by mst - Matt S. Trout (cpan:MSTROUT) . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2020 by mst - Matt S. Trout (cpan:MSTROUT) . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End JSON-MaybeXS-1.004003/MANIFEST000644 000000 000000 00000001144 13753406177 015265 0ustar00rootwheel000000 000000 Changes inc/ExtUtils/HasCompiler.pm lib/JSON/MaybeXS.pm maint/Makefile.PL.include Makefile.PL MANIFEST This list of files t/cpanel.t t/legacy.t t/lib/is_bool.pm t/new.t t/none.t t/pp.t t/preload_cpanel.t t/preload_xs.t t/xs.t xt/json_pm.t xt/json_pm_legacy.t xt/json_pp_legacy.t xt/json_xs_legacy.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) LICENSE LICENSE file (added by Distar) JSON-MaybeXS-1.004003/META.json000660 000000 000000 00000004020 13753406177 015547 0ustar00rootwheel000000 000000 { "abstract" : "Use L with a fallback to L and L", "author" : [ "mst - Matt S. Trout (cpan:MSTROUT) " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.4706, CPAN::Meta::Converter version 2.150010", "keywords" : [ "json", "serializer", "serialiser", "data" ], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "JSON-MaybeXS", "no_index" : { "directory" : [ "t", "xt" ] }, "prereqs" : { "build" : {}, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "recommends" : { "Cpanel::JSON::XS" : "2.3310" }, "requires" : { "Carp" : "0", "JSON::PP" : "2.27300", "Scalar::Util" : "0", "perl" : "5.006" } }, "test" : { "requires" : { "Test::More" : "0.88", "Test::Needs" : "0.002006" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-JSON-MaybeXS@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS" }, "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "https://github.com/p5sagit/JSON-MaybeXS.git", "web" : "https://github.com/p5sagit/JSON-MaybeXS" } }, "version" : "1.004003", "x_contributors" : [ "Clinton Gormley ", "Graham Knop ", "John SJ Anderson ", "Karen Etheridge ", "Kieren Diment ", "Matt S Trout " ], "x_serialization_backend" : "JSON::MaybeXS version 1.004002" } JSON-MaybeXS-1.004003/META.yml000660 000000 000000 00000002342 13753406176 015403 0ustar00rootwheel000000 000000 --- abstract: 'Use L with a fallback to L and L' author: - 'mst - Matt S. Trout (cpan:MSTROUT) ' build_requires: Test::More: '0.88' Test::Needs: '0.002006' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.4706, CPAN::Meta::Converter version 2.150010' keywords: - json - serializer - serialiser - data license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: JSON-MaybeXS no_index: directory: - t - xt recommends: Cpanel::JSON::XS: '2.3310' requires: Carp: '0' JSON::PP: '2.27300' Scalar::Util: '0' perl: '5.006' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS license: http://dev.perl.org/licenses/ repository: https://github.com/p5sagit/JSON-MaybeXS.git version: '1.004003' x_contributors: - 'Clinton Gormley ' - 'Graham Knop ' - 'John SJ Anderson ' - 'Karen Etheridge ' - 'Kieren Diment ' - 'Matt S Trout ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' JSON-MaybeXS-1.004003/Makefile.PL000644 000000 000000 00000010032 13660344227 016074 0ustar00rootwheel000000 000000 use strict; use warnings FATAL => 'all'; use 5.006; use lib 'inc'; use ExtUtils::HasCompiler qw(can_compile_loadable_object); use ExtUtils::MakeMaker; my %META = ( name => 'JSON-MaybeXS', license => 'perl_5', dynamic_config => 1, prereqs => { configure => { requires => { 'ExtUtils::MakeMaker' => '0', }, }, runtime => { requires => { 'Scalar::Util' => '0', 'Carp' => '0', 'JSON::PP' => '2.27300', # we may also add a runtime prereq for Cpanel::JSON::XS, on the # installer's machine perl => '5.006', }, recommends => { 'Cpanel::JSON::XS' => '2.3310' }, }, test => { requires => { 'Test::More' => '0.88', 'Test::Needs' => '0.002006', }, }, }, resources => { # GitHub mirrors from Shadowcat. We list it so we can get pull requests. # The canonical repo is: # r/o: git://git.shadowcat.co.uk/p5sagit/JSON-MaybeXS.git # r/w: p5sagit@git.shadowcat.co.uk:JSON-MaybeXS.git # web: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/JSON-MaybeXS.git repository => { url => 'https://github.com/p5sagit/JSON-MaybeXS.git', web => 'https://github.com/p5sagit/JSON-MaybeXS', type => 'git', }, bugtracker => { mailto => 'bug-JSON-MaybeXS@rt.cpan.org', web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-MaybeXS', }, license => [ 'http://dev.perl.org/licenses/' ], }, x_contributors => [ # manually added, from git shortlog -e -s -n 'Clinton Gormley ', 'Graham Knop ', 'John SJ Anderson ', 'Karen Etheridge ', 'Kieren Diment ', 'Matt S Trout ', ], keywords => [ qw(json serializer serialiser data) ], no_index => { directory => [ 't', 'xt' ] }, ); my %MM_ARGS = (); ## DYNAMIC PREREQS ########################################################### if (! parse_args()->{PUREPERL_ONLY} && can_compile_loadable_object(quiet => 1)) { $MM_ARGS{PREREQ_PM}{'Cpanel::JSON::XS'} = '2.3310'; } use Text::ParseWords; sub parse_args { # copied from EUMM ExtUtils::MakeMaker::parse_args( my $tmp = {}, Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''), @ARGV, ); return $tmp->{ARGS} || {}; } ## BOILERPLATE ############################################################### require ExtUtils::MakeMaker; (do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; # have to do this since old EUMM dev releases miss the eval $VERSION line my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; my $mymeta = $eumm_version >= 6.57_02; my $mymeta_broken = $mymeta && $eumm_version < 6.57_07; ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g; ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g; $META{license} = [ $META{license} ] if $META{license} && !ref $META{license}; $MM_ARGS{LICENSE} = $META{license}[0] if $META{license} && $eumm_version >= 6.30; $MM_ARGS{NO_MYMETA} = 1 if $mymeta_broken; $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META } unless -f 'META.yml'; $MM_ARGS{PL_FILES} ||= {}; $MM_ARGS{NORECURS} = 1 if not exists $MM_ARGS{NORECURS}; for (qw(configure build test runtime)) { my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; my $r = $MM_ARGS{$key} = { %{$META{prereqs}{$_}{requires} || {}}, %{delete $MM_ARGS{$key} || {}}, }; defined $r->{$_} or delete $r->{$_} for keys %$r; } $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0; delete $MM_ARGS{MIN_PERL_VERSION} if $eumm_version < 6.47_01; $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}} if $eumm_version < 6.63_03; $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}} if $eumm_version < 6.55_01; delete $MM_ARGS{CONFIGURE_REQUIRES} if $eumm_version < 6.51_03; ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS); ## END BOILERPLATE ########################################################### JSON-MaybeXS-1.004003/README000660 000000 000000 00000016346 13753406177 015024 0ustar00rootwheel000000 000000 NAME JSON::MaybeXS - Use Cpanel::JSON::XS with a fallback to JSON::XS and JSON::PP SYNOPSIS use JSON::MaybeXS; my $data_structure = decode_json($json_input); my $json_output = encode_json($data_structure); my $json = JSON()->new; my $json_with_args = JSON::MaybeXS->new(utf8 => 1); # or { utf8 => 1 } DESCRIPTION This module first checks to see if either Cpanel::JSON::XS or JSON::XS (at at least version 3.0) is already loaded, in which case it uses that module. Otherwise it tries to load Cpanel::JSON::XS, then JSON::XS, then JSON::PP in order, and either uses the first module it finds or throws an error. It then exports the "encode_json" and "decode_json" functions from the loaded module, along with a "JSON" constant that returns the class name for calling "new" on. If you're writing fresh code rather than replacing JSON.pm usage, you might want to pass options as constructor args rather than calling mutators, so we provide our own "new" method that supports that. EXPORTS "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 is_bool); # functions only use JSON::MaybeXS qw(JSON); # JSON constant only To import all available sensible symbols ("encode_json", "decode_json", and "is_bool"), use ":all": use JSON::MaybeXS ':all'; To import all symbols including those needed by legacy apps that use JSON::PP: use JSON::MaybeXS ':legacy'; This imports the "to_json" and "from_json" symbols as well as everything in ":all". NOTE: This is to support legacy code that makes extensive use of "to_json" and "from_json" which you are not yet in a position to refactor. DO NOT use this import tag in new code, in order to avoid the crawling horrors of getting UTF-8 support subtly wrong. See the documentation for JSON for further details. encode_json This is the "encode_json" function provided by the selected implementation module, and takes a perl data structure which is serialised to JSON text. my $json_text = encode_json($data_structure); decode_json This is the "decode_json" function provided by the selected implementation module, and takes a string of JSON text to deserialise to a perl data structure. my $data_structure = decode_json($json_text); to_json, from_json See JSON for details. These are included to support legacy code only. JSON The "JSON" constant returns the selected implementation module's name for use as a class name - so: my $json_obj = JSON()->new; # returns a Cpanel::JSON::XS or JSON::PP object and that object can then be used normally: my $data_structure = $json_obj->decode($json_text); # etc. The use of parentheses here is optional, and only used as a hint to the reader that this use of "JSON" is a *subroutine* call, *not* a class name. 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. Available since version 1.002004. CONSTRUCTOR new With JSON::PP, JSON::XS and Cpanel::JSON::XS you are required to call mutators to set options, such as: my $json = $class->new->utf8(1)->pretty(1); Since this is a trifle irritating and noticeably un-perlish, we also offer: my $json = JSON::MaybeXS->new(utf8 => 1, pretty => 1); which works equivalently to the above (and in the usual tradition will accept a hashref instead of a hash, should you so desire). The resulting object is blessed into the underlying backend, which offers (at least) the methods "encode" and "decode". BOOLEANS To include JSON-aware booleans ("true", "false") in your data, just do: use JSON::MaybeXS; my $true = JSON()->true; my $false = JSON()->false; The booleans are also available as subs or methods on JSON::MaybeXS. use JSON::MaybeXS (); my $true = JSON::MaybeXS::true; my $true = JSON::MaybeXS->true; my $false = JSON::MaybeXS::false; my $false = JSON::MaybeXS->false; CONVERTING FROM JSON::Any JSON::Any used to be the favoured compatibility layer above the various JSON backends, but over time has grown a lot of extra code to deal with legacy backends (e.g. JSON::Syck) that are no longer needed. This is a rough guide of translating such code: Change code from: use JSON::Any; my $json = JSON::Any->new->objToJson($data); # or to_json($data), or Dump($data) to: use JSON::MaybeXS; my $json = encode_json($data); Change code from: use JSON::Any; my $data = JSON::Any->new->jsonToObj($json); # or from_json($json), or Load($json) to: use JSON::MaybeXS; my $json = decode_json($data); CAVEATS The "new()" method in this module is technically a factory, not a constructor, because the objects it returns will *NOT* be blessed into the "JSON::MaybeXS" class. If you are using an object returned by this module as a Moo(se) attribute, this type constraint code: is 'json' => ( isa => 'JSON::MaybeXS' ); will *NOT* do what you expect. Instead, either rely on the "JSON" class constant described above, as so: is 'json' => ( isa => JSON::MaybeXS::JSON() ); Alternatively, you can use duck typing: use Moose::Util::TypeConstraints 'duck_type'; is 'json' => ( isa => Object , duck_type([qw/ encode decode /])); INSTALLATION At installation time, Makefile.PL will attempt to determine if you have a working compiler available, and therefore whether you are able to run XS code. If so, Cpanel::JSON::XS will be added to the prerequisite list, unless JSON::XS is already installed at a high enough version. JSON::XS may also be upgraded to fix any incompatibility issues. Because running XS code is not mandatory and JSON::PP (which is in perl core) is used as a fallback backend, this module is safe to be used in a suite of code that is fatpacked or installed into a restricted-resource environment. You can also prevent any XS dependencies from being installed by setting "PUREPERL_ONLY=1" in Makefile.PL options (or in the "PERL_MM_OPT" environment variable), or using the "--pp" or "--pureperl" flags with the cpanminus client. AUTHOR mst - Matt S. Trout (cpan:MSTROUT) CONTRIBUTORS * Clinton Gormley * Karen Etheridge * Kieren Diment COPYRIGHT Copyright (c) 2013 the "JSON::MaybeXS" "AUTHOR" and "CONTRIBUTORS" as listed above. LICENSE This library is free software and may be distributed under the same terms as perl itself. JSON-MaybeXS-1.004003/inc/000750 000000 000000 00000000000 13753406176 014677 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/lib/000750 000000 000000 00000000000 13753406176 014674 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/maint/000750 000000 000000 00000000000 13753406176 015236 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/t/000750 000000 000000 00000000000 13753406176 014371 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/xt/000750 000000 000000 00000000000 13753406176 014561 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/xt/json_pm.t000644 000000 000000 00000000730 13400027311 016373 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::More; unless ( eval { require JSON; 1 } ) { plan skip_all => 'No JSON'; } use JSON::MaybeXS; 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; JSON-MaybeXS-1.004003/xt/json_pm_legacy.t000644 000000 000000 00000002470 13653052325 017737 0ustar00rootwheel000000 000000 use warnings; use strict; use Test::More; # some tests to check JSON::PP versus JSON::MaybeXS for legacy methods unless ( eval { require JSON; 1 }) { plan skip_all => 'No JSON'; } use JSON::MaybeXS qw/:legacy/; use Encode; use utf8; my @hovercraft = ( 'My hovercraft is full of eels', 'Automjeti im është plot me ngjala', 'حَوّامتي مُمْتِلئة بِأَنْقَلَيْسون', ' Маё судна на паветранай падушцы поўна вуграмі', '我的氣墊船裝滿了鱔魚 ', 'Il mio hovercraft/aeroscivolante è pieno di anguille', 'សុទ្ធតែឣន្ចងពេញទូកហាះយើង ។', "Tá m'árthach foluaineach lán d'eascanna." ); foreach my $h (@hovercraft) { $h = '["' . $h . '"]'; my $j_perl = JSON::from_json($h); my $j_json = JSON::to_json($j_perl); my $h_enc = Encode::encode_utf8($h); my $j_perl_enc = JSON::from_json($h_enc); my $j_json_enc = JSON::to_json($j_perl_enc); my $jm_perl = from_json($h); my $jm_json = to_json($jm_perl); my $jm_perl_enc = from_json($h_enc); my $jm_json_enc = to_json($jm_perl_enc); is_deeply($j_perl, $jm_perl); is_deeply($j_perl_enc, $jm_perl_enc); is ($j_json, $jm_json); is ($j_json_enc, $jm_json_enc); } done_testing(); JSON-MaybeXS-1.004003/xt/json_pp_legacy.t000644 000000 000000 00000000143 13400027077 017731 0ustar00rootwheel000000 000000 use strict; use warnings; $ENV{PERL_JSON_BACKEND} = 'JSON::PP'; require './xt/json_pm_legacy.t'; JSON-MaybeXS-1.004003/xt/json_xs_legacy.t000644 000000 000000 00000000143 13400027077 017744 0ustar00rootwheel000000 000000 use strict; use warnings; $ENV{PERL_JSON_BACKEND} = 'JSON::XS'; require './xt/json_pm_legacy.t'; JSON-MaybeXS-1.004003/t/cpanel.t000644 000000 000000 00000000705 13660344050 016014 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::More 0.88; use JSON::MaybeXS; use Test::Needs 'Cpanel::JSON::XS'; diag 'Using Cpanel::JSON::XS ', Cpanel::JSON::XS->VERSION; is( JSON, 'Cpanel::JSON::XS', 'Correct JSON class' ); is( \&encode_json, \&Cpanel::JSON::XS::encode_json, 'Correct encode_json function' ); is( \&decode_json, \&Cpanel::JSON::XS::decode_json, 'Correct encode_json function' ); require './t/lib/is_bool.pm'; done_testing; JSON-MaybeXS-1.004003/t/legacy.t000644 000000 000000 00000002364 13400027077 016020 0ustar00rootwheel000000 000000 use strict; use warnings; # hide Cpanel::JSON::XS use lib map { my $m = $_; sub { return unless $_[1] eq $m; die "Can't locate $m in \@INC (hidden).\n" }; } qw{Cpanel/JSON/XS.pm}; use Test::More 0.88; use JSON::MaybeXS qw/:legacy/; my $in = '[1, 2, 3, 4]'; my $arr = from_json($in); my $j = to_json($arr); is($j, '[1,2,3,4]'); is(ref($arr), 'ARRAY'); my $json = 'JSON::MaybeXS'; diag "using invocant: $json"; like( do { eval { $json->from_json($in) }; $@ }, qr/from_json should not be called as a method/, 'blessed invocant detected in from_json', ); like( do { eval { $json->to_json($arr, { blah => 1 } ) }; $@ }, qr/to_json should not be called as a method/, 'blessed invocant detected in to_json', ); done_testing; __END__ to_json $json_text = to_json($perl_scalar) Converts the given Perl data structure to a json string. This function call is functionally identical to: $json_text = JSON()->new->encode($perl_scalar) from_json $perl_scalar = from_json($json_text) The opposite of "to_json": expects a json string and tries to parse it, returning the resulting reference. This function call is functionally identical to: $perl_scalar = JSON()->decode($json_text) JSON-MaybeXS-1.004003/t/lib/000750 000000 000000 00000000000 13753406176 015137 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/t/new.t000644 000000 000000 00000001024 12637357463 015355 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::More 0.88; use JSON::MaybeXS (); our @call; sub Fake::new { bless({}, 'Fake') } sub Fake::foo { push @call, a => $_[1] } sub Fake::bar { push @call, c => $_[1] } { local $JSON::MaybeXS::JSON_Class = 'Fake'; my @args = (foo => 'b', bar => 'd'); foreach my $args (\@args, [ { @args } ]) { local @call; my $obj = JSON::MaybeXS->new(@$args); is(ref($obj), 'Fake', 'Object of correct class'); is(join(' ', sort @call), 'a b c d', 'Methods called'); } } done_testing; JSON-MaybeXS-1.004003/t/none.t000644 000000 000000 00000000717 13400027251 015505 0ustar00rootwheel000000 000000 use strict; use warnings; # hide Cpanel::JSON::XS, JSON::XS, JSON::PP use lib map { my $m = $_; sub { return unless $_[1] eq $m; die "Can't locate $m in \@INC (hidden).\n" }; } qw{Cpanel/JSON/XS.pm JSON/XS.pm JSON/PP.pm}; use Test::More 0.88; ok(!eval { require JSON::MaybeXS; 1 }, 'Class failed to load'); like( $@, qr{Can't locate Cpanel/JSON/XS\.pm.*Can't locate JSON/XS\.pm.*Can't locate JSON/PP\.pm}s, 'All errors reported' ); done_testing; JSON-MaybeXS-1.004003/t/pp.t000644 000000 000000 00000001104 13660344050 015163 0ustar00rootwheel000000 000000 use strict; use warnings; # hide Cpanel::JSON::XS, JSON::XS use lib map { my $m = $_; sub { return unless $_[1] eq $m; die "Can't locate $m in \@INC (hidden).\n" }; } qw{Cpanel/JSON/XS.pm JSON/XS.pm}; use Test::Needs 'JSON::PP'; use Test::More 0.88; use JSON::MaybeXS; diag 'Using JSON::PP ', JSON::PP->VERSION; is(JSON, 'JSON::PP', 'Correct JSON class'); is( \&encode_json, \&JSON::PP::encode_json, 'Correct encode_json function' ); is( \&decode_json, \&JSON::PP::decode_json, 'Correct encode_json function' ); require './t/lib/is_bool.pm'; done_testing; JSON-MaybeXS-1.004003/t/preload_cpanel.t000644 000000 000000 00000000737 13660344050 017527 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::Needs 'Cpanel::JSON::XS'; # load first, before JSON::MaybeXS use Test::More 0.88; use JSON::MaybeXS; diag 'Using Cpanel::JSON::XS ', Cpanel::JSON::XS->VERSION; is(JSON, 'Cpanel::JSON::XS', 'Correct JSON class'); is( \&encode_json, \&Cpanel::JSON::XS::encode_json, 'Correct encode_json function' ); is( \&decode_json, \&Cpanel::JSON::XS::decode_json, 'Correct encode_json function' ); require './t/lib/is_bool.pm'; done_testing; JSON-MaybeXS-1.004003/t/preload_xs.t000644 000000 000000 00000000666 13660344064 016725 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::Needs { 'JSON::XS' => '3.0' }; # load first, before JSON::MaybeXS use Test::More 0.88; use JSON::MaybeXS; diag 'Using JSON::XS ', JSON::XS->VERSION; 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; JSON-MaybeXS-1.004003/t/xs.t000644 000000 000000 00000001131 13753405535 015207 0ustar00rootwheel000000 000000 use strict; use warnings; # hide Cpanel::JSON::XS use lib map { my $m = $_; sub { return unless $_[1] eq $m; die "Can't locate $m in \@INC (hidden).\n" }; } qw{Cpanel/JSON/XS.pm}; use Test::More 0.88; use JSON::MaybeXS; use Test::Needs { 'JSON::XS' => '3.0' }; # load first, before JSON::MaybeXS diag 'Using JSON::XS ', JSON::XS->VERSION; 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; JSON-MaybeXS-1.004003/t/lib/is_bool.pm000644 000000 000000 00000002024 13400027077 017112 0ustar00rootwheel000000 000000 use strict; use warnings; use Test::More; use JSON::MaybeXS; my $data = JSON::MaybeXS->new->decode('{"foo": true, "bar": false, "baz": 1}'); diag 'true is: ', explain $data->{foo}; diag 'false is: ', explain $data->{bar}; 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', ); is( JSON::MaybeXS::encode_json([JSON::MaybeXS::true]), '[true]', JSON() . ': true sub encodes as correct boolean', ); is( JSON::MaybeXS::encode_json([JSON::MaybeXS->true]), '[true]', JSON() . ': true method encodes as correct boolean', ); is( JSON::MaybeXS::encode_json([JSON::MaybeXS::false]), '[false]', JSON() . ': false sub encodes as correct boolean', ); is( JSON::MaybeXS::encode_json([JSON::MaybeXS->false]), '[false]', JSON() . ': false method encodes as correct boolean', ); 1; JSON-MaybeXS-1.004003/maint/Makefile.PL.include000644 000000 000000 00000000344 13400027077 020624 0ustar00rootwheel000000 000000 BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") } use lib 'Distar/lib'; use Distar; author 'mst - Matt S. Trout (cpan:MSTROUT) '; manifest_include inc => '.pm'; 1; JSON-MaybeXS-1.004003/lib/JSON/000750 000000 000000 00000000000 13753406176 015445 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/lib/JSON/MaybeXS.pm000644 000000 000000 00000022734 13753405767 017335 0ustar00rootwheel000000 000000 package JSON::MaybeXS; use strict; use warnings FATAL => 'all'; use base qw(Exporter); our $VERSION = '1.004003'; $VERSION =~ tr/_//d; sub _choose_json_module { return 'Cpanel::JSON::XS' if $INC{'Cpanel/JSON/XS.pm'}; return 'JSON::XS' if $INC{'JSON/XS.pm'} && eval { JSON::XS->VERSION(3.0); 1 }; my @err; return 'Cpanel::JSON::XS' if eval { require Cpanel::JSON::XS; 1; }; push @err, "Error loading Cpanel::JSON::XS: $@"; return 'JSON::XS' if eval { require JSON::XS; JSON::XS->VERSION(3.0); 1; }; push @err, "Error loading JSON::XS: $@"; return 'JSON::PP' if eval { require JSON::PP; 1 }; push @err, "Error loading JSON::PP: $@"; die join( "\n", "Couldn't load a JSON module:", @err ); } BEGIN { our $JSON_Class = _choose_json_module(); $JSON_Class->import(qw(encode_json decode_json)); no strict 'refs'; *$_ = $JSON_Class->can($_) for qw(true false); } our @EXPORT = qw(encode_json decode_json JSON); my @EXPORT_ALL = qw(is_bool); our @EXPORT_OK = qw(is_bool to_json from_json); our %EXPORT_TAGS = ( all => [ @EXPORT, @EXPORT_ALL ], legacy => [ @EXPORT, @EXPORT_OK ], ); sub JSON () { our $JSON_Class } sub new { shift; my %args = @_ == 1 ? %{$_[0]} : @_; my $new = (our $JSON_Class)->new; $new->$_($args{$_}) for keys %args; 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('Cpanel::JSON::XS::Boolean') or $_[0]->isa('JSON::PP::Boolean')); } # (mostly) CopyPasta from JSON.pm version 2.90 use Carp (); sub from_json ($@) { if ( ref($_[0]) =~ /^JSON/ or $_[0] =~ /^JSON/ ) { Carp::croak "from_json should not be called as a method."; } my $json = JSON()->new; if (@_ == 2 and ref $_[1] eq 'HASH') { my $opt = $_[1]; for my $method (keys %$opt) { $json->$method( $opt->{$method} ); } } return $json->decode( $_[0] ); } sub to_json ($@) { if ( ref($_[0]) =~ /^JSON/ or (@_ > 2 and $_[0] =~ /^JSON/) ) { Carp::croak "to_json should not be called as a method."; } my $json = JSON()->new; if (@_ == 2 and ref $_[1] eq 'HASH') { my $opt = $_[1]; for my $method (keys %$opt) { $json->$method( $opt->{$method} ); } } $json->encode($_[0]); } 1; =head1 NAME JSON::MaybeXS - Use L with a fallback to L and L =head1 SYNOPSIS use JSON::MaybeXS; my $data_structure = decode_json($json_input); my $json_output = encode_json($data_structure); my $json = JSON()->new; my $json_with_args = JSON::MaybeXS->new(utf8 => 1); # or { utf8 => 1 } =head1 DESCRIPTION This module first checks to see if either L or L (at at least version 3.0) is already loaded, in which case it uses that module. Otherwise it tries to load L, then L, then L in order, and either uses the first module it finds or throws an error. It then exports the C and C functions from the loaded module, along with a C constant that returns the class name for calling C on. If you're writing fresh code rather than replacing L usage, you might want to pass options as constructor args rather than calling mutators, so we provide our own C method that supports that. =head1 EXPORTS C, C and C are exported by default; C is exported on request. To import only some symbols, specify them on the C line: use JSON::MaybeXS qw(encode_json decode_json is_bool); # functions only use JSON::MaybeXS qw(JSON); # JSON constant only To import all available sensible symbols (C, C, and C), use C<:all>: use JSON::MaybeXS ':all'; To import all symbols including those needed by legacy apps that use L: use JSON::MaybeXS ':legacy'; This imports the C and C symbols as well as everything in C<:all>. NOTE: This is to support legacy code that makes extensive use of C and C which you are not yet in a position to refactor. DO NOT use this import tag in new code, in order to avoid the crawling horrors of getting UTF-8 support subtly wrong. See the documentation for L for further details. =head2 encode_json This is the C function provided by the selected implementation module, and takes a perl data structure which is serialised to JSON text. my $json_text = encode_json($data_structure); =head2 decode_json This is the C function provided by the selected implementation module, and takes a string of JSON text to deserialise to a perl data structure. my $data_structure = decode_json($json_text); =head2 to_json, from_json See L for details. These are included to support legacy code B. =head2 JSON The C constant returns the selected implementation module's name for use as a class name - so: my $json_obj = JSON()->new; # returns a Cpanel::JSON::XS or JSON::PP object and that object can then be used normally: my $data_structure = $json_obj->decode($json_text); # etc. The use of parentheses here is optional, and only used as a hint to the reader that this use of C is a I call, I a class name. =head2 is_bool $is_boolean = is_bool($scalar) Returns true if the passed scalar represents either C or C, two constants that act like C<1> and C<0>, respectively and are used to represent JSON C and C 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. Available since version 1.002004. =head1 CONSTRUCTOR =head2 new With L, L and L you are required to call mutators to set options, such as: my $json = $class->new->utf8(1)->pretty(1); Since this is a trifle irritating and noticeably un-perlish, we also offer: my $json = JSON::MaybeXS->new(utf8 => 1, pretty => 1); which works equivalently to the above (and in the usual tradition will accept a hashref instead of a hash, should you so desire). The resulting object is blessed into the underlying backend, which offers (at least) the methods C and C. =head1 BOOLEANS To include JSON-aware booleans (C, C) in your data, just do: use JSON::MaybeXS; my $true = JSON()->true; my $false = JSON()->false; The booleans are also available as subs or methods on JSON::MaybeXS. use JSON::MaybeXS (); my $true = JSON::MaybeXS::true; my $true = JSON::MaybeXS->true; my $false = JSON::MaybeXS::false; my $false = JSON::MaybeXS->false; =head1 CONVERTING FROM JSON::Any L used to be the favoured compatibility layer above the various JSON backends, but over time has grown a lot of extra code to deal with legacy backends (e.g. L) that are no longer needed. This is a rough guide of translating such code: Change code from: use JSON::Any; my $json = JSON::Any->new->objToJson($data); # or to_json($data), or Dump($data) to: use JSON::MaybeXS; my $json = encode_json($data); Change code from: use JSON::Any; my $data = JSON::Any->new->jsonToObj($json); # or from_json($json), or Load($json) to: use JSON::MaybeXS; my $json = decode_json($data); =head1 CAVEATS The C method in this module is technically a factory, not a constructor, because the objects it returns will I be blessed into the C class. If you are using an object returned by this module as a Moo(se) attribute, this type constraint code: is 'json' => ( isa => 'JSON::MaybeXS' ); will I do what you expect. Instead, either rely on the C class constant described above, as so: is 'json' => ( isa => JSON::MaybeXS::JSON() ); Alternatively, you can use duck typing: use Moose::Util::TypeConstraints 'duck_type'; is 'json' => ( isa => Object , duck_type([qw/ encode decode /])); =head1 INSTALLATION At installation time, F will attempt to determine if you have a working compiler available, and therefore whether you are able to run XS code. If so, L will be added to the prerequisite list, unless L is already installed at a high enough version. L may also be upgraded to fix any incompatibility issues. Because running XS code is not mandatory and L (which is in perl core) is used as a fallback backend, this module is safe to be used in a suite of code that is fatpacked or installed into a restricted-resource environment. You can also prevent any XS dependencies from being installed by setting C in F options (or in the C environment variable), or using the C<--pp> or C<--pureperl> flags with the L. =head1 AUTHOR mst - Matt S. Trout (cpan:MSTROUT) =head1 CONTRIBUTORS =over 4 =item * Clinton Gormley =item * Karen Etheridge =item * Kieren Diment =back =head1 COPYRIGHT Copyright (c) 2013 the C L and L as listed above. =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. =cut JSON-MaybeXS-1.004003/inc/ExtUtils/000750 000000 000000 00000000000 13753406176 016460 5ustar00rootwheel000000 000000 JSON-MaybeXS-1.004003/inc/ExtUtils/HasCompiler.pm000644 000000 000000 00000022031 13400027077 021213 0ustar00rootwheel000000 000000 package ExtUtils::HasCompiler; $ExtUtils::HasCompiler::VERSION = '0.021'; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw/can_compile_loadable_object can_compile_static_library can_compile_extension/; our %EXPORT_TAGS = (all => \@EXPORT_OK); use Config; use Carp 'carp'; use File::Basename 'basename'; use File::Spec::Functions qw/catfile catdir rel2abs/; use File::Temp qw/tempdir tempfile/; my $tempdir = tempdir('HASCOMPILERXXXX', CLEANUP => 1, DIR => '.'); my $loadable_object_format = <<'END'; #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifndef PERL_UNUSED_VAR #define PERL_UNUSED_VAR(var) #endif XS(exported) { #ifdef dVAR dVAR; #endif dXSARGS; PERL_UNUSED_VAR(cv); /* -W */ PERL_UNUSED_VAR(items); /* -W */ XSRETURN_IV(42); } #ifndef XS_EXTERNAL #define XS_EXTERNAL(foo) XS(foo) #endif /* we don't want to mess with .def files on mingw */ #if defined(WIN32) && defined(__GNUC__) # define EXPORT __declspec(dllexport) #else # define EXPORT #endif EXPORT XS_EXTERNAL(boot_%s) { #ifdef dVAR dVAR; #endif dXSARGS; PERL_UNUSED_VAR(cv); /* -W */ PERL_UNUSED_VAR(items); /* -W */ newXS("%s::exported", exported, __FILE__); } END my $counter = 1; my %prelinking = map { $_ => 1 } qw/MSWin32 VMS aix/; sub can_compile_loadable_object { my %args = @_; my $output = $args{output} || \*STDOUT; my $config = $args{config} || 'ExtUtils::HasCompiler::Config'; return if not $config->get('usedl'); my ($source_handle, $source_name) = tempfile('TESTXXXX', DIR => $tempdir, SUFFIX => '.c', UNLINK => 1); my $basename = basename($source_name, '.c'); my $abs_basename = catfile($tempdir, $basename); my ($cc, $ccflags, $optimize, $cccdlflags, $ld, $ldflags, $lddlflags, $libperl, $perllibs, $archlibexp, $_o, $dlext) = map { $config->get($_) } qw/cc ccflags optimize cccdlflags ld ldflags lddlflags libperl perllibs archlibexp _o dlext/; my $incdir = catdir($archlibexp, 'CORE'); my $object_file = $abs_basename.$_o; my $loadable_object = "$abs_basename.$dlext"; my @commands; if ($^O eq 'MSWin32' && $cc =~ /^cl/) { push @commands, qq{$cc $ccflags $cccdlflags $optimize /I "$incdir" /c $source_name /Fo$object_file}; push @commands, qq{$ld $object_file $lddlflags $libperl $perllibs /out:$loadable_object /def:$abs_basename.def /pdb:$abs_basename.pdb}; } elsif ($^O eq 'VMS') { # Mksymlists is only the beginning of the story. open my $opt_fh, '>>', "$abs_basename.opt" or do { carp "Couldn't append to '$abs_basename.opt'"; return }; print $opt_fh "PerlShr/Share\n"; close $opt_fh; my $incdirs = $ccflags =~ s{ /inc[^=]+ (?:=)+ (?:\()? ( [^\/\)]* ) }{}xi ? "$1,$incdir" : $incdir; push @commands, qq{$cc $ccflags $optimize /include=($incdirs) $cccdlflags $source_name /obj=$object_file}; push @commands, qq{$ld $ldflags $lddlflags=$loadable_object $object_file,$abs_basename.opt/OPTIONS,${incdir}perlshr_attr.opt/OPTIONS' $perllibs}; } else { my @extra; if ($^O eq 'MSWin32') { my $lib = '-l' . ($libperl =~ /lib([^.]+)\./)[0]; push @extra, "$abs_basename.def", $lib, $perllibs; } elsif ($^O eq 'cygwin') { push @extra, catfile($incdir, $config->get('useshrplib') ? 'libperl.dll.a' : 'libperl.a'); } elsif ($^O eq 'aix') { $lddlflags =~ s/\Q$(BASEEXT)\E/$abs_basename/; $lddlflags =~ s/\Q$(PERL_INC)\E/$incdir/; } elsif ($^O eq 'android') { push @extra, qq{"-L$incdir"}, '-lperl', $perllibs; } push @commands, qq{$cc $ccflags $optimize "-I$incdir" $cccdlflags -c $source_name -o $object_file}; push @commands, qq{$ld $object_file -o $loadable_object $lddlflags @extra}; } if ($prelinking{$^O}) { require ExtUtils::Mksymlists; ExtUtils::Mksymlists::Mksymlists(NAME => $basename, FILE => $abs_basename, IMPORTS => {}); } my $shortname = '_Loadable' . $counter++; my $package = "ExtUtils::HasCompiler::$shortname"; printf $source_handle $loadable_object_format, $basename, $package or do { carp "Couldn't write to $source_name: $!"; return }; close $source_handle or do { carp "Couldn't close $source_name: $!"; return }; for my $command (@commands) { print $output "$command\n" if not $args{quiet}; system $command and do { carp "Couldn't execute $command: $!"; return }; } # Skip loading when cross-compiling return 1 if exists $args{skip_load} ? $args{skip_load} : $config->get('usecrosscompile'); require DynaLoader; local @DynaLoader::dl_require_symbols = "boot_$basename"; my $handle = DynaLoader::dl_load_file(rel2abs($loadable_object), 0); if ($handle) { my $symbol = DynaLoader::dl_find_symbol($handle, "boot_$basename") or do { carp "Couldn't find boot symbol for $basename"; return }; my $compilet = DynaLoader::dl_install_xsub('__ANON__::__ANON__', $symbol, $source_name); my $ret = eval { $compilet->(); $package->exported } or carp $@; delete $ExtUtils::HasCompiler::{"$shortname\::"}; eval { DynaLoader::dl_unload_file($handle) } or carp $@; return defined $ret && $ret == 42; } else { carp "Couldn't load $loadable_object: " . DynaLoader::dl_error(); return; } } my %static_unsupported_on = map { $_ => 1 } qw/VMS aix MSWin32 cygwin/; sub can_compile_static_library { my %args = @_; my $output = $args{output} || \*STDOUT; my $config = $args{config} || 'ExtUtils::HasCompiler::Config'; return if $config->get('useshrplib') eq 'true'; my ($source_handle, $source_name) = tempfile('TESTXXXX', DIR => $tempdir, SUFFIX => '.c', UNLINK => 1); my $basename = basename($source_name, '.c'); my $abs_basename = catfile($tempdir, $basename); my ($cc, $ccflags, $optimize, $ar, $full_ar, $ranlib, $archlibexp, $_o, $lib_ext) = map { $config->get($_) } qw/cc ccflags optimize ar full_ar ranlib archlibexp _o lib_ext/; my $incdir = catdir($archlibexp, 'CORE'); my $object_file = "$abs_basename$_o"; my $static_library = $abs_basename.$lib_ext; my @commands; if ($static_unsupported_on{$^O}) { return; } else { my $my_ar = length $full_ar ? $full_ar : $ar; push @commands, qq{$cc $ccflags $optimize "-I$incdir" -c $source_name -o $object_file}; push @commands, qq{$my_ar cr $static_library $object_file}; push @commands, qq{$ranlib $static_library} if $ranlib ne ':'; } my $shortname = '_Loadable' . $counter++; my $package = "ExtUtils::HasCompiler::$shortname"; printf $source_handle $loadable_object_format, $basename, $package or do { carp "Couldn't write to $source_name: $!"; return }; close $source_handle or do { carp "Couldn't close $source_name: $!"; return }; for my $command (@commands) { print $output "$command\n" if not $args{quiet}; system $command and do { carp "Couldn't execute $command: $!"; return }; } return 1; } sub can_compile_extension { my %args = @_; $args{config} ||= 'ExtUtils::HasCompiler::Config'; my $linktype = $args{linktype} || ($args{config}->get('usedl') ? 'dynamic' : 'static'); return $linktype eq 'static' ? can_compile_static_library(%args) : can_compile_loadable_object(%args); } sub ExtUtils::HasCompiler::Config::get { my (undef, $key) = @_; return $ENV{uc $key} || $Config{$key}; } 1; # ABSTRACT: Check for the presence of a compiler __END__ =pod =encoding UTF-8 =head1 NAME ExtUtils::HasCompiler - Check for the presence of a compiler =head1 VERSION version 0.021 =head1 SYNOPSIS use ExtUtils::HasCompiler 'can_compile_extension'; if (can_compile_extension()) { ... } else { ... } =head1 DESCRIPTION This module tries to check if the current system is capable of compiling, linking and loading an XS module. B: this is an early release, interface stability isn't guaranteed yet. =head1 FUNCTIONS =head2 can_compile_loadable_object(%opts) This checks if the system can compile, link and load a perl loadable object. It may take the following options: =over 4 =item * quiet Do not output the executed compilation commands. =item * config An L (compatible) object for configuration. =item * skip_load This causes can_compile_loadable_object to not try to load the generated object. This defaults to true on a cross-compiling perl. =back =head2 can_compile_static_library(%opts) This checks if the system can compile and link a perl static library. It does not check it it can compile a new perl with it. It may take the following options: =over 4 =item * quiet Do not output the executed compilation commands. =item * config An L (compatible) object for configuration. =back =head2 can_compile_extension(%opts) This will call either C, or C, depending on which is the default on your configuration. In addition to the arguments listed above, it can take one more optional argument: =over 4 =item * linktype This will force the linktype to be either static or dynamic. Dynamic compilation on a static perl won't work, but static libraries can be viable on a dynamic perl. =back =head1 AUTHOR Leon Timmermans =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Leon Timmermans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut