File Coverage

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