File Coverage

lib/Syntax/Operator/Equ.xs
Criterion Covered Total %
statement 27 27 100.0
branch 32 44 72.7
condition n/a
subroutine n/a
pod n/a
total 59 71 83.1


line stmt bran cond sub pod time code
1             /* You may distribute under the terms of either the GNU General Public License
2             * or the Artistic License (the same terms as Perl itself)
3             *
4             * (C) Paul Evans, 2016-2022 -- leonerd@leonerd.org.uk
5             */
6             #define PERL_NO_GET_CONTEXT
7              
8             #include "EXTERN.h"
9             #include "perl.h"
10             #include "XSUB.h"
11              
12             #include "XSParseInfix.h"
13              
14             #include "sv_numeq.c.inc"
15             #include "sv_streq.c.inc"
16              
17 5           static OP *pp_equ_numeric(pTHX)
18             {
19 5           dSP;
20             dTARG;
21 5           SV *lhs = TOPs, *rhs = TOPm1s;
22              
23 5 50         SvGETMAGIC(lhs);
24 5 50         SvGETMAGIC(rhs);
25              
26 5 100         bool lundef = !SvOK(lhs), rundef = !SvOK(rhs);
    50          
    50          
    100          
    50          
    50          
27              
28 5 100         if(lundef || rundef) {
29 3           POPs;
30 3 100         SETs(lundef && rundef ? &PL_sv_yes : &PL_sv_no);
31 3           RETURN;
32             }
33              
34 2           POPs;
35 2 100         SETs(sv_numeq_flags(lhs, rhs, 0) ? &PL_sv_yes : &PL_sv_no);
36 2           RETURN;
37             }
38              
39 5           static OP *pp_equ_stringy(pTHX)
40             {
41 5           dSP;
42             dTARG;
43 5           SV *lhs = TOPs, *rhs = TOPm1s;
44              
45 5 50         SvGETMAGIC(lhs);
46 5 50         SvGETMAGIC(rhs);
47              
48 5 100         bool lundef = !SvOK(lhs), rundef = !SvOK(rhs);
    50          
    50          
    100          
    50          
    50          
49              
50 5 100         if(lundef || rundef) {
51 3           POPs;
52 3 100         SETs(lundef && rundef ? &PL_sv_yes : &PL_sv_no);
53 3           RETURN;
54             }
55              
56 2           POPs;
57 2 100         SETs(sv_streq_flags(lhs, rhs, 0) ? &PL_sv_yes : &PL_sv_no);
58 2           RETURN;
59             }
60              
61             static const struct XSParseInfixHooks hooks_numeric = {
62             .cls = XPI_CLS_EQUALITY,
63             .wrapper_func_name = "Syntax::Operator::Equ::is_numequ",
64             .permit_hintkey = "Syntax::Operator::Equ/equ",
65             .ppaddr = &pp_equ_numeric,
66             };
67              
68             static const struct XSParseInfixHooks hooks_stringy = {
69             .cls = XPI_CLS_EQUALITY,
70             .wrapper_func_name = "Syntax::Operator::Equ::is_strequ",
71             .permit_hintkey = "Syntax::Operator::Equ/equ",
72             .ppaddr = &pp_equ_stringy,
73             };
74              
75             MODULE = Syntax::Operator::Equ PACKAGE = Syntax::Operator::Equ
76              
77             BOOT:
78 6           boot_xs_parse_infix(0.26);
79              
80             register_xs_parse_infix("===", &hooks_numeric, NULL);
81             register_xs_parse_infix("equ", &hooks_stringy, NULL);