| 1 | package MaxMind::DB::Writer::Util; | ||||||||||
| 2 | |||||||||||
| 3 | 38 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 38 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 38 | our $VERSION = '0.300004'; | |||||||||
| 7 | |||||||||||
| 8 | 38 | ▶ | use Digest::SHA qw( sha1_base64 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 38 | ▶ | use Encode qw( encode ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 38 | ▶ | use Sereal::Encoder 3.002 qw( sereal_encode_with_object ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 38 | ▶ | use Exporter qw( import ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 38 | our @EXPORT_OK = qw( key_for_data ); | |||||||||
| 14 | |||||||||||
| 15 | { | ||||||||||
| 16 | # Although this mostly works fine when canonical and canonical_refs are | ||||||||||
| 17 | # enabled, it is still somewhat broken. See: | ||||||||||
| 18 | # | ||||||||||
| 19 | # https://metacpan.org/pod/distribution/Sereal-Encoder/lib/Sereal/Encoder.pm#CANONICAL-REPRESENTATION | ||||||||||
| 20 | # | ||||||||||
| 21 | # The arrays in the example, for instance, would have distinct keys | ||||||||||
| 22 | # despite being structurally equivalent. Requires Sereal 3.002. | ||||||||||
| 23 | 38 | my $Encoder = Sereal::Encoder->new( | |||||||||
| 24 | { | ||||||||||
| 25 | canonical => 1, | ||||||||||
| 26 | canonical_refs => 1, | ||||||||||
| 27 | } | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 111272 | ▶ | sub key_for_data { | ||||||||
|
Subroutine
key_for_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 31 | |||||||||||
| 32 | # We need to use sha1 because the Sereal structure has \0 bytes which | ||||||||||
| 33 | # confuse the C code. As a bonus, this makes the keys smaller so they | ||||||||||
| 34 | # take up less space. As an un-bonus, this makes the code a little | ||||||||||
| 35 | # slower. | ||||||||||
| 36 | 111272 | ▶ | my $key | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | = ref $_[0] | ||||||||||
| 38 | ? sereal_encode_with_object( $Encoder, $_[0] ) | ||||||||||
| 39 | : encode( 'UTF-8', $_[0] ); | ||||||||||
| 40 | |||||||||||
| 41 | 111272 | return sha1_base64($key); | |||||||||
| 42 | } | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 38 | 1; | |||||||||