Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[koha-equinox.git] / Koha / Util / SystemPreferences.pm
1 package Koha::Util::SystemPreferences;
2
3 # Copyright 2018 Koha Development Team
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use parent qw( Exporter );
23
24 our @EXPORT = qw(
25   get_yaml_pref_hash
26 );
27
28 =head1 NAME
29
30 Koha::Util::SystemPreferences - utility class with System Preference routines
31
32 =head1 METHODS
33
34 =head2 get_yaml_pref_hash
35
36 Turn a pref defined via YAML as a hash
37
38 =cut
39
40 sub get_yaml_pref_hash {
41     my ( $pref ) = @_;
42     return if !defined( $pref );
43
44     my @lines = split /\n/, C4::Context->preference($pref)//'';
45     my $pref_as_hash;
46     foreach my $line (@lines){
47         my ($field,$array) = split /:/, $line;
48         next if !$array;
49         $field =~ s/^\s*|\s*$//g;
50         $array =~ s/[ [\]\r]//g;
51         my @array = split /,/, $array;
52         @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array;
53         @array = map { $_ eq 'NULL' ? undef : $_ } @array;
54         $pref_as_hash->{$field} = \@array;
55     }
56
57     return $pref_as_hash;
58 }
59
60 1;
61 __END__
62
63 =head1 AUTHOR
64
65 Koha Development Team <http://koha-community.org/>
66
67 Nick Clemens <nick@bywatersolutions.com>
68
69 =cut