From 5d96e091e7f4993d3eb42ee7affec1f200857db6 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Mon, 3 Jun 2024 12:30:34 +0000 Subject: [PATCH] Bug 31109: Koha::Util::Misc - utility class with miscellaneous routines New module with only one function now: digest -- to calculate a md5_hex digest of the given argument (any Perl data structure). Signed-off-by: Roman Dolny --- Koha/Util/Misc.pm | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Koha/Util/Misc.pm diff --git a/Koha/Util/Misc.pm b/Koha/Util/Misc.pm new file mode 100644 index 0000000000..416d5fe40f --- /dev/null +++ b/Koha/Util/Misc.pm @@ -0,0 +1,56 @@ +package Koha::Util::Misc; + +# Copyright 2024 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Digest::MD5 qw( md5_hex ); +use Sereal::Encoder qw( encode_sereal ); + +use Exporter 'import'; + +BEGIN { + our @EXPORT_OK = qw( digest ); +} + +=head1 NAME + +Koha::Util::Misc - utility class with miscellaneous routines + +=head1 METHODS + +=head2 digest + +Calculates a md5_hex digest of the given argument (any Perl data structure). + +=cut + +sub digest { + my $data = shift; + return md5_hex( encode_sereal( ( ref $data eq '' ) ? \$data : $data, { sort_keys => 1 } ) ); +} + +1; +__END__ + +=head1 AUTHOR + +Koha Development Team + +Janusz Kaczmarek + +=cut -- 2.39.2