File Coverage

blib/lib/ExtUtils/ParseXS/Eval.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 4 50.0
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             package ExtUtils::ParseXS::Eval;
2 18     18   117 use strict;
  18         35  
  18         528  
3 18     18   83 use warnings;
  18         36  
  18         4527  
4              
5             our $VERSION = '3.44';
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 71     71 1 147 my ($_pxs, $_code, $_other) = @_;
42              
43             my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
44 71         113 = @{$_pxs}{qw(Package ALIAS func_name Full_func_name pname)};
  71         230  
45              
46             my ($var, $type, $ntype, $subtype, $arg)
47 71         130 = @{$_other}{qw(var type ntype subtype arg)};
  71         175  
48              
49 71         4532 my $rv = eval $_code;
50 71 50       427 warn $@ if $@;
51 71         257 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 57     57 1 106 my ($_pxs, $_code, $_other) = @_;
76              
77             my ($Package, $ALIAS, $func_name, $Full_func_name, $pname)
78 57         95 = @{$_pxs}{qw(Package ALIAS func_name Full_func_name pname)};
  57         178  
79              
80             my ($var, $type, $num, $init, $printed_name, $arg, $ntype, $argoff, $subtype)
81 57         103 = @{$_other}{qw(var type num init printed_name arg ntype argoff subtype)};
  57         190  
82              
83 57         4376 my $rv = eval $_code;
84 57 50       517 warn $@ if $@;
85 57         371 return $rv;
86             }
87              
88             =head1 TODO
89              
90             Eventually, with better documentation and possible some cleanup,
91             this could be part of C.
92              
93             =cut
94              
95             1;
96              
97             # vim: ts=2 sw=2 et: