nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1From: =?UTF-8?q?Christian=20K=C3=B6gler?= <ck3d@gmx.de>
2Date: Mon, 10 Apr 2023 22:12:24 +0200
3Subject: [PATCH] miniperl compatible modules
4
5CPAN::Meta
6ExtUtils::MakeMaker
7JSON::PP
8Data::Dumper
9
10Updated for perl v5.40.0 by marcus@means.no
11
12---
13
14diff --git a/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm b/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm
15index b0e83b0d2d..dab4907704 100644
16--- a/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm
17+++ b/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm
18@@ -52,21 +52,38 @@
19 # from version::vpp
20 sub _find_magic_vstring {
21 my $value = shift;
22- my $tvalue = '';
23- require B;
24- my $sv = B::svref_2object(\$value);
25- my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
26- while ( $magic ) {
27- if ( $magic->TYPE eq 'V' ) {
28- $tvalue = $magic->PTR;
29- $tvalue =~ s/^v?(.+)$/v$1/;
30- last;
31- }
32- else {
33- $magic = $magic->MOREMAGIC;
34+
35+ # B is not available in miniperl (it depends on XS), so try to load it safely
36+ my $has_B = eval { require B; 1 };
37+
38+ if ($has_B) {
39+ my $sv = B::svref_2object(\$value);
40+ my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
41+ while ($magic) {
42+ if ($magic->TYPE eq 'V') {
43+ my $tvalue = $magic->PTR;
44+ $tvalue =~ s/^v?(.+)$/v$1/;
45+ return $tvalue;
46+ }
47+ $magic = $magic->MOREMAGIC;
48 }
49 }
50- return $tvalue;
51+
52+ # --- Fallback for miniperl ---
53+ # Perl represents vstrings internally as sequences of bytes like "\x01\x02\x03"
54+ # and only shows them as "v1.2.3" when printed.
55+ # Try to detect that pattern heuristically.
56+ use builtin qw/reftype/;
57+ if (!ref($value) && reftype(\$value) eq 'VSTRING') {
58+ return sprintf("v%vd", $value);
59+ }
60+
61+ # If it's already a "v1.2.3" string, just return it as is
62+ if ($value =~ /^v\d+(?:\.\d+)*$/) {
63+ return $value;
64+ }
65+
66+ return '';
67 }
68
69 # Perl 5.10.0 didn't have "is_qv" in version.pm
70diff --git a/cpan/CPAN-Meta-YAML/lib/CPAN/Meta/YAML.pm b/cpan/CPAN-Meta-YAML/lib/CPAN/Meta/YAML.pm
71index 746abd63bc..c55d7cd2d0 100644
72--- a/cpan/CPAN-Meta-YAML/lib/CPAN/Meta/YAML.pm
73+++ b/cpan/CPAN-Meta-YAML/lib/CPAN/Meta/YAML.pm
74@@ -1,6 +1,7 @@
75 use 5.008001; # sane UTF-8 support
76 use strict;
77 use warnings;
78+no warnings 'experimental::builtin';
79 package CPAN::Meta::YAML; # git description: v1.75-3-g85169f1
80 # XXX-INGY is 5.8.1 too old/broken for utf8?
81 # XXX-XDG Lancaster consensus was that it was sufficient until
82@@ -650,27 +651,29 @@ sub _dump_string {
83 join '', map { "$_\n" } @lines;
84 }
85
86-sub _has_internal_string_value {
87+# taken from cpan/JSON-PP/lib/JSON/PP.pm
88+sub _looks_like_number {
89 my $value = shift;
90- my $b_obj = B::svref_2object(\$value); # for round trip problem
91- return $b_obj->FLAGS & B::SVf_POK();
92+ no warnings 'numeric';
93+ # if the utf8 flag is on, it almost certainly started as a string
94+ return if utf8::is_utf8($value);
95+ # detect numbers
96+ # string & "" -> ""
97+ # number & "" -> 0 (with warning)
98+ # nan and inf can detect as numbers, so check with * 0
99+ return unless length((my $dummy = "") & $value);
100+ return unless 0 + $value eq $value;
101+ return 1 if $value * 0 == 0;
102+ return -1; # inf/nan
103 }
104
105 sub _dump_scalar {
106 my $string = $_[1];
107 my $is_key = $_[2];
108- # Check this before checking length or it winds up looking like a string!
109- my $has_string_flag = _has_internal_string_value($string);
110 return '~' unless defined $string;
111 return "''" unless length $string;
112- if (Scalar::Util::looks_like_number($string)) {
113- # keys and values that have been used as strings get quoted
114- if ( $is_key || $has_string_flag ) {
115- return qq['$string'];
116- }
117- else {
118- return $string;
119- }
120+ if (_looks_like_number($string)) {
121+ return qq['$string'];
122 }
123 if ( $string =~ /[\x00-\x09\x0b-\x0d\x0e-\x1f\x7f-\x9f\'\n]/ ) {
124 $string =~ s/\\/\\\\/g;
125@@ -800,9 +803,6 @@ sub errstr {
126 # Helper functions. Possibly not needed.
127
128
129-# Use to detect nv or iv
130-use B;
131-
132 # XXX-INGY Is flock CPAN::Meta::YAML's responsibility?
133 # Some platforms can't flock :-(
134 # XXX-XDG I think it is. When reading and writing files, we ought
135@@ -822,35 +822,8 @@ sub _can_flock {
136 }
137 }
138
139-
140-# XXX-INGY Is this core in 5.8.1? Can we remove this?
141-# XXX-XDG Scalar::Util 1.18 didn't land until 5.8.8, so we need this
142-#####################################################################
143-# Use Scalar::Util if possible, otherwise emulate it
144-
145-use Scalar::Util ();
146 BEGIN {
147- local $@;
148- if ( eval { Scalar::Util->VERSION(1.18); } ) {
149- *refaddr = *Scalar::Util::refaddr;
150- }
151- else {
152- eval <<'END_PERL';
153-# Scalar::Util failed to load or too old
154-sub refaddr {
155- my $pkg = ref($_[0]) or return undef;
156- if ( !! UNIVERSAL::can($_[0], 'can') ) {
157- bless $_[0], 'Scalar::Util::Fake';
158- } else {
159- $pkg = undef;
160- }
161- "$_[0]" =~ /0x(\w+)/;
162- my $i = do { no warnings 'portable'; hex $1 };
163- bless $_[0], $pkg if defined $pkg;
164- $i;
165-}
166-END_PERL
167- }
168+ *refaddr = *builtin::refaddr;
169 }
170
171 delete $CPAN::Meta::YAML::{refaddr};
172diff --git a/cpan/CPAN-Meta/lib/CPAN/Meta/Merge.pm b/cpan/CPAN-Meta/lib/CPAN/Meta/Merge.pm
173index 3604eae402..991f69d275 100644
174--- a/cpan/CPAN-Meta/lib/CPAN/Meta/Merge.pm
175+++ b/cpan/CPAN-Meta/lib/CPAN/Meta/Merge.pm
176@@ -1,12 +1,13 @@
177 use strict;
178 use warnings;
179+no warnings 'experimental::builtin';
180
181 package CPAN::Meta::Merge;
182
183 our $VERSION = '2.150010';
184
185 use Carp qw/croak/;
186-use Scalar::Util qw/blessed/;
187+use builtin qw/blessed/;
188 use CPAN::Meta::Converter 2.141170;
189
190 sub _is_identical {
191diff --git a/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm b/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm
192index d4e93fd8a5..809da68d02 100644
193--- a/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm
194+++ b/cpan/CPAN-Meta/lib/CPAN/Meta/Prereqs.pm
195@@ -1,6 +1,7 @@
196 use 5.006;
197 use strict;
198 use warnings;
199+no warnings 'experimental::builtin';
200 package CPAN::Meta::Prereqs;
201
202 our $VERSION = '2.150010';
203@@ -14,7 +14,7 @@ our $VERSION = '2.150010';
204 #pod =cut
205
206 use Carp qw(confess);
207-use Scalar::Util qw(blessed);
208+use builtin qw(blessed);
209 use CPAN::Meta::Requirements 2.121;
210
211 #pod =method new
212diff --git a/cpan/JSON-PP/lib/JSON/PP.pm b/cpan/JSON-PP/lib/JSON/PP.pm
213index fc8fcbc8f0..cda7b90c65 100644
214--- a/cpan/JSON-PP/lib/JSON/PP.pm
215+++ b/cpan/JSON-PP/lib/JSON/PP.pm
216@@ -4,6 +4,7 @@ package JSON::PP;
217
218 use 5.008;
219 use strict;
220+no warnings 'experimental::builtin';
221
222 use Exporter ();
223 BEGIN { our @ISA = ('Exporter') }
224diff --git a/dist/Data-Dumper/Dumper.pm b/dist/Data-Dumper/Dumper.pm
225index bb6d3caedb..0c2fde4743 100644
226--- a/dist/Data-Dumper/Dumper.pm
227+++ b/dist/Data-Dumper/Dumper.pm
228@@ -11,6 +11,7 @@ package Data::Dumper;
229
230 use strict;
231 use warnings;
232+no warnings 'experimental::builtin';
233
234 #$| = 1;
235
236@@ -125,8 +126,7 @@ sub new {
237 # Packed numeric addresses take less memory. Plus pack is faster than sprintf
238
239 sub format_refaddr {
240- require Scalar::Util;
241- pack "J", Scalar::Util::refaddr(shift);
242+ pack "J", builtin::refaddr(shift);
243 };
244
245 #
246@@ -282,9 +282,8 @@ sub _dump {
247 warn "WARNING(Freezer method call failed): $@" if $@;
248 }
249
250- require Scalar::Util;
251- my $realpack = Scalar::Util::blessed($val);
252- my $realtype = $realpack ? Scalar::Util::reftype($val) : ref $val;
253+ my $realpack = builtin::blessed($val);
254+ my $realtype = $realpack ? builtin::reftype($val) : ref $val;
255 $id = format_refaddr($val);
256
257 # Note: By this point $name is always defined and of non-zero length.
258@@ -576,7 +575,7 @@ sub _dump {
259 # here generates a different result. So there are actually "three" different
260 # implementations of Data::Dumper (kind of sort of) but we only test two.
261 elsif (!defined &_vstring
262- and ref $ref eq 'VSTRING' || eval{Scalar::Util::isvstring($val)}) {
263+ and ref $ref eq 'VSTRING') {
264 $out .= sprintf "v%vd", $val;
265 }
266 # \d here would treat "1\x{660}" as a safe decimal number
267diff --git a/cpan/JSON-PP/lib/JSON/PP.pm b/cpan/JSON-PP/lib/JSON/PP.pm
268index fc8fcbc8f0..cda7b90c65 100644
269--- a/cpan/JSON-PP/lib/JSON/PP.pm
270+++ b/cpan/JSON-PP/lib/JSON/PP.pm
271@@ -12,6 +12,6 @@ package JSON::PP;
272
273 use Carp ();
274-use Scalar::Util qw(blessed reftype refaddr);
275+use builtin qw(blessed reftype refaddr);
276 #use Devel::Peek;
277
278
279diff --git a/cpan/CPAN-Meta/lib/Parse/CPAN/Meta.pm b/cpan/CPAN-Meta/lib/Parse/CPAN/Meta.pm
280--- a/cpan/CPAN-Meta/lib/Parse/CPAN/Meta.pm
281+++ b/cpan/CPAN-Meta/lib/Parse/CPAN/Meta.pm
282@@ -53,7 +53,8 @@ sub load_json_string {
283 my ($class, $string) = @_;
284 require Encode;
285 # load_json_string takes characters, decode_json expects bytes
286- my $encoded = Encode::encode('UTF-8', $string, Encode::PERLQQ());
287+ my $encoded = $string;
288+ utf8::encode($encoded); # Miniperl workaround
289 my $data = eval { $class->json_decoder()->can('decode_json')->($encoded) };
290 croak $@ if $@;
291 return $data || {};
292@@ -122,7 +122,7 @@ sub _slurp {
293 open my $fh, "<:raw", "$_[0]" ## no critic
294 or die "can't open $_[0] for reading: $!";
295 my $content = do { local $/; <$fh> };
296- $content = Encode::decode('UTF-8', $content, Encode::PERLQQ());
297+ utf8::decode($content); # Workaround for miniperl
298 return $content;
299 }