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