| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Convenient representation of company from Yandex Maps |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Yandex::Geo::Company; |
|
4
|
|
|
|
|
|
|
$Yandex::Geo::Company::VERSION = '0.05'; |
|
5
|
1
|
|
|
1
|
|
71525
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
22
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
31
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Object::Tiny |
|
10
|
1
|
|
|
1
|
|
338
|
qw{ id name shortName phones postalCode address url vk instagram links longitude latitude }; |
|
|
1
|
|
|
|
|
210
|
|
|
|
1
|
|
|
|
|
5
|
|
|
11
|
1
|
|
|
1
|
|
293
|
use JSON::XS; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
553
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub properties { |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# my $self = shift; |
|
17
|
|
|
|
|
|
|
return { |
|
18
|
|
|
|
|
|
|
# set => [ sort keys $self ], |
|
19
|
5
|
|
|
5
|
1
|
2790
|
all => [ |
|
20
|
|
|
|
|
|
|
qw{ id name shortName phones postalCode address url vk instagram links longitude latitude } |
|
21
|
|
|
|
|
|
|
], |
|
22
|
|
|
|
|
|
|
string => [ |
|
23
|
|
|
|
|
|
|
qw/id name shortName url address postalCode vk instagram longitude latitude/ |
|
24
|
|
|
|
|
|
|
], |
|
25
|
|
|
|
|
|
|
array => [qw/phones links/] # real properties in capital case |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub from_geo_json { |
|
31
|
1
|
|
|
1
|
1
|
157471
|
my $feature_collection = shift; |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
3
|
my @result; |
|
34
|
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
for my $f ( @{ $feature_collection->features } ) { |
|
|
1
|
|
|
|
|
6
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
4
|
my $company_meta = $f->properties->{CompanyMetaData}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
2
|
my $h = {}; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
for ( @{ __PACKAGE__->properties->{string} } ) { |
|
|
1
|
|
|
|
|
8
|
|
|
42
|
10
|
|
|
|
|
20
|
$h->{$_} = $company_meta->{$_}; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
8
|
push @{ $h->{phones} }, $_->{formatted} |
|
46
|
1
|
|
|
|
|
3
|
for ( @{ $company_meta->{Phones} } ); |
|
|
1
|
|
|
|
|
3
|
|
|
47
|
1
|
|
|
|
|
1
|
push @{ $h->{links} }, $_->{href} for ( @{ $company_meta->{Links} } ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
8
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $vk_link = |
|
50
|
1
|
|
|
|
|
2
|
( grep { $_->{aref} eq '#vkontakte' } @{ $company_meta->{Links} } ) |
|
|
3
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
2
|
|
|
51
|
|
|
|
|
|
|
[0]; |
|
52
|
1
|
50
|
|
|
|
5
|
$h->{vk} = $vk_link->{href} if defined $vk_link; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $inst_link = |
|
55
|
1
|
|
|
|
|
3
|
( grep { $_->{aref} eq '#instagram' } @{ $company_meta->{Links} } ) |
|
|
3
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
12
|
|
|
56
|
|
|
|
|
|
|
[0]; |
|
57
|
1
|
50
|
|
|
|
4
|
$h->{instagram} = $inst_link->{href} if defined $inst_link; |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
10
|
$h->{longitude} = $f->geometry->coordinates->[1]; |
|
60
|
1
|
|
|
|
|
5
|
$h->{latitude} = $f->geometry->coordinates->[0]; |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
16
|
my $company_obj = __PACKAGE__->new(%$h); |
|
63
|
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
12
|
push @result, $company_obj; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
return \@result; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub from_json { |
|
74
|
0
|
|
|
0
|
1
|
0
|
my $json_str = shift; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
my $res = decode_json $json_str; |
|
77
|
0
|
|
|
|
|
0
|
my $features = @{ $res->{features} }; |
|
|
0
|
|
|
|
|
0
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
my @result; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
for my $f (@$features) { |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
my $company_meta = $f->{properties}{CompanyMetaData}; |
|
84
|
0
|
|
|
|
|
0
|
my $h = {}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
for ( @{ __PACKAGE__->properties->{string} } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
87
|
0
|
|
|
|
|
0
|
$h->{$_} = $company_meta->{$_}; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
push @{ $h->{phones} }, $_->{formatted} |
|
91
|
0
|
|
|
|
|
0
|
for ( @{ $company_meta->{Phones} } ); |
|
|
0
|
|
|
|
|
0
|
|
|
92
|
0
|
|
|
|
|
0
|
push @{ $h->{links} }, $_->{href} for ( @{ $company_meta->{Links} } ); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
93
|
|
|
|
|
|
|
my $vk_link = |
|
94
|
0
|
|
|
|
|
0
|
( grep { $_->{aref} eq '#vkontakte' } @{ $company_meta->{Links} } ) |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
95
|
|
|
|
|
|
|
[0]; |
|
96
|
0
|
0
|
|
|
|
0
|
$h->{vk} = $vk_link->{href} if defined $vk_link; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
my $company_obj = __PACKAGE__->new(%$h); |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
push @result, $company_obj; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
return \@result; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub to_array { |
|
109
|
2
|
|
|
2
|
1
|
423
|
my $self = shift; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return [ |
|
112
|
|
|
|
|
|
|
$self->id, $self->name, |
|
113
|
2
|
|
|
|
|
37
|
$self->shortName, join( "\n", @{ $self->phones } ), |
|
114
|
|
|
|
|
|
|
$self->postalCode, $self->address, |
|
115
|
|
|
|
|
|
|
$self->longitude, $self->latitude, |
|
116
|
|
|
|
|
|
|
$self->url, $self->vk, |
|
117
|
2
|
|
|
|
|
39
|
$self->instagram, join( "\n", @{ $self->links } ) |
|
|
2
|
|
|
|
|
48
|
|
|
118
|
|
|
|
|
|
|
]; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |