some tweaks
[gitmo/Class-MOP.git] / MOP.xs
1
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5
6 /*
7 check_method_cache_flag:
8   check the PL_sub_generation 
9   ISA/method cache thing
10
11 get_code_info:
12   Pass in a coderef, returns:
13   [ $pkg_name, $coderef_name ] ie:
14   [ 'Foo::Bar', 'new' ]
15 */
16
17 MODULE = Class::MOP   PACKAGE = Class::MOP
18
19 SV*
20 check_package_cache_flag()
21   CODE:
22     RETVAL = newSViv(PL_sub_generation);
23   OUTPUT:
24     RETVAL
25
26 void
27 get_code_info(coderef)
28   SV* coderef
29   PREINIT:
30     char* name;
31     char* pkg;
32   PPCODE:
33
34     if( SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV){
35       coderef = SvRV(coderef);
36       name    = GvNAME( CvGV(coderef) );
37       pkg     = HvNAME( GvSTASH(CvGV(coderef)) );
38
39       EXTEND(SP, 2);
40       PUSHs(newSVpvn(pkg, strlen(pkg)));
41       PUSHs(newSVpvn(name, strlen(name)));
42     }
43