Syntax-Operator-Equ-0.06000755001750001750 014452064455 14000 5ustar00leoleo000000000000Syntax-Operator-Equ-0.06/.editorconfig000444001750001750 5314452064455 16550 0ustar00leoleo000000000000root = true [*.{pm,pl,t}] indent_size = 3 Syntax-Operator-Equ-0.06/Build.PL000444001750001750 145314452064455 15434 0ustar00leoleo000000000000use v5; use strict; use warnings; use Module::Build; use XS::Parse::Infix::Builder; my @extra_compiler_flags = qw( -Ihax ); my $build = Module::Build->new( module_name => "Syntax::Operator::Equ", test_requires => { 'Test2::V0' => 0, }, configure_requires => { 'Module::Build' => '0.4004', # test_requires 'XS::Parse::Infix::Builder' => '0.26', }, requires => { 'perl' => '5.014', # pluggable keywords, XOP 'XS::Parse::Infix' => '0.26', }, license => 'perl', create_license => 1, create_readme => 1, meta_merge => { resources => { x_IRC => "irc://irc.perl.org/#io-async", }, }, extra_compiler_flags => \@extra_compiler_flags, ); XS::Parse::Infix::Builder->extend_module_build( $build ); $build->create_build_script; Syntax-Operator-Equ-0.06/Changes000444001750001750 202514452064455 15427 0ustar00leoleo000000000000Revision history for Syntax-Operator-Equ 0.06 2023-07-07 [CHANGES] * Added Syntax::Operator::Eqr * Adjusted documentation for the release of Perl v5.38 * Swap all of the unit tests from Test::More to Test2::V0 0.05 2022-12-25 [CHANGES] * Capture t/80in+equ.t from Syntax-Operator-In * Document that PL_infix_plugin now works on development perl version v5.37.7 0.04 2022-10-24 [CHANGES] * Updates for XS::Parse::Infix v0.26 0.03 2022-06-26 [CHANGES] * Use the new Perl API functions sv_numeq_flags() and sv_streq_flags() where they exist; provide hax/ back-compat where they do not * Add unit tests for automatic deparse logic from XS::Parse::Infix 0.02 2021-09-06 [CHANGES] * Provide some plain-perl wrapper functions so perls without PL_infix_plugin can still use these operators 0.01 2021-08-31 First version, released on an unsuspecting world. Syntax-Operator-Equ-0.06/LICENSE000444001750001750 4375514452064455 15200 0ustar00leoleo000000000000This software is copyright (c) 2023 by Paul Evans . 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) 2023 by Paul Evans . 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) 2023 by Paul Evans . 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Syntax-Operator-Equ-0.06/MANIFEST000444001750001750 55514452064455 15253 0ustar00leoleo000000000000.editorconfig Build.PL Changes hax/sv_numeq.c.inc hax/sv_streq.c.inc lib/Syntax/Operator/Eqr.pm lib/Syntax/Operator/Equ.pm lib/Syntax/Operator/Equ.xs LICENSE MANIFEST This list of files META.json META.yml README t/00use.t t/01equ-stringy.t t/02equ-numeric.t t/03eqr.t t/10getmagic.t t/11func.t t/12deparse.t t/80in+equ.t t/80match-eqr.t t/80match-equ.t t/99pod.t Syntax-Operator-Equ-0.06/META.json000444001750001750 260214452064455 15556 0ustar00leoleo000000000000{ "abstract" : "equality operators that distinguish C", "author" : [ "Paul Evans " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4231", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Syntax-Operator-Equ", "prereqs" : { "build" : { "requires" : { "ExtUtils::CBuilder" : "0" } }, "configure" : { "requires" : { "Module::Build" : "0.4004", "XS::Parse::Infix::Builder" : "0.26" } }, "runtime" : { "requires" : { "XS::Parse::Infix" : "0.26", "perl" : "5.014" } }, "test" : { "requires" : { "Test2::V0" : "0" } } }, "provides" : { "Syntax::Operator::Eqr" : { "file" : "lib/Syntax/Operator/Eqr.pm", "version" : "0.06" }, "Syntax::Operator::Equ" : { "file" : "lib/Syntax/Operator/Equ.pm", "version" : "0.06" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "x_IRC" : "irc://irc.perl.org/#io-async" }, "version" : "0.06", "x_serialization_backend" : "JSON::PP version 4.07" } Syntax-Operator-Equ-0.06/META.yml000444001750001750 155314452064455 15412 0ustar00leoleo000000000000--- abstract: 'equality operators that distinguish C' author: - 'Paul Evans ' build_requires: ExtUtils::CBuilder: '0' Test2::V0: '0' configure_requires: Module::Build: '0.4004' XS::Parse::Infix::Builder: '0.26' dynamic_config: 1 generated_by: 'Module::Build version 0.4231, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Syntax-Operator-Equ provides: Syntax::Operator::Eqr: file: lib/Syntax/Operator/Eqr.pm version: '0.06' Syntax::Operator::Equ: file: lib/Syntax/Operator/Equ.pm version: '0.06' requires: XS::Parse::Infix: '0.26' perl: '5.014' resources: IRC: irc://irc.perl.org/#io-async license: http://dev.perl.org/licenses/ version: '0.06' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Syntax-Operator-Equ-0.06/README000444001750001750 673214452064455 15025 0ustar00leoleo000000000000NAME Syntax::Operator::Equ - equality operators that distinguish undef SYNOPSIS On Perl v5.38 or later: use v5.38; use Syntax::Operator::Equ; if($x equ $y) { say "x and y are both undef, or both defined and equal strings"; } if($i === $j) { say "i and j are both undef, or both defined and equal numbers"; } Or via Syntax::Keyword::Match on Perl v5.14 or later: use v5.14; use Syntax::Keyword::Match; use Syntax::Operator::Equ; match($str : equ) { case(undef) { say "The variable is not defined" } case("") { say "The variable is defined but is empty" } default { say "The string is non-empty" } } DESCRIPTION This module provides infix operators that implement equality tests of strings or numbers similar to perl's eq and == operators, except that they consider undef to be a distinct value, separate from the empty string or the number zero. These operators do not warn when either or both operands are undef. They yield true if both operands are undef, false if exactly one operand is, or otherwise behave the same as the regular string or number equality tests if both operands are defined. Support for custom infix operators was added in the Perl 5.37.x development cycle and is available from development release v5.37.7 onwards, and therefore in Perl v5.38 onwards. The documentation of XS::Parse::Infix describes the situation in more detail. While Perl versions before this do not support custom infix operators, they can still be used via XS::Parse::Infix and hence XS::Parse::Keyword. Custom keywords which attempt to parse operator syntax may be able to use these. One such module is Syntax::Keyword::Match; see the SYNOPSIS example given above. OPERATORS equ my $equal = $lhs equ $rhs; Yields true if both operands are undef, or if both are defined and contain equal string values. Yields false if given exactly one undef, or two unequal strings. === my $equal = $lhs === $rhs; Yields true if both operands are undef, or if both are defined and contain equal numerical values. Yields false if given exactly one undef, or two unequal numbers. Note that while this operator will not cause warnings about uninitialized values, it can still warn if given defined stringy values that are not valid as numbers. FUNCTIONS As a convenience, the following functions may be imported which implement the same behaviour as the infix operators, though are accessed via regular function call syntax. These wrapper functions are implemented using XS::Parse::Infix, and thus have an optimising call-checker attached to them. In most cases, code which calls them should not in fact have the full runtime overhead of a function call because the underlying test operator will get inlined into the calling code at compiletime. In effect, code calling these functions should run with the same performance as code using the infix operators directly. is_strequ my $equal = is_strequ( $lhs, $rhs ); A function version of the "equ" stringy operator. is_numequ my $equal = is_numequ( $lhs, $rgh ); A function version of the "===" numerical operator. SEE ALSO * Syntax::Operator::Eqr - string equality and regexp match operator AUTHOR Paul Evans Syntax-Operator-Equ-0.06/hax000755001750001750 014452064455 14560 5ustar00leoleo000000000000Syntax-Operator-Equ-0.06/hax/sv_numeq.c.inc000444001750001750 332214452064455 17466 0ustar00leoleo000000000000/* vi: set ft=c : */ #ifndef sv_numeq_flags # define sv_numeq_flags(lhs, rhs, flags) S_sv_numeq_flags(aTHX_ lhs, rhs, flags) static bool S_sv_numeq_flags(pTHX_ SV *lhs, SV *rhs, U32 flags) { if(flags & SV_GMAGIC) { if(lhs) SvGETMAGIC(lhs); if(rhs) SvGETMAGIC(rhs); } if(!lhs) lhs = &PL_sv_undef; if(!rhs) rhs = &PL_sv_undef; if(!(flags & SV_SKIP_OVERLOAD) && (SvAMAGIC(lhs) || SvAMAGIC(rhs))) { SV *ret = amagic_call(lhs, rhs, eq_amg, 0); if(ret) return SvTRUE(ret); } /* We'd like to call Perl_do_ncmp, except that isn't an exported API function * Here's a near-copy of it for num-equality testing purposes */ #ifndef HAVE_BOOL_SvIV_please_nomg /* Before perl 5.18, SvIV_please_nomg() was void-returning */ SvIV_please_nomg(lhs); SvIV_please_nomg(rhs); #endif if( #ifdef HAVE_BOOL_SvIV_please_nomg SvIV_please_nomg(rhs) && SvIV_please_nomg(lhs) #else SvIOK(lhs) && SvIOK(rhs) #endif ) { /* Compare as integers */ switch((SvUOK(lhs) ? 1 : 0) | (SvUOK(rhs) ? 2 : 0)) { case 0: /* IV == IV */ return SvIVX(lhs) == SvIVX(rhs); case 1: /* UV == IV */ { const IV riv = SvUVX(rhs); if(riv < 0) return 0; return (SvUVX(lhs) == riv); } case 2: /* IV == UV */ { const IV liv = SvUVX(lhs); if(liv < 0) return 0; return (liv == SvUVX(rhs)); } case 3: /* UV == UV */ return SvUVX(lhs) == SvUVX(rhs); } } else { /* Compare NVs */ NV const rnv = SvNV_nomg(rhs); NV const lnv = SvNV_nomg(lhs); return lnv == rnv; } } #endif #ifndef sv_numeq # define sv_numeq(lhs, rhs) sv_numeq_flags(lhs, rhs, 0) #endif Syntax-Operator-Equ-0.06/hax/sv_streq.c.inc000444001750001750 122114452064455 17473 0ustar00leoleo000000000000/* vi: set ft=c : */ #ifndef sv_streq_flags # define sv_streq_flags(lhs, rhs, flags) S_sv_streq_flags(aTHX_ lhs, rhs, flags) static bool S_sv_streq_flags(pTHX_ SV *lhs, SV *rhs, U32 flags) { if(flags & SV_GMAGIC) { if(lhs) SvGETMAGIC(lhs); if(rhs) SvGETMAGIC(rhs); } if(!lhs) lhs = &PL_sv_undef; if(!rhs) rhs = &PL_sv_undef; if(!(flags & SV_SKIP_OVERLOAD) && (SvAMAGIC(lhs) || SvAMAGIC(rhs))) { SV *ret = amagic_call(lhs, rhs, seq_amg, 0); if(ret) return SvTRUE(ret); } return sv_eq_flags(lhs, rhs, 0); } #endif #ifndef sv_streq # define sv_streq(lhs, rhs) sv_streq_flags(lhs, rhs, 0) #endif Syntax-Operator-Equ-0.06/lib000755001750001750 014452064455 14546 5ustar00leoleo000000000000Syntax-Operator-Equ-0.06/lib/Syntax000755001750001750 014452064455 16034 5ustar00leoleo000000000000Syntax-Operator-Equ-0.06/lib/Syntax/Operator000755001750001750 014452064455 17627 5ustar00leoleo000000000000Syntax-Operator-Equ-0.06/lib/Syntax/Operator/Eqr.pm000444001750001750 1070614452064455 21075 0ustar00leoleo000000000000# You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # # (C) Paul Evans, 2023 -- leonerd@leonerd.org.uk package Syntax::Operator::Eqr 0.06; use v5.14; use warnings; use Carp; # Load the XS code require Syntax::Operator::Equ; =head1 NAME C - string equality and regexp match operator =head1 SYNOPSIS On Perl v5.38 or later: use v5.38; use Syntax::Operator::Eqr; if($str eqr $pat) { say "x and y are both undef, or both defined and equal strings, " . "or y is a regexp that matches x"; } Or via L on Perl v5.14 or later: use v5.14; use Syntax::Keyword::Match; use Syntax::Operator::Eqr; match($str : eqr) { case(undef) { say "The variable is not defined" } case("") { say "The variable is defined but is empty" } case(qr/^.$/) { say "The variable contains exactly one character" } default { say "The string contains more than one" } } =head1 DESCRIPTION This module provides an infix operators that implements a matching operation whose behaviour depends on whether the right-hand side operand is undef, a quoted regexp object, or some other value. If undef, it is true only if the lefthand operand is also undef. If a quoted regexp object, it behaves like Perl's C<=~> pattern-matching operator. If neither, it behaves like the C operator. This operator does not warn when either or both operands are C. Support for custom infix operators was added in the Perl 5.37.x development cycle and is available from development release v5.37.7 onwards, and therefore in Perl v5.38 onwards. The documentation of L describes the situation in more detail. While Perl versions before this do not support custom infix operators, they can still be used via C and hence L. Custom keywords which attempt to parse operator syntax may be able to use these. One such module is L; see the SYNOPSIS example given above. =head2 Comparison With Smartmatch At first glance it would appear a little similar to core perl's ill-fated smartmatch operator (C<~~>), but this version is much simpler. It does not try to determine if stringy or numerical match is preferred, nor does it attempt to make sense of any C, C, C or other complicated container values on either side. Its behaviour is in effect entirely determined by the value on its righthand side - the three cases of C, some C object, or anything else. This in particular makes it behave sensibly with the C syntax provided by L. =cut sub import { my $class = shift; my $caller = caller; $class->import_into( $caller, @_ ); } sub import_into { my $class = shift; my ( $caller, @syms ) = @_; @syms or @syms = qw( eqr ); my %syms = map { $_ => 1 } @syms; $^H{"Syntax::Operator::Eqr/eqr"}++ if delete $syms{eqr}; foreach (qw( is_eqr )) { no strict 'refs'; *{"${caller}::$_"} = \&{$_} if delete $syms{$_}; } croak "Unrecognised import symbols @{[ keys %syms ]}" if keys %syms; } =head1 OPERATORS =head2 eqr my $matches = $lhs eqr $rhs; Yields true if both operands are C, or if the right-hand side is a quoted regexp value that matches the left-hand side, or if both are defined and contain equal string values. Yields false if given exactly one C, two unequal strings, or a string that does not match the pattern. =cut =head1 FUNCTIONS As a convenience, the following functions may be imported which implement the same behaviour as the infix operators, though are accessed via regular function call syntax. These wrapper functions are implemented using L, and thus have an optimising call-checker attached to them. In most cases, code which calls them should not in fact have the full runtime overhead of a function call because the underlying test operator will get inlined into the calling code at compiletime. In effect, code calling these functions should run with the same performance as code using the infix operators directly. =head2 is_eqr my $matches = is_eqr( $lhs, $rhs ); A function version of the L stringy operator. =cut =head1 SEE ALSO =over 4 =item * L - equality operators that distinguish C =back =head1 AUTHOR Paul Evans =cut 0x55AA; Syntax-Operator-Equ-0.06/lib/Syntax/Operator/Equ.pm000444001750001750 1032114452064455 21071 0ustar00leoleo000000000000# You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # # (C) Paul Evans, 2021-2023 -- leonerd@leonerd.org.uk package Syntax::Operator::Equ 0.06; use v5.14; use warnings; use Carp; require XSLoader; XSLoader::load( __PACKAGE__, our $VERSION ); =head1 NAME C - equality operators that distinguish C =head1 SYNOPSIS On Perl v5.38 or later: use v5.38; use Syntax::Operator::Equ; if($x equ $y) { say "x and y are both undef, or both defined and equal strings"; } if($i === $j) { say "i and j are both undef, or both defined and equal numbers"; } Or via L on Perl v5.14 or later: use v5.14; use Syntax::Keyword::Match; use Syntax::Operator::Equ; match($str : equ) { case(undef) { say "The variable is not defined" } case("") { say "The variable is defined but is empty" } default { say "The string is non-empty" } } =head1 DESCRIPTION This module provides infix operators that implement equality tests of strings or numbers similar to perl's C and C<==> operators, except that they consider C to be a distinct value, separate from the empty string or the number zero. These operators do not warn when either or both operands are C. They yield true if both operands are C, false if exactly one operand is, or otherwise behave the same as the regular string or number equality tests if both operands are defined. Support for custom infix operators was added in the Perl 5.37.x development cycle and is available from development release v5.37.7 onwards, and therefore in Perl v5.38 onwards. The documentation of L describes the situation in more detail. While Perl versions before this do not support custom infix operators, they can still be used via C and hence L. Custom keywords which attempt to parse operator syntax may be able to use these. One such module is L; see the SYNOPSIS example given above. =cut sub import { my $class = shift; my $caller = caller; $class->import_into( $caller, @_ ); } sub import_into { my $class = shift; my ( $caller, @syms ) = @_; @syms or @syms = qw( equ ); my %syms = map { $_ => 1 } @syms; $^H{"Syntax::Operator::Equ/equ"}++ if delete $syms{equ}; foreach (qw( is_strequ is_numequ )) { no strict 'refs'; *{"${caller}::$_"} = \&{$_} if delete $syms{$_}; } croak "Unrecognised import symbols @{[ keys %syms ]}" if keys %syms; } =head1 OPERATORS =head2 equ my $equal = $lhs equ $rhs; Yields true if both operands are C, or if both are defined and contain equal string values. Yields false if given exactly one C, or two unequal strings. =head2 === my $equal = $lhs === $rhs; Yields true if both operands are C, or if both are defined and contain equal numerical values. Yields false if given exactly one C, or two unequal numbers. Note that while this operator will not cause warnings about uninitialized values, it can still warn if given defined stringy values that are not valid as numbers. =cut =head1 FUNCTIONS As a convenience, the following functions may be imported which implement the same behaviour as the infix operators, though are accessed via regular function call syntax. These wrapper functions are implemented using L, and thus have an optimising call-checker attached to them. In most cases, code which calls them should not in fact have the full runtime overhead of a function call because the underlying test operator will get inlined into the calling code at compiletime. In effect, code calling these functions should run with the same performance as code using the infix operators directly. =head2 is_strequ my $equal = is_strequ( $lhs, $rhs ); A function version of the L stringy operator. =head2 is_numequ my $equal = is_numequ( $lhs, $rgh ); A function version of the L numerical operator. =cut =head1 SEE ALSO =over 4 =item * L - string equality and regexp match operator =back =head1 AUTHOR Paul Evans =cut 0x55AA; Syntax-Operator-Equ-0.06/lib/Syntax/Operator/Equ.xs000444001750001750 575314452064455 21104 0ustar00leoleo000000000000/* You may distribute under the terms of either the GNU General Public License * or the Artistic License (the same terms as Perl itself) * * (C) Paul Evans, 2016-2023 -- leonerd@leonerd.org.uk */ #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "XSParseInfix.h" #include "sv_numeq.c.inc" #include "sv_streq.c.inc" static OP *pp_equ_numeric(pTHX) { dSP; dTARG; SV *lhs = TOPs, *rhs = TOPm1s; SvGETMAGIC(lhs); SvGETMAGIC(rhs); bool lundef = !SvOK(lhs), rundef = !SvOK(rhs); if(lundef || rundef) { POPs; SETs(lundef && rundef ? &PL_sv_yes : &PL_sv_no); RETURN; } POPs; SETs(sv_numeq_flags(lhs, rhs, 0) ? &PL_sv_yes : &PL_sv_no); RETURN; } static bool test_stringy_equ(pTHX_ SV *lhs, SV *rhs, bool test_rhs_regexp) { SvGETMAGIC(lhs); SvGETMAGIC(rhs); bool lundef = !SvOK(lhs), rundef = !SvOK(rhs); if(lundef || rundef) { return lundef && rundef; } if(test_rhs_regexp && SvRXOK(rhs)) { /* There isn't an API function for this so we'll have to do some * PL_op and stack hackery. Stolen from * https://metacpan.org/release/LEONT/Syntax-Infix-Smartmatch-0.001/source/lib/Syntax/Infix/Smartmatch.xs */ dSP; REGEXP *re = (REGEXP *)SvRV(rhs); PMOP *const matcher = cPMOPx(newPMOP(OP_MATCH, OPf_WANT_SCALAR | OPf_STACKED)); PM_SETRE(matcher, ReREFCNT_inc(re)); ENTER; SAVEFREEOP((OP *)matcher); SAVEOP(); PL_op = (OP *)matcher; XPUSHs(lhs); PUTBACK; (void)PL_ppaddr[OP_MATCH](aTHX); SPAGAIN; bool result = SvTRUEx(POPs); LEAVE; return result; } return sv_streq_flags(lhs, rhs, 0); } static OP *pp_equ_stringy(pTHX) { dSP; dTARG; SV *lhs = TOPm1s, *rhs = TOPs; POPs; SETs(test_stringy_equ(aTHX_ lhs, rhs, FALSE) ? &PL_sv_yes : &PL_sv_no); RETURN; } static OP *pp_eqr(pTHX) { dSP; dTARG; SV *lhs = TOPm1s, *rhs = TOPs; POPs; SETs(test_stringy_equ(aTHX_ lhs, rhs, TRUE) ? &PL_sv_yes : &PL_sv_no); RETURN; } static const struct XSParseInfixHooks hooks_equ_numeric = { .cls = XPI_CLS_EQUALITY, .wrapper_func_name = "Syntax::Operator::Equ::is_numequ", .permit_hintkey = "Syntax::Operator::Equ/equ", .ppaddr = &pp_equ_numeric, }; static const struct XSParseInfixHooks hooks_equ_stringy = { .cls = XPI_CLS_EQUALITY, .wrapper_func_name = "Syntax::Operator::Equ::is_strequ", .permit_hintkey = "Syntax::Operator::Equ/equ", .ppaddr = &pp_equ_stringy, }; static const struct XSParseInfixHooks hooks_eqr = { .cls = XPI_CLS_MATCH_MISC, .wrapper_func_name = "Syntax::Operator::Eqr::is_eqr", .permit_hintkey = "Syntax::Operator::Eqr/eqr", .ppaddr = &pp_eqr, }; MODULE = Syntax::Operator::Equ PACKAGE = Syntax::Operator::Equ BOOT: boot_xs_parse_infix(0.26); register_xs_parse_infix("===", &hooks_equ_numeric, NULL); register_xs_parse_infix("equ", &hooks_equ_stringy, NULL); register_xs_parse_infix("eqr", &hooks_eqr, NULL); Syntax-Operator-Equ-0.06/t000755001750001750 014452064455 14243 5ustar00leoleo000000000000Syntax-Operator-Equ-0.06/t/00use.t000444001750001750 24214452064455 15477 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; require Syntax::Operator::Equ; require Syntax::Operator::Eqr; pass( "Modules loaded" ); done_testing; Syntax-Operator-Equ-0.06/t/01equ-stringy.t000444001750001750 146314452064455 17221 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use Syntax::Operator::Equ; BEGIN { plan skip_all => "No PL_infix_plugin" unless XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN; } my $warnings = 0; $SIG{__WARN__} = sub { $warnings++ }; ok( "abc" equ "abc", 'identical strings'); ok(!("abc" equ "def"), 'different strings'); ok( undef equ undef, 'undef is undef'); ok(!("abc" equ undef), 'undef is not a string'); ok(!("" equ undef), 'undef is not empty string'); # overloaded 'eq' operator { my $equal; package Greedy { use overload 'eq' => sub { $equal }; } my $greedy = bless [], "Greedy"; $equal = 1; ok( $greedy equ "abc", 'Greedy is abc when set' ); $equal = 0; ok(!($greedy equ "abc"), 'Greedy is not abc when unset' ); } ok(!$warnings, 'no warnings'); done_testing; Syntax-Operator-Equ-0.06/t/02equ-numeric.t000444001750001750 152214452064455 17161 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use Syntax::Operator::Equ; BEGIN { plan skip_all => "No PL_infix_plugin" unless XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN; } my $warnings = 0; $SIG{__WARN__} = sub { $warnings++ }; ok( 123 === 123, 'identical numbers'); ok(!(123 === 456), 'different numbers'); ok( undef === undef, 'undef is undef'); ok(!(123 === undef), 'undef is not a number'); ok(!(0 === undef), 'undef is not zero'); ok( "1.0" === 1, 'values are compared numerically' ); # overloaded '==' operator { my $equal; package Greedy { use overload '==' => sub { $equal }; } my $greedy = bless [], "Greedy"; $equal = 1; ok( $greedy === 123, 'Greedy is 123 when set' ); $equal = 0; ok(!($greedy === 123), 'Greedy is not 123 when unset' ); } ok(!$warnings, 'no warnings'); done_testing; Syntax-Operator-Equ-0.06/t/03eqr.t000444001750001750 174614452064455 15527 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use Syntax::Operator::Eqr; BEGIN { plan skip_all => "No PL_infix_plugin" unless XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN; } my $warnings = 0; $SIG{__WARN__} = sub { $warnings++ }; ok( "abc" eqr "abc", 'identical strings'); ok(!("abc" eqr "def"), 'different strings'); ok( undef eqr undef, 'undef is undef'); ok(!("abc" eqr undef), 'undef is not a string'); ok(!("" eqr undef), 'undef is not empty string'); ok( "ghi" eqr qr/h/, 'string pattern match'); ok(!("ghi" eqr qr/H/), 'string pattern non-match'); my $pat = qr/i/; ok( "ghi" eqr $pat, 'string pattern match from variable'); # overloaded 'eq' operator { my $equal; package Greedy { use overload 'eq' => sub { $equal }; } my $greedy = bless [], "Greedy"; $equal = 1; ok( $greedy eqr "abc", 'Greedy is abc when set' ); $equal = 0; ok(!($greedy eqr "abc"), 'Greedy is not abc when unset' ); } ok(!$warnings, 'no warnings'); done_testing; Syntax-Operator-Equ-0.06/t/10getmagic.t000444001750001750 55014452064455 16466 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use Syntax::Operator::Equ; BEGIN { plan skip_all => "No PL_infix_plugin" unless XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN; } my $warnings = 0; $SIG{__WARN__} = sub { $warnings++ }; { ok( !defined $1, '$1 not yet set' ); "abc" =~ m/(\w+)/; ok( $1 equ "abc", '$1 is now abc' ); } done_testing; Syntax-Operator-Equ-0.06/t/11func.t000444001750001750 211414452064455 15660 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use Syntax::Operator::Equ qw( is_strequ is_numequ ); use Syntax::Operator::Eqr qw( is_eqr ); my $warnings = 0; $SIG{__WARN__} = sub { $warnings++ }; # stringy { ok( is_strequ( "abc", "abc" ), 'identical strings'); ok(!is_strequ( "abc", "def" ), 'different strings'); ok( is_strequ( undef, undef ), 'undef is undef'); ok(!is_strequ( "abc", undef ), 'undef is not a string'); ok(!is_strequ( "", undef ), 'undef is not empty string'); } # numeric { ok( is_numequ( 123, 123 ), 'identical numbers'); ok(!is_numequ( 123, 456 ), 'different numbers'); ok( is_numequ( undef, undef ), 'undef is undef'); ok(!is_numequ( 123, undef ), 'undef is not a number'); ok(!is_numequ( 0, undef ), 'undef is not zero'); } # eqr { ok( is_eqr( "abc", "abc" ), 'identical strings'); ok(!is_eqr( "abc", "def" ), 'different strings'); ok( is_eqr( "ghi", qr/h/ ), 'string pattern match'); ok(!is_eqr( "ghi", qr/H/ ), 'string pattern non-match'); } ok(!$warnings, 'no warnings'); done_testing; Syntax-Operator-Equ-0.06/t/12deparse.t000444001750001750 152214452064455 16353 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; use Syntax::Operator::Equ qw( is_strequ is_numequ ); use B::Deparse; my $deparser = B::Deparse->new(); sub is_deparsed { my ( $sub, $exp, $name ) = @_; my $got = $deparser->coderef2text( $sub ); # Deparsed output is '{ ... }'-wrapped $got = ( $got =~ m/^{\n(.*)\n}$/s )[0]; # Deparsed output will have a lot of pragmata and so on; just grab the # final line $got = ( split m/\n/, $got )[-1]; $got =~ s/^\s+//; is( $got, $exp, $name ); } is_deparsed sub { is_strequ $_[0], $_[1] }, 'Syntax::Operator::Equ::is_strequ($_[0], $_[1]);', 'is_streq'; if( XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN ) { use Syntax::Operator::Equ; is_deparsed eval('sub { $_[0] equ $_[1] }'), '$_[0] equ $_[1];', 'infix equ operator'; } done_testing; Syntax-Operator-Equ-0.06/t/80in+equ.t000444001750001750 230214452064455 16126 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; BEGIN { plan skip_all => "Syntax::Operator::In >= 0.03 is not available" unless eval { require Syntax::Operator::In; Syntax::Operator::In->VERSION( '0.03' ) }; plan skip_all => "Syntax::Operator::Equ is not available" unless eval { require Syntax::Operator::Equ; }; Syntax::Operator::In->import; Syntax::Operator::Equ->import; diag( "Syntax::Operator::In $Syntax::Operator::In::VERSION, " . "Syntax::Operator::Equ $Syntax::Operator::Equ::VERSION" ); } BEGIN { plan skip_all => "No PL_infix_plugin" unless XS::Parse::Infix::HAVE_PL_INFIX_PLUGIN; } ok( 0 in:=== (0..4) , '0 is in 0..4 by ==='); ok(not(6 in:=== (0..4)), '6 is not in 0..4 by ==='); ok( undef in:=== (1, undef, 3), 'undef is in list containing undef by ==='); ok(not(undef in:=== (0..4)), 'undef is not in 0..4 by ==='); ok( 'a' in:equ ('a'..'e') , 'a is in a..e by equ'); ok(not('f' in:equ ('a'..'e')), 'f is not in a..e by equ'); ok( undef in:equ ('a', undef, 'c'), 'undef is in list containing undef by equ'); ok(not(undef in:equ ('a', '', 'c')), 'undef is not in list containing empty string by equ'); done_testing; Syntax-Operator-Equ-0.06/t/80match-eqr.t000444001750001750 210414452064455 16613 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; BEGIN { plan skip_all => "Syntax::Keyword::Match >= 0.08 is not available" unless eval { require Syntax::Keyword::Match; Syntax::Keyword::Match->VERSION( '0.08' ); }; plan skip_all => "Syntax::Operator::Eqr is not available" unless eval { require Syntax::Operator::Eqr }; Syntax::Keyword::Match->import; Syntax::Operator::Eqr->import; diag( "Syntax::Keyword::Match $Syntax::Keyword::Match::VERSION, " . "Syntax::Operator::Eqr $Syntax::Operator::Eqr::VERSION" ); } # literals { my $ok; match("abc" : eqr) { case(qr/b/) { $ok++ } case("def") { fail('Not this one sorry'); } } ok( $ok, 'Literal match' ); } # undef is not "" { my $ok; match("" : eqr) { case(undef) { fail('Not this one sorry'); } case("") { $ok++ } } ok( $ok, '"" did not match undef' ); undef $ok; match(undef : eqr) { case("") { fail('Not this one sorry'); } case(undef) { $ok++ } } ok( $ok, 'undef did not match ""' ); } done_testing; Syntax-Operator-Equ-0.06/t/80match-equ.t000444001750001750 210414452064455 16616 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; BEGIN { plan skip_all => "Syntax::Keyword::Match >= 0.08 is not available" unless eval { require Syntax::Keyword::Match; Syntax::Keyword::Match->VERSION( '0.08' ); }; plan skip_all => "Syntax::Operator::Equ is not available" unless eval { require Syntax::Operator::Equ }; Syntax::Keyword::Match->import; Syntax::Operator::Equ->import; diag( "Syntax::Keyword::Match $Syntax::Keyword::Match::VERSION, " . "Syntax::Operator::Equ $Syntax::Operator::Equ::VERSION" ); } # literals { my $ok; match("abc" : equ) { case("abc") { $ok++ } case("def") { fail('Not this one sorry'); } } ok( $ok, 'Literal match' ); } # undef is not "" { my $ok; match("" : equ) { case(undef) { fail('Not this one sorry'); } case("") { $ok++ } } ok( $ok, '"" did not match undef' ); undef $ok; match(undef : equ) { case("") { fail('Not this one sorry'); } case(undef) { $ok++ } } ok( $ok, 'undef did not match ""' ); } done_testing; Syntax-Operator-Equ-0.06/t/99pod.t000444001750001750 25514452064455 15513 0ustar00leoleo000000000000#!/usr/bin/perl use v5.14; use warnings; use Test2::V0; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();