File Coverage

blib/lib/Groonga/Escape.pm
Criterion Covered Total %
statement 9 19 47.3
branch 0 2 0.0
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 12 28 42.8


line stmt bran cond sub pod time code
1             # Copyright (C) 2022 Horimoto Yasuhiro
2             #
3             # This program is free software: you can redistribute it and/or modify
4             # it under the terms of the GNU General Public License as published by
5             # the Free Software Foundation, either version 3 of the License, or
6             # (at your option) any later version.
7             #
8             # This program is distributed in the hope that it will be useful,
9             # but WITHOUT ANY WARRANTY; without even the implied warranty of
10             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11             # GNU General Public License for more details.
12             #
13             # You should have received a copy of the GNU General Public License
14             # along with this program. If not, see .
15              
16             package Groonga::Escape;
17              
18 1     1   5 use strict;
  1         2  
  1         24  
19 1     1   4 use warnings;
  1         1  
  1         21  
20              
21 1     1   4 use Carp 'croak';
  1         2  
  1         151  
22              
23             sub new {
24 0     0 0   my ($class, %args) = @_;
25 0           my $self = {%args};
26              
27 0           return bless $self, $class;
28             }
29              
30             sub escape {
31 0     0 0   my ($class, $raw_query) = @_;
32 0 0         unless($raw_query) {
33 0           croak "Invalid arguments: ${raw_query}";
34             }
35              
36 0           my $escape = '\\';
37 0           my $escaped_query = $raw_query;
38 0           $escaped_query =~ s/([+\-><~*()"\\:])/$escape$1/g;
39              
40 0           return $escaped_query;
41             }
42              
43             1;