diff options
author | Chase Whitener <cwhitener@gmail.com> | 2018-01-09 15:43:17 -0500 |
---|---|---|
committer | Julien Fiegehenn <simbabque@cpan.org> | 2023-04-29 17:01:54 +0100 |
commit | 10a1c73d9aec86bdc0ff12adf197d7624a923776 (patch) | |
tree | 420bf80239d2174714a39c25a14cfd99777e6335 | |
parent | 0f2cb990c9f27e2da1b661876e24fe19d0f52bee (diff) | |
download | uri-10a1c73d9aec86bdc0ff12adf197d7624a923776.tar.gz |
Update URI::_punycode to make several functions that have never
been documented and have always been considered private to
actually be private.
* adapt -> _adapt
* code_point -> _code_point
* digit_value -> _digit_value
* min -> _min
This allows us to remove some special casing in the dist.ini conf
file, reducing complexity.
-rw-r--r-- | Changes | 1 | ||||
-rw-r--r-- | dist.ini | 1 | ||||
-rw-r--r-- | lib/URI/_punycode.pm | 20 |
3 files changed, 11 insertions, 11 deletions
@@ -81,6 +81,7 @@ Revision history for URI 1.73 2018-01-09 06:42:51Z - Update documentation for URI::_punycode (GH Issue #45) + - Prefix private methods with _ in URI::_punycode (GH Issue #47) 1.72 2017-07-25 - Convert the dist to Dist::Zilla for authoring. @@ -103,7 +103,6 @@ trustme = URI::Heuristic => qr/^(?:MY_COUNTRY|uf_url|uf_urlstr)$/ trustme = URI::URL => qr/^(?:address|article|crack|dos_path|encoded822addr|eparams|epath|frag)$/ trustme = URI::URL => qr/^(?:full_path|groupart|keywords|local_path|mac_path|netloc|newlocal|params|path|path_components|print_on|query|strict|unix_path|url|vms_path)$/ trustme = URI::WithBase => qr/^(?:can|clone|eq|new_abs)$/ -trustme = URI::_punycode => qr/^(?:adapt|code_point|digit_value|min)$/ trustme = URI::_query => qr/^(?:equery|query|query_form|query_form_hash|query_keywords|query_param|query_param_append|query_param_delete)$/ trustme = URI::_segment => qr/^(?:new)$/ trustme = URI::_userpass => qr/^(?:password|user)$/ diff --git a/lib/URI/_punycode.pm b/lib/URI/_punycode.pm index 25eba2b..1c73079 100644 --- a/lib/URI/_punycode.pm +++ b/lib/URI/_punycode.pm @@ -25,7 +25,7 @@ my $BasicRE = qr/[\x00-\x7f]/; sub _croak { require Carp; Carp::croak(@_); } -sub digit_value { +sub _digit_value { my $code = shift; return ord($code) - ord("A") if $code =~ /[A-Z]/; return ord($code) - ord("a") if $code =~ /[a-z]/; @@ -33,14 +33,14 @@ sub digit_value { return; } -sub code_point { +sub _code_point { my $digit = shift; return $digit + ord('a') if 0 <= $digit && $digit <= 25; return $digit + ord('0') - 26 if 26 <= $digit && $digit <= 36; die 'NOT COME HERE'; } -sub adapt { +sub _adapt { my($delta, $numpoints, $firsttime) = @_; $delta = $firsttime ? $delta / DAMP : $delta / 2; $delta += $delta / $numpoints; @@ -71,7 +71,7 @@ sub decode_punycode { LOOP: for (my $k = BASE; 1; $k += BASE) { my $cp = substr($code, 0, 1, ''); - my $digit = digit_value($cp); + my $digit = _digit_value($cp); defined $digit or return _croak("invalid punycode input"); $i += $digit * $w; my $t = ($k <= $bias) ? TMIN @@ -79,7 +79,7 @@ sub decode_punycode { last LOOP if $digit < $t; $w *= (BASE - $t); } - $bias = adapt($i - $oldi, @output + 1, $oldi == 0); + $bias = _adapt($i - $oldi, @output + 1, $oldi == 0); warn "bias becomes $bias" if $DEBUG; $n += $i / (@output + 1); $i = $i % (@output + 1); @@ -106,7 +106,7 @@ sub encode_punycode { warn "basic codepoints: (@output)" if $DEBUG; while ($h < @input) { - my $m = min(grep { $_ >= $n } map ord, @input); + my $m = _min(grep { $_ >= $n } map ord, @input); warn sprintf "next code point to insert is %04x", $m if $DEBUG; $delta += ($m - $n) * ($h + 1); $n = $m; @@ -120,12 +120,12 @@ sub encode_punycode { my $t = ($k <= $bias) ? TMIN : ($k >= $bias + TMAX) ? TMAX : $k - $bias; last LOOP if $q < $t; - my $cp = code_point($t + (($q - $t) % (BASE - $t))); + my $cp = _code_point($t + (($q - $t) % (BASE - $t))); push @output, chr($cp); $q = ($q - $t) / (BASE - $t); } - push @output, chr(code_point($q)); - $bias = adapt($delta, $h + 1, $h == $b); + push @output, chr(_code_point($q)); + $bias = _adapt($delta, $h + 1, $h == $b); warn "bias becomes $bias" if $DEBUG; $delta = 0; $h++; @@ -137,7 +137,7 @@ sub encode_punycode { return join '', @output; } -sub min { +sub _min { my $min = shift; for (@_) { $min = $_ if $_ <= $min } return $min; |