Skip to content

Instantly share code, notes, and snippets.

@exodist
Created June 24, 2020 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exodist/cc355b975cab0d3a1dcae67f6e25f18c to your computer and use it in GitHub Desktop.
Save exodist/cc355b975cab0d3a1dcae67f6e25f18c to your computer and use it in GitHub Desktop.
package Test2::Plugin::Cover;
use strict;
use warnings;
our $VERSION = '0.000001';
use XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);
1;
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include <stdio.h>
Perl_ppaddr_t orig_subhandler;
SV *one;
static OP* my_subhandler(pTHX) {
OP* out = orig_subhandler(aTHX);
if (out->op_type == OP_NEXTSTATE || out->op_type == OP_DBSTATE) {
char *file = CopFILE(cCOPx(out));
long len = strlen(file);
HV *files = get_hv("Test2::Plugin::Cover::FILES", 0);
if (!hv_exists(files, file, len)) {
SvREFCNT_inc(one);
hv_store(files, file, len, one, 0);
}
}
return out;
}
MODULE = Test2::Plugin::Cover PACKAGE = Test2::Plugin::Cover
PROTOTYPES: ENABLE
BOOT:
{
MY_CXT_INIT;
one = newSVnv(1);
SvREFCNT_inc(one);
orig_subhandler = PL_ppaddr[OP_ENTERSUB];
PL_ppaddr[OP_ENTERSUB] = my_subhandler;
}
use Test2::Plugin::Cover;
use Cpanel::JSON::XS;
__END__
No output, exit code 139
use Test2::Plugin::Cover;
use Data::UUID;
Data::UUID->new;
__END__
No output, exit code 139
use Test2::Plugin::Cover;
sub foo { 'foo' }
print foo(), "\n";
__END__
Output: foo
Exit code: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment