line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
* or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* (C) Paul Evans, 2021-2022 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
*/ |
6
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "EXTERN.h" |
9
|
|
|
|
|
|
|
#include "perl.h" |
10
|
|
|
|
|
|
|
#include "XSUB.h" |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#include "object_pad.h" |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#include "perl-backcompat.c.inc" |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
|
static void trigger_gen_accessor_ops(pTHX_ FieldMeta *fieldmeta, SV *hookdata, void *_funcdata, enum AccessorType type, struct AccessorGenerationCtx *ctx) |
17
|
|
|
|
|
|
|
{ |
18
|
2
|
100
|
|
|
|
|
if(type != ACCESSOR_WRITER) |
19
|
|
|
|
|
|
|
return; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
OP *selfop; |
22
|
1
|
|
|
|
|
|
OP *callop = newLISTOP(OP_LIST, 0, |
23
|
|
|
|
|
|
|
selfop = newOP(OP_PADSV, 0), NULL); |
24
|
1
|
50
|
|
|
|
|
callop = op_append_list(OP_LIST, callop, |
25
|
|
|
|
|
|
|
newMETHOP_named(OP_METHOD_NAMED, 0, newSVpvn_share(SvPV_nolen(hookdata), SvCUR(hookdata), 0))); |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
|
selfop->op_targ = PADIX_SELF; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
|
callop = op_convert_list(OP_ENTERSUB, OPf_STACKED, callop); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
|
ctx->post_bodyops = op_append_list(OP_LINESEQ, ctx->post_bodyops, callop); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
|
static void trigger_seal(pTHX_ FieldMeta *fieldmeta, SV *hookdata, void *_funcdata) |
37
|
|
|
|
|
|
|
{ |
38
|
1
|
50
|
|
|
|
|
if(mop_field_get_attribute(fieldmeta, "writer")) |
39
|
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
warn("Applying :Trigger attribute to field %" SVf " is not useful without a :writer", |
42
|
0
|
|
|
|
|
|
SVfARG(mop_field_get_name(fieldmeta))); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
static const struct FieldHookFuncs trigger_hooks = { |
46
|
|
|
|
|
|
|
.ver = OBJECTPAD_ABIVERSION, |
47
|
|
|
|
|
|
|
.flags = OBJECTPAD_FLAG_ATTR_MUST_VALUE, |
48
|
|
|
|
|
|
|
.permit_hintkey = "Object::Pad::FieldAttr::Trigger/Trigger", |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
.seal = &trigger_seal, |
51
|
|
|
|
|
|
|
.gen_accessor_ops = &trigger_gen_accessor_ops, |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
MODULE = Object::Pad::FieldAttr::Trigger PACKAGE = Object::Pad::FieldAttr::Trigger |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
BOOT: |
57
|
2
|
|
|
|
|
|
register_field_attribute("Trigger", &trigger_hooks, NULL); |