boolean-0.46000755000000000000 012737757574 12211 5ustar00rootroot000000000000README100644000000000000 755212737757574 13163 0ustar00rootroot000000000000boolean-0.46NAME boolean - Boolean support for Perl VERSION This document describes boolean version 0.46. SYNOPSIS use boolean; do &always if true; do &never if false; do &maybe if boolean($value)->isTrue; and: use boolean ':all'; $guess = int(rand(2)) % 2 ? true : false; do &something if isTrue($guess); do &something_else if isFalse($guess); DESCRIPTION Most programming languages have a native Boolean data type. Perl does not. Perl has a simple and well known Truth System. The following scalar values are false: $false1 = undef; $false2 = 0; $false3 = 0.0; $false4 = ''; $false5 = '0'; Every other scalar value is true. This module provides basic Boolean support, by defining two special objects: true and false. RATIONALE When sharing data between programming languages, it is important to support the same group of basic types. In Perlish programming languages, these types include: Hash, Array, String, Number, Null and Boolean. Perl lacks native Boolean support. Data interchange modules like YAML and JSON can now use boolean to encodedecoderoundtrip Boolean values. FUNCTIONS This module defines the following functions: true This function returns a scalar value which will evaluate to true. The value is a singleton object, meaning there is only one "true" value in a Perl process at any time. You can check to see whether the value is the "true" object with the isTrue function described below. false This function returns a scalar value which will evaluate to false. The value is a singleton object, meaning there is only one "false" value in a Perl process at any time. You can check to see whether the value is the "false" object with the isFalse function described below. boolean($scalar) Casts the scalar value to a boolean value. If $scalar is true, it returns boolean::true, otherwise it returns boolean::false. isTrue($scalar) Returns boolean::true if the scalar passed to it is the boolean::true object. Returns boolean::false otherwise. isFalse($scalar) Returns boolean::true if the scalar passed to it is the boolean::false object. Returns boolean::false otherwise. isBoolean($scalar) Returns boolean::true if the scalar passed to it is the boolean::true or boolean::false object. Returns boolean::false otherwise. METHODS Since true and false return objects, you can call methods on them. $boolean->isTrue Same as isTrue($boolean). $boolean->isFalse Same as isFalse($boolean). USE OPTIONS By default this module exports the true, false and boolean functions. The module also defines these export tags: :all Exports true, false, boolean, isTrue, isFalse, isBoolean DEPRECATIONS This module offered an export tag, -truth, that overrides the Perl interpreter's internal values for true and false. This has been found to corrupt the interpreter in some circumstances. Also, these overrides will no longer be possible as of Perl 5.22. Therefore, the -truth import tag is deprecated. JSON SUPPORT JSON::MaybeXS (or less preferably JSON.pm ) will encode Perl data with boolean.pm values correctly if you use the convert_blessed option: use JSON::MaybeXS; use boolean -truth; my $json = JSON::MaybeXS->new->convert_blessed; say $json->encode({false => (0 == 1)}); # Says: '{"false":false}', AUTHOR Ingy döt Net COPYRIGHT AND LICENSE Copyright 2007-2016. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html Changes100644000000000000 575312737757574 13577 0ustar00rootroot000000000000boolean-0.460.46 Fri Jul 8 17:14:32 UTC 2016 - Apply PR/14 @dagolden++ - Adds CLONE method for thread safety 0.45 Thu Feb 5 15:39:26 PST 2015 - Remove last vestige of -truth from the tests! 0.44 Sat Jan 31 13:55:37 PST 2015 - Apply PRs 9,10,11 @dagolden++ 0.43 Thu Jan 1 00:27:42 PST 2015 - Update docs 0.42 Sat Aug 16 10:49:31 PDT 2014 - Meta 0.0.2 - Remove .gitignore 0.41 Fri Aug 15 15:41:09 PDT 2014 - Add t/000-compile-modules.t - CPAN Day 2014 - 21 Release Salute! 0.40 Fri Aug 8 19:12:51 PDT 2014 - Fix swim errors 0.39 Sat Aug 2 10:17:12 PDT 2014 - Fix Copyright years. - Fix Meta and add Contributing 0.38 Wed Jun 25 21:08:05 PDT 2014 - Revert json.t. Failed on cpantesters. 0.37 Wed Jun 25 16:47:29 PDT 2014 - Add JSON to recommends 0.36 Wed Jun 25 16:46:39 PDT 2014 - Fix homepage in metadata 0.35 Tue Jun 17 10:59:25 PDT 2014 - Remove ABSTRACT and use manual $VERSION 0.34 Sat Jun 14 13:16:30 PDT 2014 - Release 0.33 got botched. 0.33 Sat Jun 14 12:59:00 PDT 2014 - Package with Zilla::Dist - Add badges 0.32 Sat Feb 8 19:17:09 PST 2014 - Some dzil changes 0.31 Thu Feb 6 18:28:28 PST 2014 - Switch to dzil 0.30 Wed Apr 3 15:24:44 PDT 2013 - Fix https://rt.cpan.org/Public/Bug/Display.html?id=84398 - chip++ - Documented JSON support. 0.29 Mon Apr 1 21:48:31 PDT 2013 - Support JSON and JSON::XS. dankogai-san++ 0.28 Mon Sep 12 13:51:47 CEST 2011 - Added -truth option. - This idea was inspired by https://rt.cpan.org/Ticket/Display.html?id=65536 - Awesome idea! - Released from Liz++&Wendy++ downstairs bathroom 0.27 Tue Jun 28 10:47:01 EDT 2011 - Switch to Module::Package at YAPC 2011 ++ 0.26 Fri Jan 21 00:05:44 EST 2011 - Fixed doc bug reported by KENTNL++ - Tweaked Makefile.PL 0.25 Sat Jan 15 19:05:19 EST 2011 - Fixed a bug caused by Readonly::XS (schwern++) - Removed the new methods and autobox methods. They didn't add much except confusion. - Documented that you can use isTrue and isFalse as methods. - &boolean(1,2,3) now dies like boolean(1,2,3) - &boolean() now dies like boolean() 0.24 Thu Jan 13 15:27:09 EST 2011 - @Schwern++ found out how to make true and false immutable. Kudos to #strategicdata++. - Document the boolean() function. - Added is_true and is_false methods. - Added boolean, is_true, and is_false autobox methods 0.23 Thu Sep 16 19:27:54 PDT 2010 - Weird macosx dist bug broke everything. Worked around. 0.22 Wed Sep 15 00:21:20 PDT 2010 - Update copyright years. 0.21 Mon Sep 13 18:40:21 PDT 2010 - Add a boolean($) coercer export function - Add many more tests (from 20 to 55 tests) - Add prototypes to all exports functions - Overload not and ! to return boolean 0.20 Sun Aug 24 18:52:39 PDT 2008 - Total rewrite. - Drop XS code. Uses pure perl. - Objects are scalar refs with overloading. - Drop null support. 0.12 Tue Jun 3 21:33:58 PDT 2008 - Doc fixes. 0.11 Mon Jun 11 12:17:58 PDT 2007 - Doc fixes. Thanks Adriano Ferreira. - Test refactoring. 0.10 Sun Jun 10 15:46:33 PDT 2007 - isTrue('first release'); LICENSE100644000000000000 4366012737757574 13330 0ustar00rootroot000000000000boolean-0.46This software is copyright (c) 2016 by Ingy döt Net. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. 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) 2016 by Ingy döt Net. 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) 2016 by Ingy döt Net. 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 t000755000000000000 012737757574 12375 5ustar00rootroot000000000000boolean-0.46json.t100644000000000000 106712737757574 13677 0ustar00rootroot000000000000boolean-0.46/tuse strict; use warnings; use Test::More tests => 3; use boolean; my $HAVE_JSON = eval { require JSON::MaybeXS }; SKIP: { skip "JSON is missing", 3 unless $HAVE_JSON; eval{ my $json = JSON::MaybeXS->new->convert_blessed(); is($json->encode({false => false}), '{"false":false}', 'JSON false works'); is($json->encode({true => true}), '{"true":true}', 'JSON true works'); is(ref(boolean::TO_JSON(true)), 'SCALAR', 'Make sure we can call boolean::TO_JSON($b)'); }; diag "$@" if $@; }; MANIFEST100644000000000000 42612737757574 13405 0ustar00rootroot000000000000boolean-0.46# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.047. CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README lib/boolean.pm lib/boolean.pod t/000-compile-modules.t t/author-pod-syntax.t t/boolean.t t/export.t t/json.t t/threads.t META.yml100644000000000000 126512737757574 13547 0ustar00rootroot000000000000boolean-0.46--- abstract: 'Boolean support for Perl' author: - 'Ingy döt Net ' build_requires: {} configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.047, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: boolean no_index: directory: - example - inc - t - xt recommends: JSON::MaybeXS: '0' requires: perl: v5.8.1 resources: bugtracker: https://github.com/ingydotnet/boolean-pm/issues homepage: https://github.com/ingydotnet/boolean-pm repository: https://github.com/ingydotnet/boolean-pm.git version: '0.46' META.json100644000000000000 246112737757574 13716 0ustar00rootroot000000000000boolean-0.46{ "abstract" : "Boolean support for Perl", "author" : [ "Ingy d\u00f6t Net " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.047, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "boolean", "no_index" : { "directory" : [ "example", "inc", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "recommends" : { "JSON::MaybeXS" : "0" }, "requires" : { "perl" : "v5.8.1" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ingydotnet/boolean-pm/issues" }, "homepage" : "https://github.com/ingydotnet/boolean-pm", "repository" : { "type" : "git", "url" : "https://github.com/ingydotnet/boolean-pm.git", "web" : "https://github.com/ingydotnet/boolean-pm" } }, "version" : "0.46" } export.t100644000000000000 177612737757574 14256 0ustar00rootroot000000000000boolean-0.46/tuse Test::More tests => 4 * 6; use strict; # use warnings; use lib 'lib'; package None; use boolean(); package Default; use boolean; package All; use boolean ':all'; package Test; use boolean ':test'; package main; use boolean; my @functions = qw(true false boolean isTrue isFalse isBoolean); my @exports = qw(None Default All Test); my %exported = ( None => [false, false, false, false, false, false], Default => [true, true, true, false, false, false], All => [true, true, true, true, true, true], Test => [false, false, false, true, true, true], ); for my $export (@exports) { my $tag = ":" . lc($export); for (my $i = 0; $i < @functions; $i++) { my $function = $functions[$i]; my $exported = $exported{$export}->[$i]; my $defined = defined(&{$export . "::" . $function}) ? 1 : 0; my $test = $exported == $defined; ok $test, $tag . ($exported ? " imports " : " does not import ") . $function; } } threads.t100644000000000000 122712737757574 14356 0ustar00rootroot000000000000boolean-0.46/tuse Test::More; use strict; use lib 'lib'; use Config; BEGIN { plan skip_all => "requires threads" unless $Config{usethreads} }; use threads; plan tests => 8; use boolean ':all'; my $true = true; my $false = false; sub ok_from_thread($) { local $Test::Builder = $Test::Builder::Level + 1; my $code = shift; ok( threads->create(eval "sub { $code }")->join(), $code ); }; ok_from_thread "isTrue(true)"; ok_from_thread "isFalse(false)"; ok_from_thread "isBoolean(true)"; ok_from_thread "isBoolean(false)"; ok_from_thread "isTrue(\$true)"; ok_from_thread "isFalse(\$false)"; ok_from_thread "isBoolean(\$true)"; ok_from_thread "isBoolean(\$false)"; boolean.t100644000000000000 672012737757574 14346 0ustar00rootroot000000000000boolean-0.46/tuse Test::More tests => 61; use strict; use lib 'lib'; use boolean ':all'; ok true, 'true is defined and works'; ok !false, 'false is defined and works'; ok not(false), 'false works with not()'; ok not(not(true)), 'true works with not()'; ok isTrue(true), "isTrue works with true"; ok isFalse(false), "isFalse works false"; ok not(isTrue(false)), "isTrue not true with false"; ok not(isFalse(true)), "isFalse not true with true"; ok isBoolean(true), 'true isBoolean'; ok isBoolean(false), 'false isBoolean'; ok not(isBoolean(undef)), 'undef is not Boolean'; ok not(isBoolean("")), '"" is not Boolean'; ok not(isBoolean(0)), '0 is not Boolean'; ok not(isBoolean(1)), '1 is not Boolean'; ok true eq true, 'true eq true'; ok true == true, 'true == true'; ok false eq false, 'false eq false'; ok false == false, 'false == false'; ok not(true) == false, 'not(true) == false'; ok not(false) == true, 'not(false) == true'; ok !(true) == false, '!(true) == false'; ok !(false) == true, '!(false) == true'; ok isBoolean(isFalse(isFalse(undef))), 'boolean return values are boolean'; ok isBoolean(not(true)), 'not boolean returns boolean'; ok isBoolean(!(false)), '! boolean returns boolean'; # Test true in various contexts my $t = true; is ref($t), 'boolean', "ref(true) eq 'boolean'"; is "$t", "1", "true stringifies to '1'"; my $t1 = $t ? "true" : "false"; is $t1, "true", "Ternary works with true"; my $t2; if ($t) { $t2 = "true"; } else { $t2 = "false"; } is $t2, "true", "'if' works with true"; ok $t eq 1, 'true eq 0'; ok $t == 1, 'true == 0'; # Test false in various contexts my $f = false; ok $f eq false, '$f eq false'; ok $f == false, '$f == false'; is ref($f), 'boolean', "ref(true) eq 'boolean'"; is "$f", "0", "false stringifies to '0'"; my $f1 = $f ? "true" : "false"; is $f1, "false", "Ternary works with false"; my $f2; if ($f) { $f2 = "true"; } else { $f2 = "false"; } is $f2, "false", "'if' works with false"; ok $f eq 0, 'false eq 0'; ok $f == 0, 'false == 0'; # boolean() eval "boolean()"; like $@, qr/Not enough arguments for boolean::boolean/, "boolean() has too few args (prototyped)"; eval "&boolean()"; like $@, qr/Not enough arguments for boolean::boolean/, "&boolean() has too few args (unprototyped)"; eval "boolean(1,2,3)"; like $@, qr/Too many arguments for boolean::boolean/, "boolean(1,2,3) has too many args (prototyped)"; eval "&boolean(1,2,3)"; like $@, qr/Too many arguments for boolean::boolean/, "&boolean(1,2,3) has too many args (unprototyped)"; my @t = (0); ok isBoolean(boolean(42)), "boolean() returns boolean"; ok isBoolean(boolean(undef)), "boolean() works with undef"; ok isBoolean(boolean(())), "boolean works with ()"; ok isBoolean(boolean((0))), "boolean works with ()"; ok isBoolean(boolean(@t)), "boolean works with ()"; ok isTrue(boolean(42)), "boolean(42) isTrue"; ok isFalse(boolean(undef)), "boolean(undef) isFalse"; ok isFalse(boolean(())), "boolean(()) isFalse"; ok isFalse(boolean((0))), "boolean((0)) isFalse"; ok isFalse(boolean((1, 0))), "boolean((1, 0)) isFalse"; ok isTrue(boolean((0, 1))), "boolean((1, 0)) isTrue"; ok isTrue(boolean(@t)), "boolean on array with one false value isTrue"; # Other stuff eval 'true(1)'; ok $@, "Can't pass values to true/false"; eval 'true(@main::array)'; ok $@, "Can't pass values to true/false"; eval 'true(())'; ok $@, "Can't pass values to true/false"; eval 'false(undef)'; ok $@, "Can't pass values to true/false"; ok true->isTrue, "true isTrue"; ok false->isFalse, "false isFalse"; Makefile.PL100644000000000000 161012737757574 14242 0ustar00rootroot000000000000boolean-0.46# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.047. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Boolean support for Perl", "AUTHOR" => "Ingy d\x{f6}t Net ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "boolean", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008001", "NAME" => "boolean", "PREREQ_PM" => {}, "VERSION" => "0.46", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = (); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); CONTRIBUTING100644000000000000 235412737757574 14130 0ustar00rootroot000000000000boolean-0.46Contributing ============ The "boolean" Project needs your help! Please consider being a contributor. This file contains instructions that will help you be an effective contributor to the Project. GitHub ------ The code for this Project is hosted at GitHub. The URL is: https://github.com/ingydotnet/boolean-pm You can get the code with this command: git clone https://github.com/ingydotnet/boolean-pm If you've found a bug or a missing feature that you would like the author to know about, report it here: https://github.com/ingydotnet/boolean-pm/issues or fix it and submit a pull request here: https://github.com/ingydotnet/boolean-pm/pulls See these links for help on interacting with GitHub: * https://help.github.com/ * https://help.github.com/articles/creating-a-pull-request Zilla::Dist ----------- This Project uses Zilla::Dist to prepare it for publishing to CPAN. Read: https://metacpan.org/pod/Zilla::Dist::Contributing for up-to-date instructions on what contributors like yourself need to know to use it. IRC --- boolean has an IRC channel where you can find real people to help you: irc.freenode.net#pkg Join the channel. Join the team! Thanks in advance, # This file generated by Zilla-Dist-0.0.193 lib000755000000000000 012737757574 12700 5ustar00rootroot000000000000boolean-0.46boolean.pm100644000000000000 421112737757574 15013 0ustar00rootroot000000000000boolean-0.46/libuse strict; use warnings; package boolean; our $VERSION = '0.46'; my ($true, $false); use overload '""' => sub { ${$_[0]} }, '!' => sub { ${$_[0]} ? $false : $true }, fallback => 1; use base 'Exporter'; @boolean::EXPORT = qw(true false boolean); @boolean::EXPORT_OK = qw(isTrue isFalse isBoolean); %boolean::EXPORT_TAGS = ( all => [@boolean::EXPORT, @boolean::EXPORT_OK], test => [qw(isTrue isFalse isBoolean)], ); sub import { my @options = grep $_ ne '-truth', @_; $_[0]->truth if @options != @_; @_ = @options; goto &Exporter::import; } my ($true_val, $false_val, $bool_vals); BEGIN { my $t = 1; my $f = 0; $true = do {bless \$t, 'boolean'}; $false = do {bless \$f, 'boolean'}; $true_val = overload::StrVal($true); $false_val = overload::StrVal($false); $bool_vals = {$true_val => 1, $false_val => 1}; } # refaddrs change on thread spawn, so CLONE fixes them up sub CLONE { $true_val = overload::StrVal($true); $false_val = overload::StrVal($false); $bool_vals = {$true_val => 1, $false_val => 1}; } sub true() { $true } sub false() { $false } sub boolean($) { die "Not enough arguments for boolean::boolean" if scalar(@_) == 0; die "Too many arguments for boolean::boolean" if scalar(@_) > 1; return not(defined $_[0]) ? false : "$_[0]" ? $true : $false; } sub isTrue($) { not(defined $_[0]) ? false : (overload::StrVal($_[0]) eq $true_val) ? true : false; } sub isFalse($) { not(defined $_[0]) ? false : (overload::StrVal($_[0]) eq $false_val) ? true : false; } sub isBoolean($) { not(defined $_[0]) ? false : (exists $bool_vals->{overload::StrVal($_[0])}) ? true : false; } sub truth { die "-truth not supported on Perl 5.22 or later" if $] >= 5.021005; # enable modifying true and false &Internals::SvREADONLY( \ !!0, 0); &Internals::SvREADONLY( \ !!1, 0); # turn perl internal booleans into blessed booleans: ${ \ !!0 } = $false; ${ \ !!1 } = $true; # make true and false read-only again &Internals::SvREADONLY( \ !!0, 1); &Internals::SvREADONLY( \ !!1, 1); } sub TO_JSON { ${$_[0]} ? \1 : \0 } 1; boolean.pod100644000000000000 1012412737757574 15201 0ustar00rootroot000000000000boolean-0.46/lib=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.43. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME boolean - Boolean support for Perl =for html boolean-pm =head1 VERSION This document describes L version B<0.46>. =head1 SYNOPSIS use boolean; do &always if true; do &never if false; do &maybe if boolean($value)->isTrue; and: use boolean ':all'; $guess = int(rand(2)) % 2 ? true : false; do &something if isTrue($guess); do &something_else if isFalse($guess); =head1 DESCRIPTION Most programming languages have a native C data type. Perl does not. Perl has a simple and well known Truth System. The following scalar values are false: $false1 = undef; $false2 = 0; $false3 = 0.0; $false4 = ''; $false5 = '0'; Every other scalar value is true. This module provides basic Boolean support, by defining two special objects: C and C. =head1 RATIONALE When sharing data between programming languages, it is important to support the same group of basic types. In Perlish programming languages, these types include: Hash, Array, String, Number, Null and Boolean. Perl lacks native Boolean support. Data interchange modules like YAML and JSON can now C to encodeIroundtrip Boolean values. =head1 FUNCTIONS This module defines the following functions: =over =item C This function returns a scalar value which will evaluate to true. The value is a singleton object, meaning there is only one "true" value in a Perl process at any time. You can check to see whether the value is the "true" object with the isTrue function described below. =item C This function returns a scalar value which will evaluate to false. The value is a singleton object, meaning there is only one "false" value in a Perl process at any time. You can check to see whether the value is the "false" object with the isFalse function described below. =item C Casts the scalar value to a boolean value. If C<$scalar> is true, it returns C, otherwise it returns C. =item C Returns C if the scalar passed to it is the C object. Returns C otherwise. =item C Returns C if the scalar passed to it is the C object. Returns C otherwise. =item C Returns C if the scalar passed to it is the C or C object. Returns C otherwise. =back =head1 METHODS Since true and false return objects, you can call methods on them. =over =item C<< $boolean->isTrue >> Same as isTrue($boolean). =item C<< $boolean->isFalse >> Same as isFalse($boolean). =back =head1 USE OPTIONS By default this module exports the C, C and C functions. The module also defines these export tags: =over =item C<:all> Exports C, C, C, C, C, C =back =head1 DEPRECATIONS This module offered an export tag, C<-truth>, that overrides the Perl interpreter's internal values for true and false. This has been found to corrupt the interpreter in some circumstances. Also, these overrides will no longer be possible as of Perl 5.22. Therefore, the C<-truth> import tag is deprecated. =head1 JSON SUPPORT JSON::MaybeXS (or less preferably JSON.pm ) will encode Perl data with boolean.pm values correctly if you use the C option: use JSON::MaybeXS; use boolean -truth; my $json = JSON::MaybeXS->new->convert_blessed; say $json->encode({false => (0 == 1)}); # Says: '{"false":false}', =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT AND LICENSE Copyright 2007-2016. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut author-pod-syntax.t100644000000000000 50312737757574 16306 0ustar00rootroot000000000000boolean-0.46/t#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 000-compile-modules.t100644000000000000 44112737757574 16274 0ustar00rootroot000000000000boolean-0.46/t# This test does a basic `use` check on all the code. use Test::More; use File::Find; sub test { s{^lib/(.*)\.pm$}{$1} or return; s{/}{::}g; use_ok $_; } $ENV{PERL_ZILD_TEST_000_COMPILE_MODULES} = 1; find { wanted => \&test, no_chdir => 1, }, 'lib'; done_testing;