File Coverage

lib/Number/Iterator/XS.xs
Criterion Covered Total %
statement 35 42 83.3
branch 19 48 39.5
condition n/a
subroutine n/a
pod n/a
total 54 90 60.0


line stmt bran cond sub pod time code
1             #define PERL_NO_GET_CONTEXT // we'll define thread context if necessary (faster)
2             #include "EXTERN.h" // globals/constant import locations
3             #include "perl.h" // Perl symbols, structures and constants definition
4             #include "XSUB.h" // xsubpp functions and macros
5              
6             MODULE = Number::Iterator::XS PACKAGE = Number::Iterator::XS
7             PROTOTYPES: ENABLE
8             FALLBACK: TRUE
9              
10             SV *
11             new(...)
12             CODE:
13 2           HV * hash = newHV();;
14 2           SV * class = newSVsv(ST(0));
15 2           int i = 1;
16 6 100         for (i = 1; i < items; i += 2) {
17             STRLEN retlen;
18 4           char * key = SvPV(ST(i), retlen);
19 4           *hv_store(hash, key, retlen, newSVsv(ST(i + 1)), 0);
20             }
21 2 50         if (SvTYPE(class) != SVt_PV) {
22 0 0         char * name = HvNAME(SvSTASH(SvRV(class)));
    0          
    0          
    0          
    0          
    0          
23 0           class = newSVpv(name, strlen(name));
24             }
25 2           RETVAL = sv_bless(newRV_noinc((SV*)hash), gv_stashsv(class, 0));
26             OUTPUT:
27             RETVAL
28              
29             SV *
30             iterate(self, ...)
31             SV * self
32             OVERLOAD: ++
33             CODE:
34 6           HV * hash = (HV*)SvRV(self);
35 6 100         if (hv_exists(hash, "iterate", 7)) {
36 3           SV * cb = *hv_fetch(hash, "iterate", 7, 0);
37 3           dSP;
38 3 50         PUSHMARK(SP);
39 3 50         XPUSHs(self);
40 3           PUTBACK;
41 3           call_sv(cb, G_SCALAR);
42             } else {
43 3 100         double value = hv_exists(hash, "value", 5) ? SvNV(*hv_fetch(hash, "value", 5, 0)) : 0.;
44 3 50         double interval = hv_exists(hash, "interval", 8) ? SvNV(*hv_fetch(hash, "interval", 8, 0)) : 1.;
45 3           *hv_store(hash, "value", 5, newSVnv(value + interval), 0);
46             }
47 6           RETVAL = newSVsv(self);
48             OUTPUT:
49             RETVAL
50              
51              
52             SV *
53             deiterate(self, ...)
54             SV * self
55             OVERLOAD: --
56             CODE:
57 2           HV * hash = (HV*)SvRV(self);
58 2 100         if (hv_exists(hash, "deiterate", 9)) {
59 1           SV * cb = *hv_fetch(hash, "deiterate", 9, 0);
60 1           dSP;
61 1 50         PUSHMARK(SP);
62 1 50         XPUSHs(self);
63 1           PUTBACK;
64 1           call_sv(cb, G_SCALAR);
65             } else {
66 1 50         double value = hv_exists(hash, "value", 5) ? SvNV(*hv_fetch(hash, "value", 5, 0)) : 0;
67 1 50         double interval = hv_exists(hash, "interval", 8) ? SvNV(*hv_fetch(hash, "interval", 8, 0)) : 1;
68 1           *hv_store(hash, "value", 5, newSVnv(value - interval), 0);
69             }
70 2           RETVAL = newSVsv(self);;
71             OUTPUT:
72             RETVAL
73              
74             SV *
75             value(self, ...)
76             SV * self
77             OVERLOAD: \"\"
78             CODE:
79 7           HV * hash = (HV*)SvRV(self);
80 7 50         if (items > 1 && SvTYPE(ST(1)) == SVt_NV) {
    50          
81 0           *hv_store(hash, "value", 5, newSVsv(ST(1)), 0);
82             }
83 7 50         RETVAL = hv_exists(hash, "value", 5) ? newSVsv(*hv_fetch(hash, "value", 5, 0)) : newSViv(0);
84             OUTPUT:
85             RETVAL
86              
87             SV *
88             interval(self, ...)
89             SV * self
90             CODE:
91 0           HV * hash = (HV*)SvRV(self);
92 0 0         if (items > 1 && SvTYPE(ST(1)) == SVt_NV) {
    0          
93 0           *hv_store(hash, "interval", 8, newSVsv(ST(1)), 0);
94             }
95 0 0         RETVAL = hv_exists(hash, "interval", 8) ? newSVsv(*hv_fetch(hash, "interval", 8, 0)) : newSViv(1);
96             OUTPUT:
97             RETVAL