Refactor how prehashed hash keys work.
[gitmo/Class-MOP.git] / xs / Method.xs
1 #include "mop.h"
2
3 MODULE = Class::MOP::Method   PACKAGE = Class::MOP::Method
4
5 PROTOTYPES: DISABLE
6
7 void
8 name(self)
9     SV *self
10     PREINIT:
11         register HE *he;
12     PPCODE:
13         if ( ! SvROK(self) ) {
14             die("Cannot call name as a class method");
15         }
16
17         if ( (he = hv_fetch_ent((HV *)SvRV(self), KEY_FOR(name), 0, HASH_FOR(name))) )
18             XPUSHs(HeVAL(he));
19         else
20             ST(0) = &PL_sv_undef;
21
22 void
23 package_name(self)
24     SV *self
25     PREINIT:
26         register HE *he;
27     PPCODE:
28         if ( ! SvROK(self) ) {
29             die("Cannot call package_name as a class method");
30         }
31
32         if ( (he = hv_fetch_ent((HV *)SvRV(self), KEY_FOR(package_name), 0, HASH_FOR(package_name))) )
33             XPUSHs(HeVAL(he));
34         else
35             ST(0) = &PL_sv_undef;
36
37 void
38 body(self)
39     SV *self
40     PREINIT:
41         register HE *he;
42     PPCODE:
43         if ( ! SvROK(self) ) {
44             die("Cannot call body as a class method");
45         }
46
47         if ( (he = hv_fetch_ent((HV *)SvRV(self), KEY_FOR(body), 0, HASH_FOR(body))) )
48             XPUSHs(HeVAL(he));
49         else
50             ST(0) = &PL_sv_undef;