Bug 9239 follow-up: POD and perlcritic fixes
[koha.git] / Koha / QueryParser / Driver / PQF / Util.pm
1 package Koha::QueryParser::Driver::PQF::Util;
2 use Scalar::Util qw(looks_like_number);
3
4 use strict;
5 use warnings;
6
7 =head1 NAME
8
9     Koha::QueryParser::Driver::PQF::Util - Utility module for PQF QueryParser driver
10
11 =head1 FUNCTIONS
12
13 =head2 attributes_to_attr_string
14
15     Koha::QueryParser::Driver::PQF::Util(%attributes);
16
17     Koha::QueryParser::Driver::PQF::Util({ '1' => '1003', '4' => '6' });
18
19 Convert a hashref with a Bib-1 mapping into its PQF string representation.
20
21 =cut
22
23 sub attributes_to_attr_string {
24     my ($attributes) = @_;
25     my $attr_string = '';
26     my $key;
27     my $value;
28     while (($key, $value) = each(%$attributes)) {
29         next unless looks_like_number($key);
30         $attr_string .= ' @attr ' . $key . '=' . $value . ' ';
31     }
32     $attr_string =~ s/^\s*//;
33     $attr_string =~ s/\s*$//;
34     $attr_string .= ' ' . $attributes->{''} if defined $attributes->{''};
35     return $attr_string;
36 }
37
38 1;