line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::GData::Query; |
2
|
9
|
|
|
9
|
|
51983
|
use WebService::GData; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
61
|
|
3
|
9
|
|
|
9
|
|
43
|
use base 'WebService::GData'; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
763
|
|
4
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
5289
|
use WebService::GData::Error; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
92
|
|
6
|
9
|
|
|
9
|
|
5665
|
use WebService::GData::Constants qw(:all); |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
15705
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#specify default parameters |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.0205; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
*disable = *WebService::GData::disable; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub __init { |
15
|
6
|
|
|
6
|
|
15
|
my $this = shift; |
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
534
|
$this->{_query} = { |
18
|
|
|
|
|
|
|
'v' => GDATA_MINIMUM_VERSION, |
19
|
|
|
|
|
|
|
alt => JSON, |
20
|
|
|
|
|
|
|
prettyprint => FALSE, |
21
|
|
|
|
|
|
|
strict => TRUE, |
22
|
|
|
|
|
|
|
}; |
23
|
6
|
|
|
|
|
19
|
return $this; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub set_from_query_string { |
28
|
0
|
|
|
0
|
0
|
0
|
my ($this,$uri) = @_; |
29
|
0
|
|
|
|
|
0
|
my (undef,$query_string) = split(/\?/,$uri); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
0
|
my @elements = split(/&/,$query_string); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
foreach my $element (@elements){ |
34
|
0
|
|
|
|
|
0
|
my ($param,$val)= split(/=/,$element); |
35
|
0
|
|
|
|
|
0
|
$this->_set_query($param,$val); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub install_sub { |
41
|
138
|
|
|
138
|
0
|
162
|
my $subname = shift; |
42
|
138
|
|
|
|
|
143
|
my $field = $subname; |
43
|
138
|
|
|
|
|
224
|
$field =~ s/_/-/g; |
44
|
|
|
|
|
|
|
return sub { |
45
|
4
|
|
|
4
|
|
11
|
my ( $this, $val ) = @_; |
46
|
|
|
|
|
|
|
|
47
|
4
|
100
|
|
|
|
45
|
if ( my $code = $this->can( '_' . $field . '_is_valid' ) ) { |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
5
|
my $res = &$code($val); |
50
|
1
|
50
|
|
|
|
5
|
if ($res) { |
51
|
0
|
|
|
|
|
0
|
return $this->_set_query( $field, $val ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
1
|
|
|
|
|
16
|
die new WebService::GData::Error( 'invalid_parameter_type', |
55
|
|
|
|
|
|
|
$subname . '() did not get a proper value.' ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
3
|
|
|
|
|
16
|
return $this->_set_query( $field, $val ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
138
|
|
|
|
|
615
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub install { |
64
|
13
|
|
|
13
|
1
|
29
|
my $parameters = shift; |
65
|
13
|
|
|
|
|
42
|
my $package = caller; |
66
|
13
|
|
|
|
|
65
|
WebService::GData::install_in_package( $parameters, \&install_sub, |
67
|
|
|
|
|
|
|
$package ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
install( |
71
|
|
|
|
|
|
|
[ |
72
|
|
|
|
|
|
|
'strict', 'fields', 'v', 'alt', |
73
|
|
|
|
|
|
|
'prettyprint', 'author', 'updated_min', 'updated_max', |
74
|
|
|
|
|
|
|
'published_min', 'published_max' |
75
|
|
|
|
|
|
|
] |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#move this else where... |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _is_date_format { |
81
|
0
|
|
|
0
|
|
0
|
my $val = shift; |
82
|
0
|
0
|
|
|
|
0
|
return $val |
83
|
|
|
|
|
|
|
if ( $val =~ |
84
|
|
|
|
|
|
|
m/[0-9]{4}-[0-9]{2}-[0-9]{3}T[0-9]{2}:[0-9]{2}:[0-9]{2}-[0-9]{2}:00/ ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _is_boolean { |
88
|
1
|
|
|
1
|
|
2
|
my $val = shift; |
89
|
1
|
50
|
33
|
|
|
59
|
return $val if ( $val eq FALSE || $val eq TRUE ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _v_is_valid { |
93
|
0
|
|
|
0
|
|
0
|
my $val = shift; |
94
|
0
|
0
|
|
|
|
0
|
return $val if ( $val >= GDATA_MINIMUM_VERSION ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _published_max_is_valid { |
98
|
0
|
|
|
0
|
|
0
|
return _is_date_format( shift() ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _published_min_is_valid { |
102
|
0
|
|
|
0
|
|
0
|
return _is_date_format( shift() ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _updated_max_is_valid { |
106
|
0
|
|
|
0
|
|
0
|
return _is_date_format( shift() ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _updated_min_is_valid { |
110
|
0
|
|
|
0
|
|
0
|
return _is_date_format( shift() ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _prettyprint_is_valid { |
114
|
1
|
|
|
1
|
|
6
|
return _is_boolean( shift() ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _strict_is_valid { |
118
|
0
|
|
|
0
|
|
0
|
return _is_boolean( shift() ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub start_index { |
122
|
1
|
|
|
1
|
1
|
2
|
my ( $this, $start ) = @_; |
123
|
1
|
50
|
|
|
|
8
|
return $this->_set_query( 'start-index', ( int($start) < 1 ) ? 1 : $start ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub max_results { |
127
|
1
|
|
|
1
|
1
|
2
|
my ( $this, $max ) = @_; |
128
|
1
|
50
|
|
|
|
6
|
return $this->_set_query( 'max-results', ( int($max) < 1 ) ? 1 : $max ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub limit { |
132
|
1
|
|
|
1
|
1
|
3
|
my ( $this, $max, $offset ) = @_; |
133
|
1
|
|
|
|
|
4
|
$this->start_index($offset); |
134
|
1
|
|
|
|
|
4
|
return $this->max_results($max); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub q { |
138
|
0
|
|
|
0
|
1
|
0
|
my ( $this, $search ) = @_; |
139
|
0
|
|
|
|
|
0
|
$search =~ s/\s+AND\s+/ /g; |
140
|
0
|
|
|
|
|
0
|
return $this->_set_query( 'q', $search ); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub category { |
144
|
0
|
|
|
0
|
1
|
0
|
my ( $this, $category ) = @_; |
145
|
0
|
|
|
|
|
0
|
$category =~ s/\s+OR\s+/|/g; |
146
|
0
|
|
|
|
|
0
|
$category =~ s/\s+AND\s+/,/g; |
147
|
0
|
|
|
|
|
0
|
$category =~ s/\s{1}/,/g; |
148
|
0
|
|
|
|
|
0
|
return $this->_set_query( 'category', $category ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _set_query { |
152
|
5
|
|
|
5
|
|
10
|
my ( $this, $key, $val ) = @_; |
153
|
5
|
|
|
|
|
17
|
$this->{_query}->{$key} = $val; |
154
|
5
|
|
|
|
|
17
|
return $this; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub get { |
158
|
20
|
|
|
20
|
1
|
1294
|
my ( $this, $key ) = @_; |
159
|
20
|
|
|
|
|
222
|
return $this->{_query}->{$key}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub to_query_string { |
163
|
4
|
|
|
4
|
1
|
8
|
my $this = shift; |
164
|
4
|
|
|
|
|
9
|
my @query = (); |
165
|
4
|
|
|
|
|
7
|
while ( my ( $field, $value ) = each %{ $this->{_query} } ) { |
|
22
|
|
|
|
|
80
|
|
166
|
18
|
50
|
|
|
|
56
|
push @query, $field . '=' . _urlencode($value) if ( defined $value ); |
167
|
18
|
50
|
|
|
|
49
|
push @query, $field if ( !defined $value ); |
168
|
|
|
|
|
|
|
} |
169
|
4
|
|
|
|
|
40
|
return '?' . join '&', @query; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _urlencode { |
173
|
18
|
|
|
18
|
|
24
|
my ($string) = shift; |
174
|
18
|
|
|
|
|
33
|
$string =~ s/(\W)/"%" . unpack("H2", $1)/ge; |
|
0
|
|
|
|
|
0
|
|
175
|
18
|
|
|
|
|
39
|
return $string; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub __to_string { |
179
|
1
|
|
|
1
|
|
4
|
return shift()->to_query_string(); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
"The earth is blue like an orange."; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |