File Coverage

blib/arch/Crypt/SecretBuffer/Install/Files.pm
Criterion Covered Total %
statement 24 33 72.7
branch 4 10 40.0
condition n/a
subroutine 3 4 75.0
pod 0 2 0.0
total 31 49 63.2


line stmt bran cond sub pod time code
1             package Crypt::SecretBuffer::Install::Files;
2              
3             $self = {
4             'c_api' => [
5             {
6             'module' => 'Crypt::SecretBuffer',
7             'name' => 'secret_buffer_charset_from_regexpref',
8             'prototype' => 'secret_buffer_charset * secret_buffer_charset_from_regexpref(SV *ref)'
9             },
10             {
11             'module' => 'Crypt::SecretBuffer',
12             'name' => 'secret_buffer_charset_test_byte',
13             'prototype' => 'bool secret_buffer_charset_test_byte(const secret_buffer_charset *cset, U8 b)'
14             },
15             {
16             'module' => 'Crypt::SecretBuffer',
17             'name' => 'secret_buffer_charset_test_codepoint',
18             'prototype' => 'bool secret_buffer_charset_test_codepoint(const secret_buffer_charset *cset, U32 cp)'
19             },
20             {
21             'module' => 'Crypt::SecretBuffer',
22             'name' => 'secret_buffer_parse_init',
23             'prototype' => 'bool secret_buffer_parse_init(secret_buffer_parse *parse, secret_buffer *buf, size_t pos, size_t lim, int encoding)'
24             },
25             {
26             'module' => 'Crypt::SecretBuffer',
27             'name' => 'secret_buffer_parse_init_from_sv',
28             'prototype' => 'bool secret_buffer_parse_init_from_sv(secret_buffer_parse *parse, SV *sv)'
29             },
30             {
31             'module' => 'Crypt::SecretBuffer',
32             'name' => 'secret_buffer_span_new_obj',
33             'prototype' => 'SV * secret_buffer_span_new_obj(secret_buffer *buf, size_t pos, size_t lim, int encoding)'
34             },
35             {
36             'module' => 'Crypt::SecretBuffer',
37             'name' => 'secret_buffer_span_new_obj_from_parse',
38             'prototype' => 'SV * secret_buffer_span_new_obj_from_parse(secret_buffer_parse *p)'
39             },
40             {
41             'module' => 'Crypt::SecretBuffer',
42             'name' => 'secret_buffer_match',
43             'prototype' => 'bool secret_buffer_match(secret_buffer_parse *p, SV *pattern, int flags)'
44             },
45             {
46             'module' => 'Crypt::SecretBuffer',
47             'name' => 'secret_buffer_match_charset',
48             'prototype' => 'bool secret_buffer_match_charset(secret_buffer_parse *p, secret_buffer_charset *cset, int flags)'
49             },
50             {
51             'module' => 'Crypt::SecretBuffer',
52             'name' => 'secret_buffer_match_bytestr',
53             'prototype' => 'bool secret_buffer_match_bytestr(secret_buffer_parse *p, char *data, size_t datalen, int flags)'
54             },
55             {
56             'module' => 'Crypt::SecretBuffer',
57             'name' => 'secret_buffer_sizeof_transcode',
58             'prototype' => 'SSize_t secret_buffer_sizeof_transcode(secret_buffer_parse *src, int dst_encoding)'
59             },
60             {
61             'module' => 'Crypt::SecretBuffer',
62             'name' => 'secret_buffer_transcode',
63             'prototype' => 'bool secret_buffer_transcode(secret_buffer_parse *src, secret_buffer_parse_rw *dst)'
64             },
65             {
66             'module' => 'Crypt::SecretBuffer',
67             'name' => 'secret_buffer_copy_to',
68             'prototype' => 'bool secret_buffer_copy_to(secret_buffer_parse *src, SV *dst_sv, int encoding, bool append)'
69             },
70             {
71             'module' => 'Crypt::SecretBuffer',
72             'name' => 'secret_buffer_new',
73             'prototype' => 'secret_buffer * secret_buffer_new(size_t capacity, SV **ref_out)'
74             },
75             {
76             'module' => 'Crypt::SecretBuffer',
77             'name' => 'secret_buffer_from_magic',
78             'prototype' => 'secret_buffer * secret_buffer_from_magic(SV *ref, int flags)'
79             },
80             {
81             'module' => 'Crypt::SecretBuffer',
82             'name' => 'secret_buffer_realloc',
83             'prototype' => 'void secret_buffer_realloc(secret_buffer *buf, size_t new_capacity)'
84             },
85             {
86             'module' => 'Crypt::SecretBuffer',
87             'name' => 'secret_buffer_alloc_at_least',
88             'prototype' => 'void secret_buffer_alloc_at_least(secret_buffer *buf, size_t min_capacity)'
89             },
90             {
91             'module' => 'Crypt::SecretBuffer',
92             'name' => 'secret_buffer_set_len',
93             'prototype' => 'void secret_buffer_set_len(secret_buffer *buf, size_t new_len)'
94             },
95             {
96             'module' => 'Crypt::SecretBuffer',
97             'name' => 'secret_buffer_append_uv_asn1_der_length',
98             'prototype' => 'void secret_buffer_append_uv_asn1_der_length(secret_buffer *buf, UV val)'
99             },
100             {
101             'module' => 'Crypt::SecretBuffer',
102             'name' => 'secret_buffer_parse_uv_asn1_der_length',
103             'prototype' => 'bool secret_buffer_parse_uv_asn1_der_length(secret_buffer_parse *parse, UV *out)'
104             },
105             {
106             'module' => 'Crypt::SecretBuffer',
107             'name' => 'secret_buffer_append_uv_base128le',
108             'prototype' => 'void secret_buffer_append_uv_base128le(secret_buffer *buf, UV val)'
109             },
110             {
111             'module' => 'Crypt::SecretBuffer',
112             'name' => 'secret_buffer_parse_uv_base128le',
113             'prototype' => 'bool secret_buffer_parse_uv_base128le(secret_buffer_parse *parse, UV *out)'
114             },
115             {
116             'module' => 'Crypt::SecretBuffer',
117             'name' => 'secret_buffer_append_uv_base128be',
118             'prototype' => 'void secret_buffer_append_uv_base128be(secret_buffer *buf, UV val)'
119             },
120             {
121             'module' => 'Crypt::SecretBuffer',
122             'name' => 'secret_buffer_parse_uv_base128be',
123             'prototype' => 'bool secret_buffer_parse_uv_base128be(secret_buffer_parse *parse, UV *out)'
124             },
125             {
126             'module' => 'Crypt::SecretBuffer',
127             'name' => 'secret_buffer_splice',
128             'prototype' => 'void secret_buffer_splice(secret_buffer *buf, size_t ofs, size_t len, const char *replacement, size_t replacement_len)'
129             },
130             {
131             'module' => 'Crypt::SecretBuffer',
132             'name' => 'secret_buffer_splice_sv',
133             'prototype' => 'void secret_buffer_splice_sv(secret_buffer *buf, size_t ofs, size_t len, SV *replacement)'
134             },
135             {
136             'module' => 'Crypt::SecretBuffer',
137             'name' => 'secret_buffer_SvPVbyte',
138             'prototype' => 'const char * secret_buffer_SvPVbyte(SV *thing, STRLEN *len_out)'
139             },
140             {
141             'module' => 'Crypt::SecretBuffer',
142             'name' => 'secret_buffer_append_random',
143             'prototype' => 'IV secret_buffer_append_random(secret_buffer *buf, size_t n, unsigned flags)'
144             },
145             {
146             'module' => 'Crypt::SecretBuffer',
147             'name' => 'secret_buffer_append_sysread',
148             'prototype' => 'IV secret_buffer_append_sysread(secret_buffer *buf, PerlIO *fh, size_t count)'
149             },
150             {
151             'module' => 'Crypt::SecretBuffer',
152             'name' => 'secret_buffer_append_read',
153             'prototype' => 'IV secret_buffer_append_read(secret_buffer *buf, PerlIO *fh, size_t count)'
154             },
155             {
156             'module' => 'Crypt::SecretBuffer',
157             'name' => 'secret_buffer_append_console_line',
158             'prototype' => 'int secret_buffer_append_console_line(secret_buffer *buf, PerlIO *fh)'
159             },
160             {
161             'module' => 'Crypt::SecretBuffer',
162             'name' => 'secret_buffer_syswrite',
163             'prototype' => 'IV secret_buffer_syswrite(secret_buffer *buf, PerlIO *fh, IV offset, IV count)'
164             },
165             {
166             'module' => 'Crypt::SecretBuffer',
167             'name' => 'secret_buffer_write_async',
168             'prototype' => 'IV secret_buffer_write_async(secret_buffer *buf, PerlIO *fh, IV offset, IV count, SV **ref_out)'
169             },
170             {
171             'module' => 'Crypt::SecretBuffer',
172             'name' => 'secret_buffer_result_check',
173             'prototype' => 'bool secret_buffer_result_check(SV *promise_ref, int timeout_msec, IV *wrote, IV *os_err)'
174             },
175             {
176             'module' => 'Crypt::SecretBuffer',
177             'name' => 'secret_buffer_get_stringify_sv',
178             'prototype' => 'SV * secret_buffer_get_stringify_sv(secret_buffer *buf)'
179             },
180             {
181             'module' => 'Crypt::SecretBuffer',
182             'name' => 'secret_buffer_wipe',
183             'prototype' => 'void secret_buffer_wipe(char *buf, size_t len)'
184             }
185             ],
186             'deps' => [],
187             'inc' => '',
188             'libs' => '-lpthread',
189             'typemaps' => [
190             'typemap'
191             ]
192             };
193              
194             @deps = @{ $self->{deps} };
195             @typemaps = @{ $self->{typemaps} };
196             $libs = $self->{libs};
197             $inc = $self->{inc};
198              
199             $CORE = undef;
200             foreach (@INC) {
201             if ( -f $_ . "/Crypt/SecretBuffer/Install/Files.pm") {
202             $CORE = $_ . "/Crypt/SecretBuffer/Install/";
203             last;
204             }
205             }
206              
207 0     0 0 0 sub deps { @{ $self->{deps} }; }
  0         0  
208             # Given a perl Module::Name, determine what shared library name DynaLoader
209             # wants to load for it, and then resolve the absolute path to that file.
210             # For Windows, return the name of the import library (.lib or .a) instead
211             # of the name of the shared lib (.dll) itself, because that's what belongs
212             # on the linker line.
213             # It would be much preferable to determine the file name being generated
214             # by MakeMaker ahead of time, but I can't find any way to extract that
215             # piece of knowledge from MakeMaker, and besides which MakeMaker hasn't
216             # been invoked yet and we don't have all the parameters to do so.
217             sub _resolve_lib_for_module {
218 1     1   16 my ($mod)= @_;
219 1         7 my ($mod_lib_basename)= ($mod =~ m,([^:]+)\z,);
220 1 50       13 $mod_lib_basename= DynaLoader::mod2fname($mod_lib_basename) if DynaLoader->can('mod2fname');
221 1         29 my @search= map File::Spec->catdir($_, qw( auto Crypt SecretBuffer )), @INC;
222 1 50       190 my $path= DynaLoader::dl_findfile(map("-L$_", @search), $mod_lib_basename)
223             or die "Can't locate shared library for module $mod (looked for $mod_lib_basename.$DynaLoader::dl_dlext)";
224            
225             # On win32, need to reference the '.a' or '.lib' file instead of the '.dll'
226 1 50       7 if ($^O eq 'MSWin32') {
227 0         0 my ($vol,$dirs,$file) = File::Spec->splitpath($path);
228 0         0 (my $base= $file) =~ s/.[^.]+\z//; # remove file extension
229 0         0 for ("$base.lib", # MSVC
230             "$file.a", # MinGW
231             # Try some others for good measure
232             "$file.lib", "$base.a"
233             ) {
234 0         0 my $p= File::Spec->catpath($vol, $dirs, $_);
235 0 0       0 return $p if -f $p;
236             }
237 0         0 warn "Can't determine import library name from $path; didn't find $base.lib or $file.a in $dirs";
238 0         0 return undef;
239             }
240 1         6 return $path;
241             }
242              
243             sub _maybe_quote_path {
244 3 50   3   34 return $_[0] =~ / /? qq{"$_[0]"} : $_[0]
245             }
246            
247             sub Inline {
248 1     1 0 4 my ($class, $lang) = @_;
249            
250             # Calculate the install path for this module
251 1         8 require File::Spec;
252 1         45 my ($vol,$dirs) = File::Spec->splitpath(File::Spec->rel2abs(__FILE__));
253 1         13 my $instpath= File::Spec->catpath($vol,$dirs,'');
254 1         6 $instpath =~ s,[\\/]$,,; # remove trailing slash
255            
256             # Prepare the vars for Inline
257 1         3 my $vars= +{ map { (uc($_) => $self->{$_}) } qw(inc libs typemaps) };
  3         12  
258            
259             # Include this module's own path in INC
260             $vars->{INC}= "-I"._maybe_quote_path($instpath)." $vars->{INC}",
261            
262             # Convert typemaps to absolute paths
263 1         3 $_= File::Spec->rel2abs($_, $instpath) for @{ $vars->{TYPEMAPS} };
  1         5  
264              
265             # This module exports C API functions from its library, so need to add
266             # the XS library itself to the libs.
267 1         5 require DynaLoader;
268 1         3 my %distinct_modules;
269 1         2 $distinct_modules{$_->{module}}++ for @{ $self->{c_api} };
  1         20  
270 1         6 my @libs= grep defined, map _resolve_lib_for_module($_), sort keys %distinct_modules;
271 1         6 $vars->{LIBS}= join(' ', map _maybe_quote_path($_), @libs, grep length, $vars->{LIBS});
272              
273 1         7 return $vars;
274             }
275             1;