File: Final.xs

package info (click to toggle)
libobject-pad-fieldattr-final-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116 kB
  • sloc: perl: 74; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*  You may distribute under the terms of either the GNU General Public License
 *  or the Artistic License (the same terms as Perl itself)
 *
 *  (C) Paul Evans, 2021-2022 -- leonerd@leonerd.org.uk
 */
#define PERL_NO_GET_CONTEXT

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "object_pad.h"

static void final_post_construct(pTHX_ FieldMeta *fieldmeta, SV *_hookdata, void *_funcdata, SV *field)
{
  SvREADONLY_on(field);
}

static void final_seal(pTHX_ FieldMeta *fieldmeta, SV *hookdata, void *_funcdata)
{
  if(mop_field_get_attribute(fieldmeta, "writer"))
    warn("Applying :Final attribute to field %" SVf " which already has :writer", SVfARG(mop_field_get_name(fieldmeta)));
}

static const struct FieldHookFuncs final_hooks = {
  .ver   = OBJECTPAD_ABIVERSION,
  .flags = OBJECTPAD_FLAG_ATTR_NO_VALUE,
  .permit_hintkey = "Object::Pad::FieldAttr::Final/Final",

  .seal           = &final_seal,
  .post_construct = &final_post_construct,
};

MODULE = Object::Pad::FieldAttr::Final    PACKAGE = Object::Pad::FieldAttr::Final

BOOT:
  register_field_attribute("Final", &final_hooks, NULL);