File Coverage

lib/Syntax/Operator/Matches.xs
Criterion Covered Total %
statement 51 51 100.0
branch 24 34 70.5
condition n/a
subroutine n/a
pod n/a
total 75 85 88.2


line stmt bran cond sub pod time code
1             #define PERL_NO_GET_CONTEXT
2              
3             #include "EXTERN.h"
4             #include "perl.h"
5             #include "XSUB.h"
6              
7             #include "XSParseInfix.h"
8              
9             #define sv_defined(sv) (sv && (SvIOK(sv) || SvNOK(sv) || SvPOK(sv) || SvROK(sv)))
10              
11 92           static bool test_pp_matches( pTHX_ SV *a, SV *b )
12             {
13 92           dSP;
14             dTARG;
15              
16 92           SvGETMAGIC( a );
17 92           SvGETMAGIC( b );
18              
19 92 50         if ( ! sv_defined( b ) ) {
    100          
20 26 50         return( sv_defined( a ) ? FALSE : TRUE );
    100          
21             }
22              
23 70 100         else if ( ! SvROK( b ) ) {
24 24           return( sv_eq( a, b ) ? TRUE : FALSE );
25             }
26              
27 46 100         else if ( sv_isobject( b ) && sv_derived_from( b, "Type::Tiny" ) ) {
    100          
28             int count;
29             SV *ret;
30             bool ret_truth;
31 2           ENTER;
32 2           SAVETMPS;
33 2 50         PUSHMARK(SP);
34 2 50         XPUSHs(b);
35 2 50         XPUSHs(a);
36 2           PUTBACK;
37 2           count = call_method( "check", G_SCALAR );
38 2           SPAGAIN;
39 2           ret = POPs;
40 2           ret_truth = SvTRUE( ret );
41 2           PUTBACK;
42 2 50         FREETMPS;
43 2           LEAVE;
44              
45 2           return( ret_truth );
46             }
47              
48             else {
49             int count;
50             bool r;
51 44           ENTER;
52 44           SAVETMPS;
53 44 50         PUSHMARK( SP );
54 44 50         XPUSHs( a );
55 44 50         XPUSHs( b );
56 44           PUTBACK;
57 44           count = call_pv( "match::simple::match", G_SCALAR );
58 42           SPAGAIN;
59 42           r = POPi;
60 42           PUTBACK;
61 42 50         FREETMPS;
62 42           LEAVE;
63              
64 42           return( r != 0 ? TRUE : FALSE );
65             }
66              
67             // Shouldn't happen
68             return FALSE;
69             }
70              
71 48           static OP *pp_matches( pTHX )
72             {
73 48           dSP;
74             dTARG;
75 48           SV *b = TOPs, *a = TOPm1s;
76 48           POPs;
77 48 100         SETs( test_pp_matches( aTHX_ a, b ) ? &PL_sv_yes : &PL_sv_no );
78 46           RETURN;
79             }
80              
81 44           static OP *pp_mismatches( pTHX )
82             {
83 44           dSP;
84             dTARG;
85 44           SV *b = TOPs, *a = TOPm1s;
86 44           POPs;
87 44 100         SETs( test_pp_matches( aTHX_ a, b ) ? &PL_sv_no : &PL_sv_yes );
88 44           RETURN;
89             }
90              
91             static const struct XSParseInfixHooks hooks_matches = {
92             .cls = XPI_CLS_MATCH_MISC,
93             .permit_hintkey = "Syntax::Operator::Matches/matches",
94             .ppaddr = &pp_matches,
95             };
96              
97             static const struct XSParseInfixHooks hooks_mismatches = {
98             .cls = XPI_CLS_MATCH_MISC,
99             .permit_hintkey = "Syntax::Operator::Matches/mismatches",
100             .ppaddr = &pp_mismatches,
101             };
102              
103             MODULE = Syntax::Operator::Matches PACKAGE = Syntax::Operator::Matches
104              
105             BOOT:
106 4           boot_xs_parse_infix( 0.26 );
107 4           register_xs_parse_infix( "matches", &hooks_matches, NULL );
108 4           register_xs_parse_infix( "mismatches", &hooks_mismatches, NULL );