File Coverage

blib/lib/ExtUtils/ParseXS/Eval.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package ExtUtils::ParseXS::Eval;
2 19     19   174 use strict;
  19         58  
  19         854  
3 19     19   111 use warnings;
  19         36  
  19         5904  
4              
5             our $VERSION = '3.61';
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 C<$other_hashref>:
31              
32             $Package $func_name $Full_func_name $pname
33             $var $type $ntype $subtype $arg $ALIAS
34              
35             =cut
36              
37             sub eval_output_typemap_code {
38 245     245 1 654 my ($_pxs, $_code, $_other) = @_;
39              
40             my ($Package, $var, $type, $ntype, $subtype, $arg, $ALIAS, $func_name, $Full_func_name, $pname)
41 245         897 = @{$_other}{qw(Package var type ntype subtype arg alias func_name full_C_name full_perl_name)};
  245         2701  
42              
43 245         28978 my $rv = eval $_code;
44 245 50       1553 warn $@ if $@;
45 245         1294 return $rv;
46             }
47              
48             =head2 $pxs->eval_input_typemap_code($typemapcode, $other_hashref)
49              
50             Sets up various bits of previously global state
51             (formerly ExtUtils::ParseXS package variables)
52             for eval'ing output typemap code that may refer to these
53             variables.
54              
55             Warns the contents of C<$@> if any.
56              
57             Not all these variables are necessarily considered "public" wrt. use in
58             typemaps, so beware. Variables set up from C<$other_hashref>:
59              
60             $Package $func_name $Full_func_name $pname
61             $var $type $ntype $subtype $num $init $printed_name $arg $argoff $ALIAS
62              
63             =cut
64              
65             sub eval_input_typemap_code {
66 382     382 1 1057 my ($_pxs, $_code, $_other) = @_;
67              
68             my ($Package, $var, $type, $num, $init, $printed_name, $arg, $ntype, $argoff, $subtype, $ALIAS, $func_name, $Full_func_name, $pname)
69 382         842 = @{$_other}{qw(Package var type num init printed_name arg ntype argoff subtype alias func_name full_C_name full_perl_name)};
  382         4231  
70              
71 382         53042 my $rv = eval $_code;
72 382 50       2213 warn $@ if $@;
73 382         1832 return $rv;
74             }
75              
76             =head1 TODO
77              
78             Eventually, with better documentation and possible some cleanup,
79             this could be part of C.
80              
81             =cut
82              
83             1;
84              
85             # vim: ts=2 sw=2 et: