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.07'; |
5
|
1
|
|
|
1
|
|
73172
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Class::Tiny |
10
|
1
|
|
|
1
|
|
362
|
qw{ id name shortName phones postalCode address url vk instagram links longitude latitude }; |
|
1
|
|
|
|
|
1285
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
1089
|
use JSON::XS; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
564
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub properties { |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# my $self = shift; |
17
|
|
|
|
|
|
|
return { |
18
|
|
|
|
|
|
|
# set => [ sort keys $self ], |
19
|
7
|
|
|
7
|
1
|
3159
|
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
|
159124
|
my $feature_collection = shift; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my @result; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
2
|
for my $f ( @{ $feature_collection->features } ) { |
|
1
|
|
|
|
|
6
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
5
|
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
|
|
|
|
|
4
|
|
47
|
1
|
|
|
|
|
12
|
push @{ $h->{links} }, $_->{href} for ( @{ $company_meta->{Links} } ); |
|
1
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
7
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $vk_link = |
50
|
1
|
|
|
|
|
8
|
( grep { $_->{aref} eq '#vkontakte' } @{ $company_meta->{Links} } ) |
|
3
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
2
|
|
51
|
|
|
|
|
|
|
[0]; |
52
|
1
|
50
|
|
|
|
4
|
$h->{vk} = $vk_link->{href} if defined $vk_link; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $inst_link = |
55
|
1
|
|
|
|
|
2
|
( grep { $_->{aref} eq '#instagram' } @{ $company_meta->{Links} } ) |
|
3
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
56
|
|
|
|
|
|
|
[0]; |
57
|
1
|
50
|
|
|
|
4
|
$h->{instagram} = $inst_link->{href} if defined $inst_link; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
5
|
$h->{longitude} = $f->geometry->coordinates->[1]; |
60
|
1
|
|
|
|
|
3
|
$h->{latitude} = $f->geometry->coordinates->[0]; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
8
|
my $company_obj = __PACKAGE__->new(%$h); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
67
|
push @result, $company_obj; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
4
|
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
|
5
|
my ( $self, $separator ) = @_; |
110
|
|
|
|
|
|
|
|
111
|
2
|
50
|
|
|
|
7
|
$separator = "\n" unless defined $separator; |
112
|
2
|
|
|
|
|
4
|
my @res; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
3
|
for my $p ( @{ properties()->{all} } ) { |
|
2
|
|
|
|
|
5
|
|
115
|
|
|
|
|
|
|
|
116
|
24
|
100
|
|
|
|
367
|
if ( ref( $self->$p ) eq 'ARRAY' ) { |
117
|
2
|
|
|
|
|
12
|
$self->$p( join( $separator, @{ $self->$p } ) ); |
|
2
|
|
|
|
|
23
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
24
|
|
|
|
|
383
|
push @res, $self->$p; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
15
|
return \@res; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |