.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "B::Hooks::OP::Annotation 3pm" .TH B::Hooks::OP::Annotation 3pm "2014-03-09" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" B::Hooks::OP::Annotation \- annotate and delegate hooked OPs .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& #include "hook_op_check.h" \& #include "hook_op_annotation.h" \& \& STATIC OPAnnotationGroup MYMODULE_ANNOTATIONS; \& \& STATIC void mymodule_mydata_free(pTHX_ void *mydata) { \& // ... \& } \& \& STATIC OP * mymodule_check_entersub(pTHX_ OP *op, void *unused) { \& MyData * mydata; \& \& mydata = mymodule_get_mydata(); /* metadata to be associated with this OP */ \& op_annotate(MYMODULE_ANNOTATIONS, op, mydata, mymodule_mydata_free); \& op\->op_ppaddr = mymodule_entersub; \& \& return op; \& } \& \& STATIC OP * mymodule_entersub(pTHX) { \& OPAnnotation * annotation; \& MyData * mydata; \& OP *op = PL_op; \& \& annotation = op_annotation_get(MYMODULE_ANNOTATIONS, op); \& mydata = (MyData *)annotation\->data; \& \& // ... \& \& if (ok) { \& return NORMAL; \& } else if (mymodule_stop_hooking(op)) { /* restore the previous op_ppaddr */ \& op\->op_ppaddr = annotation\->op_ppaddr; \& op_annotation_delete(MYMODULE_ANNOTATIONS, op); \& return op\->op_ppaddr(aTHX); \& } else { \& return annotation\->op_ppaddr(aTHX); /* delegate to the previous op_ppaddr */ \& } \& } \& \& MODULE = mymodule PACKAGE = mymodule \& \& BOOT: \& MYMODULE_ANNOTATIONS = op_annotation_group_new(); \& \& void \& END() \& CODE: \& op_annotation_group_free(aTHX_ MYMODULE_ANNOTATIONS); \& \& void \& setup() \& CODE: \& mymodule_hook_op_entersub_id = hook_op_check( \& OP_ENTERSUB, \& mymodule_check_entersub, \& NULL \& ); \& \& void \& teardown() \& CODE: \& hook_op_check_remove(OP_ENTERSUB, mymodule_hook_op_entersub_id); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a way for \s-1XS\s0 code that hijacks \s-1OP \s0\f(CW\*(C`op_ppaddr\*(C'\fR functions to delegate to (or restore) the previous functions, whether assigned by perl or by another module. Typically this should be used in conjunction with B::Hooks::OP::Check. .PP \&\f(CW\*(C`B::Hooks::OP::Annotation\*(C'\fR makes its types and functions available to \s-1XS\s0 code by means of ExtUtils::Depends. Modules that wish to use these exports in their \s-1XS\s0 code should \&\f(CW\*(C`use B::OP::Hooks::Annotation\*(C'\fR in the Perl module that loads the \s-1XS,\s0 and include something like the following in their Makefile.PL: .PP .Vb 2 \& use ExtUtils::MakeMaker; \& use ExtUtils::Depends; \& \& our %XS_PREREQUISITES = ( \& \*(AqB::Hooks::OP::Annotation\*(Aq => \*(Aq0.44\*(Aq, \& \*(AqB::Hooks::OP::Check\*(Aq => \*(Aq0.15\*(Aq, \& ); \& \& our %XS_DEPENDENCIES = ExtUtils::Depends\->new( \& \*(AqYour::XS::Module\*(Aq, \& keys(%XS_PREREQUISITES) \& )\->get_makefile_vars(); \& \& WriteMakefile( \& NAME => \*(AqYour::XS::Module\*(Aq, \& VERSION_FROM => \*(Aqlib/Your/XS/Module.pm\*(Aq, \& PREREQ_PM => { \& \*(AqB::Hooks::EndOfScope\*(Aq => \*(Aq0.07\*(Aq, \& %XS_PREREQUISITES \& }, \& ($ExtUtils::MakeMaker::VERSION >= 6.46 ? \& (META_MERGE => { \& configure_requires => { \& \*(AqExtUtils::Depends\*(Aq => \*(Aq0.301\*(Aq, \& %XS_PREREQUISITES \& }}) \& : () \& ), \& %XS_DEPENDENCIES, \& # ... \& ); .Ve .SS "\s-1TYPES\s0" .IX Subsection "TYPES" \fIOPAnnotation\fR .IX Subsection "OPAnnotation" .PP This struct contains the metadata associated with a particular \s-1OP\s0 i.e. the data itself, a destructor for that data, and the \f(CW\*(C`op_ppaddr\*(C'\fR function that was defined when the annotation was created by \*(L"op_annotate\*(R" or \*(L"op_annotation_new\*(R". .IP "\(bu" 4 \&\f(CW\*(C`op_ppaddr\*(C'\fR, the \s-1OP\s0's previous \f(CW\*(C`op_ppaddr\*(C'\fR function (of type \*(L"OPAnnotationPPAddr\*(R") .IP "\(bu" 4 \&\f(CW\*(C`data\*(C'\fR, a \f(CW\*(C`void *\*(C'\fR to metadata that should be associated with the \s-1OP\s0 .IP "\(bu" 4 \&\f(CW\*(C`dtor\*(C'\fR, a function (of type \*(L"OPAnnotationDtor\*(R") used to free the metadata .PP The fields are all read/write and can be modified after the annotation has been created. .PP \fIOPAnnotationGroup\fR .IX Subsection "OPAnnotationGroup" .PP Annotations are stored in groups. Multiple groups can be created, and each one manages all of the annotations associated with it. .PP Annotations can be removed from the group and freed by calling \*(L"op_annotation_delete\*(R", and the group and all its members can be destroyed by calling \*(L"op_annotation_group_free\*(R". .PP \fIOPAnnotationPPAddr\fR .IX Subsection "OPAnnotationPPAddr" .PP This typedef corresponds to the type of perl's \f(CW\*(C`op_ppaddr\*(C'\fR functions i.e. .PP .Vb 1 \& typedef OP *(*OPAnnotationPPAddr)(pTHX); .Ve .PP \fIOPAnnotationDtor\fR .IX Subsection "OPAnnotationDtor" .PP This is the typedef for the destructor used to free the metadata associated with the \s-1OP.\s0 .PP .Vb 1 \& typedef void (*OPAnnotationDtor)(pTHX_ void *data); .Ve .SS "\s-1FUNCTIONS\s0" .IX Subsection "FUNCTIONS" \fIop_annotation_new\fR .IX Subsection "op_annotation_new" .PP This function creates and returns a new \s-1OP\s0 annotation. .PP It takes an \*(L"OPAnnotationGroup\*(R", an \s-1OP,\s0 a pointer to the metadata to be associated with the \s-1OP,\s0 and a destructor for that data. The data can be \s-1NULL\s0 and the destructor can be \s-1NULL\s0 if no cleanup is required. .PP If an annotation has already been assigned for the \s-1OP,\s0 then it is replaced by the new annotation, and the old annotation is freed, triggering the destruction of its data (if supplied) by its destructor (if supplied). .PP .Vb 6 \& OPAnnotation * op_annotation_new( \& OPAnnotationGroup group, \& OP *op, \& void *data, \& OPAnnotationDtor dtor \& ); .Ve .PP \fIop_annotate\fR .IX Subsection "op_annotate" .PP This function is a void version of \*(L"op_annotation_new\*(R" for cases where the new annotation is not needed. .PP .Vb 6 \& void op_annotate( \& OPAnnotationGroup group, \& OP *op, \& void *data, \& OPAnnotationDtor dtor \& ); .Ve .PP \fIop_annotation_get\fR .IX Subsection "op_annotation_get" .PP This retrieves the annotation associated with the supplied \s-1OP.\s0 If an annotation has not been assigned for the \s-1OP,\s0 it raises a fatal exception. .PP .Vb 1 \& OPAnnotation * op_annotation_get(OPAnnotationGroup group, OP *op); .Ve .PP \fIop_annotation_delete\fR .IX Subsection "op_annotation_delete" .PP This removes the specified annotation from the group and frees its memory. If a destructor was supplied, it is called on the value in the \f(CW\*(C`data\*(C'\fR field (if supplied). .PP .Vb 1 \& void op_annotation_delete(pTHX_ OPAnnotationGroup group, OP *op); .Ve .PP \fIop_annotation_group_new\fR .IX Subsection "op_annotation_group_new" .PP This function creates a new annotation group. .PP .Vb 1 \& OPAnnotationGroup op_annotation_group_new(void); .Ve .PP \fIop_annotation_group_free\fR .IX Subsection "op_annotation_group_free" .PP This function destroys the annotations in an annotation group and frees the memory allocated for the group. .PP .Vb 1 \& void op_annotation_group_free(pTHX_ OPAnnotationGroup group); .Ve .SH "EXPORT" .IX Header "EXPORT" None by default. .SH "VERSION" .IX Header "VERSION" 0.44 .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 B::Hooks::OP::Check .IP "\(bu" 4 B::Hooks::OP::PPAddr .SH "AUTHOR" .IX Header "AUTHOR" chocolateboy .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (c) 2009\-2011 chocolateboy .PP This module is free software. .PP You may distribute this code under the same terms as Perl itself.