| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojar::Google::Analytics::Request; |
|
2
|
4
|
|
|
4
|
|
34010
|
use Mojo::Base -base; |
|
|
4
|
|
|
|
|
14
|
|
|
|
4
|
|
|
|
|
61
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.012; |
|
5
|
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
989
|
use Carp 'croak'; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
272
|
|
|
7
|
4
|
|
|
4
|
|
2101
|
use Mojo::Parameters; |
|
|
4
|
|
|
|
|
103579
|
|
|
|
4
|
|
|
|
|
32
|
|
|
8
|
4
|
|
|
4
|
|
165
|
use Mojo::Util 'url_escape'; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
183
|
|
|
9
|
4
|
|
|
4
|
|
503
|
use POSIX 'strftime'; |
|
|
4
|
|
|
|
|
5269
|
|
|
|
4
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Attributes |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'access_token'; |
|
14
|
|
|
|
|
|
|
has 'ids'; |
|
15
|
|
|
|
|
|
|
has dimensions => sub {[]}; |
|
16
|
|
|
|
|
|
|
has metrics => sub {[]}; |
|
17
|
|
|
|
|
|
|
has 'segment'; |
|
18
|
|
|
|
|
|
|
has filters => sub {[]}; |
|
19
|
|
|
|
|
|
|
has sort => sub {[]}; |
|
20
|
|
|
|
|
|
|
has start_date => &_today; |
|
21
|
|
|
|
|
|
|
has end_date => &_today; |
|
22
|
|
|
|
|
|
|
has start_index => 1; |
|
23
|
|
|
|
|
|
|
has max_results => 10_000; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Public methods |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub params { |
|
28
|
2
|
|
|
2
|
1
|
10679
|
my $self = shift; |
|
29
|
2
|
|
|
|
|
18
|
my $param = Mojar::Google::Analytics::Request->new(%$self, @_); |
|
30
|
2
|
|
|
|
|
34
|
my $p = Mojo::Parameters->new; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Absorb driver params, using defaults if necessary |
|
33
|
2
|
|
|
|
|
26
|
for (qw(start_date end_date start_index max_results)) { |
|
34
|
8
|
|
|
|
|
226
|
my $k = $_; |
|
35
|
8
|
|
|
|
|
37
|
my $v = $param->$k; |
|
36
|
8
|
|
|
|
|
53
|
delete $param->{$k}; |
|
37
|
8
|
|
|
|
|
37
|
$k =~ s/_/-/; |
|
38
|
8
|
|
|
|
|
29
|
$p = $p->append($k => $v); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
54
|
for my $k (qw(dimensions metrics)) { |
|
42
|
4
|
|
|
|
|
20
|
my $v = $param->$k; |
|
43
|
4
|
50
|
33
|
|
|
52
|
if (not ref $v or ref $v ne 'ARRAY') { |
|
|
|
50
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
croak "Field $k needs to be an arrayref"; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
elsif (@$v >= 2 and @$v % 2 == 0 and $v->[1] and $v->[1] !~ /[a-z]/) { |
|
47
|
|
|
|
|
|
|
# Assume hash (declaring datatypes) |
|
48
|
0
|
|
|
|
|
0
|
my $a = 'ga:'. $v->[2 * 0]; |
|
49
|
0
|
|
|
|
|
0
|
$a .= ',ga:'. $v->[2 * $_] for 1 .. (@$v / 2 - 1); |
|
50
|
0
|
|
|
|
|
0
|
$p = $p->append($k => $a); |
|
51
|
0
|
|
|
|
|
0
|
delete $param->{$k}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Absorb everything else |
|
56
|
2
|
|
|
|
|
10
|
for my $k (keys %$param) { |
|
57
|
6
|
|
|
|
|
117
|
my $v = $param->$k; |
|
58
|
6
|
|
|
|
|
39
|
$k =~ s/_/-/; |
|
59
|
6
|
100
|
|
|
|
21
|
if (ref $v) { |
|
60
|
|
|
|
|
|
|
# Array ref |
|
61
|
4
|
|
|
|
|
13
|
$v = join ',', map "ga:$_", @$v; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
else { |
|
64
|
|
|
|
|
|
|
# Scalar |
|
65
|
2
|
|
|
|
|
4
|
my $descending = 0; |
|
66
|
2
|
50
|
33
|
|
|
9
|
$k eq 'sort' and $v =~ s/^-// and $descending = 1; |
|
67
|
2
|
50
|
|
|
|
15
|
$v = ($descending ? '-ga:' : 'ga:') . $v if defined $v; |
|
|
|
50
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
6
|
|
|
|
|
20
|
$p = $p->append($k => $v); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
2
|
|
|
|
|
55
|
return $p->to_string; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Private methods |
|
75
|
|
|
|
|
|
|
|
|
76
|
8
|
|
|
8
|
|
907
|
sub _today { strftime '%F', localtime } |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
|
79
|
|
|
|
|
|
|
__END__ |