1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
package Bugzilla::Search::Condition;
use 5.10.1;
use strict;
use warnings;
use base qw(Exporter);
our @EXPORT_OK = qw(condition);
sub new {
my ($class, $params) = @_;
my %self = %$params;
bless \%self, $class;
return \%self;
}
sub field { return $_[0]->{field} }
sub value { return $_[0]->{value} }
sub operator {
my ($self, $value) = @_;
if (@_ == 2) {
$self->{operator} = $value;
}
return $self->{operator};
}
sub fov {
my ($self) = @_;
return ($self->field, $self->operator, $self->value);
}
sub translated {
my ($self, $params) = @_;
if (@_ == 2) {
$self->{translated} = $params;
}
return $self->{translated};
}
sub as_string {
my ($self) = @_;
my $term = $self->translated->{term};
$term = "NOT( $term )" if $term && $self->negate;
return $term;
}
sub as_params {
my ($self) = @_;
return {
f => $self->field,
o => $self->operator,
v => $self->value,
n => scalar $self->negate
};
}
sub negate {
my ($self, $value) = @_;
if (@_ == 2) {
$self->{negate} = $value ? 1 : 0;
}
return $self->{negate};
}
###########################
# Convenience Subroutines #
###########################
sub condition {
my ($field, $operator, $value) = @_;
return __PACKAGE__->new(
{field => $field, operator => $operator, value => $value});
}
1;
|