line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::JSON; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.007'; |
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
248359
|
use strict; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
243
|
|
6
|
7
|
|
|
7
|
|
40
|
use warnings; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
178
|
|
7
|
7
|
|
|
7
|
|
31
|
use Carp; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
428
|
|
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
3343
|
use JSON qw/ decode_json /; |
|
7
|
|
|
|
|
54309
|
|
|
7
|
|
|
|
|
74
|
|
10
|
7
|
|
|
7
|
|
1192
|
use List::Util qw/ first /; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
856
|
|
11
|
|
|
|
|
|
|
|
12
|
7
|
|
|
|
|
553
|
use constant GEOMETRY_OBJECTS => [ |
13
|
|
|
|
|
|
|
qw/ Point MultiPoint LineString MultiLineString Polygon MultiPolygon GeometryCollection / |
14
|
7
|
|
|
7
|
|
38
|
]; |
|
7
|
|
|
|
|
9
|
|
15
|
7
|
|
|
|
|
1801
|
use constant GEOJSON_OBJECTS => [ # |
16
|
7
|
|
|
|
|
11
|
@{ +GEOMETRY_OBJECTS }, qw/ Feature FeatureCollection / |
17
|
7
|
|
|
7
|
|
38
|
]; |
|
7
|
|
|
|
|
11
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $json = JSON->new->utf8->convert_blessed(1); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub from_json { |
22
|
32
|
|
|
32
|
1
|
8537
|
my ( $class, $json ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
32
|
|
|
|
|
1479
|
my $data = decode_json($json); |
25
|
|
|
|
|
|
|
|
26
|
32
|
50
|
|
|
|
127
|
croak "from_json requires a JSON object (hashref)" |
27
|
|
|
|
|
|
|
unless ref $data eq 'HASH'; |
28
|
|
|
|
|
|
|
|
29
|
32
|
|
|
|
|
89
|
return $class->load($data); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub load { |
33
|
42
|
|
|
42
|
1
|
17425
|
my ( $class, $data ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
42
|
50
|
|
|
|
175
|
my $type = delete $data->{type} |
36
|
|
|
|
|
|
|
or croak "Invalid JSON data: no type specified"; |
37
|
|
|
|
|
|
|
|
38
|
42
|
|
|
|
|
102
|
my $geo_json_class = 'Geo::JSON::' . $type; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
croak "Invalid type '$type'" |
41
|
42
|
100
|
|
144
|
|
182
|
unless first { $type eq $_ } @{ +GEOJSON_OBJECTS }; |
|
144
|
|
|
|
|
237
|
|
|
42
|
|
|
|
|
193
|
|
42
|
|
|
|
|
|
|
|
43
|
41
|
|
|
|
|
2432
|
eval "require $geo_json_class"; |
44
|
|
|
|
|
|
|
|
45
|
41
|
|
|
|
|
846
|
return $geo_json_class->new($data); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub codec { |
49
|
22
|
|
|
22
|
1
|
44
|
my $class = shift; |
50
|
|
|
|
|
|
|
|
51
|
22
|
|
|
|
|
26
|
my $orig = $json; |
52
|
22
|
50
|
|
|
|
50
|
$json = shift if @_; |
53
|
|
|
|
|
|
|
|
54
|
22
|
|
|
|
|
255
|
return $orig; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |