line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::JSON; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.006'; # VERSION |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Perl OO interface for geojson |
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
632080
|
use strict; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
299
|
|
8
|
7
|
|
|
7
|
|
41
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
198
|
|
9
|
7
|
|
|
7
|
|
35
|
use Carp; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
491
|
|
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
|
6043
|
use JSON qw/ decode_json /; |
|
7
|
|
|
|
|
86025
|
|
|
7
|
|
|
|
|
272
|
|
12
|
7
|
|
|
7
|
|
1313
|
use List::Util qw/ first /; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
946
|
|
13
|
|
|
|
|
|
|
|
14
|
7
|
|
|
|
|
575
|
use constant GEOMETRY_OBJECTS => [ |
15
|
|
|
|
|
|
|
qw/ Point MultiPoint LineString MultiLineString Polygon MultiPolygon GeometryCollection / |
16
|
7
|
|
|
7
|
|
42
|
]; |
|
7
|
|
|
|
|
14
|
|
17
|
7
|
|
|
|
|
2355
|
use constant GEOJSON_OBJECTS => [ # |
18
|
7
|
|
|
|
|
13
|
@{ +GEOMETRY_OBJECTS }, qw/ Feature FeatureCollection / |
19
|
7
|
|
|
7
|
|
51
|
]; |
|
7
|
|
|
|
|
15
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $json = JSON->new->utf8->convert_blessed(1); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub from_json { |
26
|
32
|
|
|
32
|
1
|
11630
|
my ( $class, $json ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
32
|
|
|
|
|
2468
|
my $data = decode_json($json); |
29
|
|
|
|
|
|
|
|
30
|
32
|
50
|
|
|
|
139
|
croak "from_json requires a JSON object (hashref)" |
31
|
|
|
|
|
|
|
unless ref $data eq 'HASH'; |
32
|
|
|
|
|
|
|
|
33
|
32
|
|
|
|
|
129
|
return $class->load($data); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub load { |
38
|
42
|
|
|
42
|
1
|
33893
|
my ( $class, $data ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
42
|
50
|
|
|
|
196
|
my $type = delete $data->{type} |
41
|
|
|
|
|
|
|
or croak "Invalid JSON data: no type specified"; |
42
|
|
|
|
|
|
|
|
43
|
42
|
|
|
|
|
107
|
my $geo_json_class = 'Geo::JSON::' . $type; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
croak "Invalid type '$type'" |
46
|
42
|
100
|
|
144
|
|
263
|
unless first { $type eq $_ } @{ +GEOJSON_OBJECTS }; |
|
144
|
|
|
|
|
312
|
|
|
42
|
|
|
|
|
231
|
|
47
|
|
|
|
|
|
|
|
48
|
41
|
|
|
|
|
2567
|
eval "require $geo_json_class"; |
49
|
|
|
|
|
|
|
|
50
|
41
|
|
|
|
|
1003
|
return $geo_json_class->new($data); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub codec { |
55
|
22
|
|
|
22
|
1
|
56
|
my $class = shift; |
56
|
|
|
|
|
|
|
|
57
|
22
|
|
|
|
|
31
|
my $orig = $json; |
58
|
22
|
50
|
|
|
|
61
|
$json = shift if @_; |
59
|
|
|
|
|
|
|
|
60
|
22
|
|
|
|
|
321
|
return $orig; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |