File Coverage

blib/arch/Crypt/SecretBuffer/Install/Files.pm
Criterion Covered Total %
statement 20 27 74.0
branch 4 12 33.3
condition n/a
subroutine 2 3 66.6
pod 0 2 0.0
total 26 44 59.0


line stmt bran cond sub pod time code
1             package Crypt::SecretBuffer::Install::Files;
2              
3             $self = {
4             'c_api' => [
5             {
6             'name' => 'secret_buffer_charset_from_regexpref',
7             'prototype' => 'secret_buffer_charset * secret_buffer_charset_from_regexpref(SV *ref)'
8             },
9             {
10             'name' => 'secret_buffer_charset_test_byte',
11             'prototype' => 'bool secret_buffer_charset_test_byte(const secret_buffer_charset *cset, U8 b)'
12             },
13             {
14             'name' => 'secret_buffer_charset_test_codepoint',
15             'prototype' => 'bool secret_buffer_charset_test_codepoint(const secret_buffer_charset *cset, U32 cp)'
16             },
17             {
18             'name' => 'secret_buffer_parse_init',
19             'prototype' => 'bool secret_buffer_parse_init(secret_buffer_parse *parse, secret_buffer *buf, size_t pos, size_t lim, int encoding)'
20             },
21             {
22             'name' => 'secret_buffer_parse_init_from_sv',
23             'prototype' => 'bool secret_buffer_parse_init_from_sv(secret_buffer_parse *parse, SV *sv)'
24             },
25             {
26             'name' => 'secret_buffer_span_new_obj',
27             'prototype' => 'SV * secret_buffer_span_new_obj(secret_buffer *buf, size_t pos, size_t lim, int encoding)'
28             },
29             {
30             'name' => 'secret_buffer_span_new_obj_from_parse',
31             'prototype' => 'SV * secret_buffer_span_new_obj_from_parse(secret_buffer_parse *p)'
32             },
33             {
34             'name' => 'secret_buffer_match',
35             'prototype' => 'bool secret_buffer_match(secret_buffer_parse *p, SV *pattern, int flags)'
36             },
37             {
38             'name' => 'secret_buffer_match_charset',
39             'prototype' => 'bool secret_buffer_match_charset(secret_buffer_parse *p, secret_buffer_charset *cset, int flags)'
40             },
41             {
42             'name' => 'secret_buffer_match_bytestr',
43             'prototype' => 'bool secret_buffer_match_bytestr(secret_buffer_parse *p, char *data, size_t datalen, int flags)'
44             },
45             {
46             'name' => 'secret_buffer_sizeof_transcode',
47             'prototype' => 'SSize_t secret_buffer_sizeof_transcode(secret_buffer_parse *src, int dst_encoding)'
48             },
49             {
50             'name' => 'secret_buffer_transcode',
51             'prototype' => 'bool secret_buffer_transcode(secret_buffer_parse *src, secret_buffer_parse *dst)'
52             },
53             {
54             'name' => 'secret_buffer_copy_to',
55             'prototype' => 'bool secret_buffer_copy_to(secret_buffer_parse *src, SV *dst_sv, int encoding, bool append)'
56             },
57             {
58             'name' => 'secret_buffer_new',
59             'prototype' => 'secret_buffer * secret_buffer_new(size_t capacity, SV **ref_out)'
60             },
61             {
62             'name' => 'secret_buffer_from_magic',
63             'prototype' => 'secret_buffer * secret_buffer_from_magic(SV *ref, int flags)'
64             },
65             {
66             'name' => 'secret_buffer_realloc',
67             'prototype' => 'void secret_buffer_realloc(secret_buffer *buf, size_t new_capacity)'
68             },
69             {
70             'name' => 'secret_buffer_alloc_at_least',
71             'prototype' => 'void secret_buffer_alloc_at_least(secret_buffer *buf, size_t min_capacity)'
72             },
73             {
74             'name' => 'secret_buffer_set_len',
75             'prototype' => 'void secret_buffer_set_len(secret_buffer *buf, size_t new_len)'
76             },
77             {
78             'name' => 'secret_buffer_append_uv_asn1_der_length',
79             'prototype' => 'void secret_buffer_append_uv_asn1_der_length(secret_buffer *buf, UV val)'
80             },
81             {
82             'name' => 'secret_buffer_parse_uv_asn1_der_length',
83             'prototype' => 'bool secret_buffer_parse_uv_asn1_der_length(secret_buffer_parse *parse, UV *out)'
84             },
85             {
86             'name' => 'secret_buffer_append_uv_base128le',
87             'prototype' => 'void secret_buffer_append_uv_base128le(secret_buffer *buf, UV val)'
88             },
89             {
90             'name' => 'secret_buffer_parse_uv_base128le',
91             'prototype' => 'bool secret_buffer_parse_uv_base128le(secret_buffer_parse *parse, UV *out)'
92             },
93             {
94             'name' => 'secret_buffer_append_uv_base128be',
95             'prototype' => 'void secret_buffer_append_uv_base128be(secret_buffer *buf, UV val)'
96             },
97             {
98             'name' => 'secret_buffer_parse_uv_base128be',
99             'prototype' => 'bool secret_buffer_parse_uv_base128be(secret_buffer_parse *parse, UV *out)'
100             },
101             {
102             'name' => 'secret_buffer_splice',
103             'prototype' => 'void secret_buffer_splice(secret_buffer *buf, size_t ofs, size_t len, const char *replacement, size_t replacement_len)'
104             },
105             {
106             'name' => 'secret_buffer_splice_sv',
107             'prototype' => 'void secret_buffer_splice_sv(secret_buffer *buf, size_t ofs, size_t len, SV *replacement)'
108             },
109             {
110             'name' => 'secret_buffer_SvPVbyte',
111             'prototype' => 'const char * secret_buffer_SvPVbyte(SV *thing, STRLEN *len_out)'
112             },
113             {
114             'name' => 'secret_buffer_append_random',
115             'prototype' => 'IV secret_buffer_append_random(secret_buffer *buf, size_t n, unsigned flags)'
116             },
117             {
118             'name' => 'secret_buffer_append_sysread',
119             'prototype' => 'IV secret_buffer_append_sysread(secret_buffer *buf, PerlIO *fh, size_t count)'
120             },
121             {
122             'name' => 'secret_buffer_append_read',
123             'prototype' => 'IV secret_buffer_append_read(secret_buffer *buf, PerlIO *fh, size_t count)'
124             },
125             {
126             'name' => 'secret_buffer_append_console_line',
127             'prototype' => 'int secret_buffer_append_console_line(secret_buffer *buf, PerlIO *fh)'
128             },
129             {
130             'name' => 'secret_buffer_syswrite',
131             'prototype' => 'IV secret_buffer_syswrite(secret_buffer *buf, PerlIO *fh, IV offset, IV count)'
132             },
133             {
134             'name' => 'secret_buffer_write_async',
135             'prototype' => 'IV secret_buffer_write_async(secret_buffer *buf, PerlIO *fh, IV offset, IV count, SV **ref_out)'
136             },
137             {
138             'name' => 'secret_buffer_result_check',
139             'prototype' => 'bool secret_buffer_result_check(SV *promise_ref, int timeout_msec, IV *wrote, IV *os_err)'
140             },
141             {
142             'name' => 'secret_buffer_get_stringify_sv',
143             'prototype' => 'SV * secret_buffer_get_stringify_sv(secret_buffer *buf)'
144             },
145             {
146             'name' => 'secret_buffer_wipe',
147             'prototype' => 'void secret_buffer_wipe(char *buf, size_t len)'
148             }
149             ],
150             'deps' => [],
151             'inc' => '',
152             'libs' => '-lpthread -lpthread -lpthread -lpthread',
153             'typemaps' => [
154             'typemap'
155             ]
156             };
157              
158             @deps = @{ $self->{deps} };
159             @typemaps = @{ $self->{typemaps} };
160             $libs = $self->{libs};
161             $inc = $self->{inc};
162              
163             $CORE = undef;
164             foreach (@INC) {
165             if ( -f $_ . "/Crypt/SecretBuffer/Install/Files.pm") {
166             $CORE = $_ . "/Crypt/SecretBuffer/Install/";
167             last;
168             }
169             }
170              
171 0     0 0 0 sub deps { @{ $self->{deps} }; }
  0         0  
172            
173             sub _maybe_quote_path {
174 2 50   2   23 return $_[0] =~ / /? qq{"$_[0]"} : $_[0]
175             }
176              
177             sub Inline {
178 1     1 0 3 my ($class, $lang) = @_;
179            
180             # Calculate the install path for this module
181 1         4 require File::Spec;
182 1         35 my ($vol,$dirs) = File::Spec->splitpath(File::Spec->rel2abs(__FILE__));
183 1         12 my $instpath= File::Spec->catpath($vol,$dirs,'');
184 1         4 $instpath =~ s,[\\/]$,,; # remove trailing slash
185            
186             # Prepare the vars for Inline
187 1         3 my $vars= +{ map { (uc($_) => $self->{$_}) } qw(inc libs typemaps) };
  3         12  
188            
189             # Include this module's own path in INC
190             $vars->{INC}= "-I"._maybe_quote_path($instpath)." $vars->{INC}",
191            
192             # Convert typemaps to absolute paths
193 1         2 $_= File::Spec->rel2abs($_, $instpath) for @{ $vars->{TYPEMAPS} };
  1         3  
194            
195             # If this module exports C API functions from its library, need to add
196             # the XS library itself to the libs.
197 1 50       3 if ($self->{c_api}) {
198 1         3 require DynaLoader;
199 1         24 my @search= map File::Spec->catdir($_, qw( auto Crypt SecretBuffer )), @INC;
200 1 50       184 my $path= DynaLoader::dl_findfile(map("-L$_", @search), "SecretBuffer")
201             or die "Can't locate shared library for module $class (looked for SecretBuffer.$DynaLoader::dl_dlext)";
202 1         14 my ($vol,$dirs,$file) = File::Spec->splitpath($path);
203 1         4 $dirs =~ s,[\\/]$,,; # remove trailing slash
204            
205             # On win32, need to reference the '.a' or '.lib' file instead of the '.dll'
206 1 50       3 if ($^O eq 'MSWin32') {
207 0         0 my $libfile= substr($file, 0, -1-length $DynaLoader::dl_dlext);
208 0 0       0 if (-f File::Spec->catpath($vol, $dirs, "$libfile.lib")) { # MSVC
    0          
209 0         0 $file= "$libfile.lib";
210             } elsif (-f File::Spec->catpath($vol, $dirs, "$libfile.a")) { # MinGW
211 0         0 $file= "$libfile.a";
212             } else {
213 0         0 warn "Can't determine import library name from $path; didn't find $libfile.lib or $libfile.a in $dirs";
214             }
215             }
216 1         5 my $libpath = File::Spec->catpath($vol,$dirs,'');
217 1         3 $vars->{LIBS}= "-L"._maybe_quote_path($libpath)." -l$file $vars->{LIBS}";
218             }
219 1         4 return $vars;
220             }
221              
222             1;