Debian Codegraph @

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Eval.pm

raw
1 package ExtUtils::ParseXS::Eval;
2 use strict;
3 use warnings;
4
5 our $VERSION = '3.51';
6
7 =head1 NAME
8
9 ExtUtils::ParseXS::Eval - Clean package to evaluate code in
10
11 =head1 SYNOPSIS
12
13 use ExtUtils::ParseXS::Eval;
14 my $rv = ExtUtils::ParseXS::Eval::eval_typemap_code(
15 $parsexs_obj, "some Perl code"
16 );
17
18 =head1 SUBROUTINES
19
20 =head2 $pxs->eval_output_typemap_code($typemapcode, $other_hashref)
21
22 Sets up various bits of previously global state
23 (formerly ExtUtils::ParseXS package variables)
24 for eval'ing output typemap code that may refer to these
25 variables.
26
27 Warns the contents of C<$@> if any.
28
29 Not all these variables are necessarily considered "public" wrt. use in
30 typemaps, so beware. Variables set up from the ExtUtils::ParseXS object:
31
32 $Package $ALIAS $func_name $Full_func_name $pname
33
34 Variables set up from C<$other_hashref>:
35
36 $var $type $ntype $subtype $arg
37
38 =cut
39
40 sub eval_output_typemap_code {
41 my ($_pxs, $_code, $_other) = @_;
42
43 my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
44 = @{$_pxs}{qw(Package ALIAS func_name Full_func_name pname)};
45
46 my ($var, $type, $ntype, $subtype, $arg)
47 = @{$_other}{qw(var type ntype subtype arg)};
48
49 my $rv = eval $_code;
50 warn $@ if $@;
51 return $rv;
52 }
53
54 =head2 $pxs->eval_input_typemap_code($typemapcode, $other_hashref)
55
56 Sets up various bits of previously global state
57 (formerly ExtUtils::ParseXS package variables)
58 for eval'ing output typemap code that may refer to these
59 variables.
60
61 Warns the contents of C<$@> if any.
62
63 Not all these variables are necessarily considered "public" wrt. use in
64 typemaps, so beware. Variables set up from the ExtUtils::ParseXS object:
65
66 $Package $ALIAS $func_name $Full_func_name $pname
67
68 Variables set up from C<$other_hashref>:
69
70 $var $type $ntype $subtype $num $init $printed_name $arg $argoff
71
72 =cut
73
74 sub eval_input_typemap_code {
75 my ($_pxs, $_code, $_other) = @_;
76
77 my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
78 = @{$_pxs}{qw(Package ALIAS func_name Full_func_name pname)};
79
80 my ($var, $type, $num, $init, $printed_name, $arg, $ntype, $argoff, $subtype)
81 = @{$_other}{qw(var type num init printed_name arg ntype argoff subtype)};
82
83 my $rv = eval $_code;
84 warn $@ if $@;
85 return $rv;
86 }
87
88 =head1 TODO
89
90 Eventually, with better documentation and possible some cleanup,
91 this could be part of C<ExtUtils::Typemaps>.
92
93 =cut
94
95 1;
96
97 # vim: ts=2 sw=2 et: