1package ExtUtils::ParseXS::Eval;
2use strict;
3use warnings;
4
5our $VERSION = '3.51';
6
7=head1 NAME
8
9ExtUtils::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
22Sets up various bits of previously global state
23(formerly ExtUtils::ParseXS package variables)
24for eval'ing output typemap code that may refer to these
25variables.
26
27Warns the contents of C<$@> if any.
28
29Not all these variables are necessarily considered "public" wrt. use in
30typemaps, so beware. Variables set up from the ExtUtils::ParseXS object:
31
32  $Package $ALIAS $func_name $Full_func_name $pname
33
34Variables set up from C<$other_hashref>:
35
36  $var $type $ntype $subtype $arg
37
38=cut
39
40sub 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
56Sets up various bits of previously global state
57(formerly ExtUtils::ParseXS package variables)
58for eval'ing output typemap code that may refer to these
59variables.
60
61Warns the contents of C<$@> if any.
62
63Not all these variables are necessarily considered "public" wrt. use in
64typemaps, so beware. Variables set up from the ExtUtils::ParseXS object:
65
66  $Package $ALIAS $func_name $Full_func_name $pname
67
68Variables set up from C<$other_hashref>:
69
70  $var $type $ntype $subtype $num $init $printed_name $arg $argoff
71
72=cut
73
74sub 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
90Eventually, with better documentation and possible some cleanup,
91this could be part of C<ExtUtils::Typemaps>.
92
93=cut
94
951;
96
97# vim: ts=2 sw=2 et:
98