line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::MobileAttribute::Plugin::Locator; |
2
|
10
|
|
|
10
|
|
25647
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
363
|
|
3
|
10
|
|
|
10
|
|
197
|
use warnings; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
331
|
|
4
|
10
|
|
|
10
|
|
54
|
use base qw/HTTP::MobileAttribute::Plugin/; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
5360
|
|
5
|
10
|
|
|
10
|
|
101
|
use UNIVERSAL::require; |
|
10
|
|
|
|
|
28
|
|
|
10
|
|
|
|
|
150
|
|
6
|
10
|
|
|
10
|
|
226
|
use Carp; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
769
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
10
|
|
|
|
|
1153
|
LOCATOR_AUTO_FROM_COMPLIANT => 1, |
9
|
|
|
|
|
|
|
LOCATOR_AUTO => 2, |
10
|
|
|
|
|
|
|
LOCATOR_GPS => 3, |
11
|
|
|
|
|
|
|
LOCATOR_BASIC => 4, |
12
|
10
|
|
|
10
|
|
61
|
}; |
|
10
|
|
|
|
|
25
|
|
13
|
10
|
|
|
10
|
|
58
|
use Exporter 'import'; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
3270
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw/LOCATOR_AUTO_FROM_COMPLIANT LOCATOR_AUTO LOCATOR_GPS LOCATOR_BASIC/; |
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
17
|
|
|
|
|
|
|
'constants' => [@EXPORT_OK], |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->depends(['IS', 'GPS', 'IS::ThirdForce']); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub get_location :Method { |
23
|
41
|
|
|
41
|
1
|
485
|
my ($self, $c, $stuff, $option_ref) = @_; |
24
|
41
|
|
|
|
|
128
|
my $params = _prepare_params( $stuff ); |
25
|
41
|
|
|
|
|
134
|
return $self->_locator($c, $params, $option_ref)->get_location($params); |
26
|
10
|
|
|
10
|
|
10833
|
} |
|
10
|
|
|
|
|
14903
|
|
|
10
|
|
|
|
|
146
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _locator { |
29
|
41
|
|
|
41
|
|
63
|
my ($self, $c, $params, $option_ref) = @_; |
30
|
41
|
|
|
|
|
86
|
my $suffix = _get_carrier_locator($c, $params, $option_ref); |
31
|
40
|
|
|
|
|
74
|
my $klass = "@{[ ref $self ]}::$suffix"; |
|
40
|
|
|
|
|
152
|
|
32
|
40
|
50
|
|
|
|
305
|
$klass->use or die $@; |
33
|
40
|
|
|
|
|
456
|
return $klass->new(); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _get_carrier_locator { |
37
|
89
|
|
|
89
|
|
254
|
my ( $agent, $params, $option_ref ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
89
|
|
|
|
|
304
|
my $carrier = $agent->carrier_longname; |
40
|
89
|
100
|
|
|
|
224
|
croak( "Invalid mobile user agent: " . $agent->user_agent ) if $carrier eq 'NonMobile'; |
41
|
|
|
|
|
|
|
|
42
|
88
|
|
|
|
|
94
|
my $locator; |
43
|
88
|
100
|
100
|
|
|
760
|
if ( !defined $option_ref |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|| !defined $option_ref->{locator} |
45
|
|
|
|
|
|
|
|| $option_ref->{locator} eq LOCATOR_AUTO_FROM_COMPLIANT ) |
46
|
|
|
|
|
|
|
{ |
47
|
37
|
100
|
|
|
|
147
|
$locator = $agent->gps_compliant ? 'GPS' : 'BasicLocation'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ( $option_ref->{locator} eq LOCATOR_AUTO ) { |
50
|
25
|
100
|
|
|
|
74
|
$locator = |
51
|
|
|
|
|
|
|
_is_gps_parameter( $agent, $params ) ? 'GPS' : 'BasicLocation'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( $option_ref->{locator} eq LOCATOR_GPS ) { |
54
|
10
|
|
|
|
|
15
|
$locator = 'GPS'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ( $option_ref->{locator} eq LOCATOR_BASIC ) { |
57
|
16
|
|
|
|
|
32
|
$locator = 'BasicLocation'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
0
|
croak( "Invalid locator: " . $option_ref->{locator} ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
88
|
|
|
|
|
389
|
return $carrier . '::' . $locator; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# to check whether parameter is gps or basic |
67
|
|
|
|
|
|
|
sub _is_gps_parameter { |
68
|
32
|
|
|
32
|
|
77
|
my ( $agent, $stuff ) = @_; |
69
|
32
|
|
|
|
|
141
|
my $params = _prepare_params($stuff); |
70
|
32
|
100
|
|
|
|
211
|
if ( $agent->is_docomo ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
71
|
12
|
|
|
|
|
64
|
return !defined $params->{AREACODE}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif ( $agent->is_ezweb ) { |
74
|
9
|
|
100
|
|
|
96
|
return defined $params->{datum} && $params->{datum} =~ /^\d+$/; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif ( $agent->is_softbank ) { |
77
|
9
|
|
|
|
|
40
|
return defined $params->{pos}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif ( $agent->is_airh_phone ) { |
80
|
2
|
|
|
|
|
8
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
0
|
croak( "Invalid mobile user agent: " . $agent->user_agent ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _prepare_params { |
88
|
77
|
|
|
77
|
|
8810
|
my $stuff = shift; |
89
|
77
|
100
|
100
|
|
|
255
|
if ( ref $stuff && eval { $stuff->can('param') } ) { |
|
69
|
|
|
|
|
672
|
|
90
|
|
|
|
|
|
|
return +{ |
91
|
8
|
|
|
|
|
25
|
map { |
92
|
3
|
100
|
|
|
|
46
|
$_ => ( scalar( @{ [ $stuff->param($_) ] } ) > 1 ) |
|
8
|
|
|
|
|
212
|
|
93
|
|
|
|
|
|
|
? [ $stuff->param($_) ] |
94
|
|
|
|
|
|
|
: $stuff->param($_) |
95
|
|
|
|
|
|
|
} $stuff->param |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
74
|
|
|
|
|
149
|
return $stuff; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
__END__ |