stop closing over the method metaobject
[gitmo/Moose.git] / mop.h
1 #ifndef __MOP_H__
2 #define __MOP_H__
3
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7
8 #define NEED_newRV_noinc
9 #define NEED_sv_2pv_flags
10 #define NEED_sv_2pv_nolen
11 #include "ppport.h"
12
13 #define MOP_CALL_BOOT(name)  mop_call_xs(aTHX_ name, cv, mark);
14
15 #ifndef XSPROTO
16 #define XSPROTO(name) XS(name)
17 #endif
18
19 void mop_call_xs (pTHX_ XSPROTO(subaddr), CV *cv, SV **mark);
20
21 typedef enum {
22     KEY__expected_method_class,
23     KEY_ISA,
24     KEY_VERSION,
25     KEY_accessor,
26     KEY_associated_class,
27     KEY_associated_metaclass,
28     KEY_associated_methods,
29     KEY_attribute_metaclass,
30     KEY_attributes,
31     KEY_body,
32     KEY_builder,
33     KEY_clearer,
34     KEY_constructor_class,
35     KEY_constructor_name,
36     KEY_definition_context,
37     KEY_destructor_class,
38     KEY_immutable_trait,
39     KEY_init_arg,
40     KEY_initializer,
41     KEY_insertion_order,
42     KEY_instance_metaclass,
43     KEY_is_inline,
44     KEY_method_metaclass,
45     KEY_methods,
46     KEY_name,
47     KEY_package,
48     KEY_package_name,
49     KEY_predicate,
50     KEY_reader,
51     KEY_wrapped_method_metaclass,
52     KEY_writer,
53     KEY_package_cache_flag,
54     KEY__version,
55     key_last,
56 } mop_prehashed_key_t;
57
58 #define KEY_FOR(name)  mop_prehashed_key_for(KEY_ ##name)
59 #define HASH_FOR(name) mop_prehashed_hash_for(KEY_ ##name)
60
61 void mop_prehash_keys (void);
62 SV *mop_prehashed_key_for (mop_prehashed_key_t key);
63 U32 mop_prehashed_hash_for (mop_prehashed_key_t key);
64
65 #define INSTALL_SIMPLE_READER(klass, name)  INSTALL_SIMPLE_READER_WITH_KEY(klass, name, name)
66 #define INSTALL_SIMPLE_READER_WITH_KEY(klass, name, key) \
67     { \
68         CV *cv = newXS("Class::MOP::" #klass "::" #name, mop_xs_simple_reader, __FILE__); \
69         CvXSUBANY(cv).any_i32 = KEY_ ##key; \
70     }
71
72 XS(mop_xs_simple_reader);
73
74 extern SV *mop_method_metaclass;
75 extern SV *mop_associated_metaclass;
76 extern SV *mop_wrap;
77
78 UV mop_check_package_cache_flag(pTHX_ HV *stash);
79 int mop_get_code_info (SV *coderef, char **pkg, char **name);
80 SV *mop_call0(pTHX_ SV *const self, SV *const method);
81
82 typedef enum {
83     TYPE_FILTER_NONE,
84     TYPE_FILTER_CODE,
85     TYPE_FILTER_ARRAY,
86     TYPE_FILTER_IO,
87     TYPE_FILTER_HASH,
88     TYPE_FILTER_SCALAR,
89 } type_filter_t;
90
91 typedef bool (*get_package_symbols_cb_t) (const char *, STRLEN, SV *, void *);
92
93 void mop_get_package_symbols(HV *stash, type_filter_t filter, get_package_symbols_cb_t cb, void *ud);
94 HV *mop_get_all_package_symbols (HV *stash, type_filter_t filter);
95
96 #endif