our
$VERSION
=
'0.4'
;
Hide Show 36 lines of Pod
sub
new {
my
(
$class
,
%param
) =
@_
;
my
$obj
= {
'AddressDetails'
=> {
'Country'
=> {
'AdministrativeArea'
=> {
'SubAdministrativeArea'
=> {
'SubAdministrativeAreaName'
=>
delete
$param
{
'SubAdministrativeAreaName'
} ||
''
,
'Locality'
=> {
'PostalCode'
=> {
'PostalCodeNumber'
=>
delete
$param
{
'PostalCodeNumber'
} ||
''
},
'LocalityName'
=>
delete
$param
{
'LocalityName'
} ||
''
,
'Thoroughfare'
=> {
'ThoroughfareName'
=>
delete
$param
{
'ThoroughfareName'
} ||
''
}
}
},
'AdministrativeAreaName'
=>
delete
$param
{
'AdministrativeAreaName'
} ||
''
},
'CountryNameCode'
=>
delete
$param
{
'CountryNameCode'
} ||
''
,
'CountryName'
=>
delete
$param
{
'CountryName'
} ||
''
}
},
'address'
=>
delete
$param
{
'address'
} ||
''
,
'Point'
=> {
'coordinates'
=> [
delete
$param
{
'longitude'
} ||
''
,
delete
$param
{
'latitude'
} ||
''
,
delete
$param
{
'altitude'
} || 0
]
}
};
my
$out
=
delete
$param
{
'output'
} ||
'json'
;
bless
{
data
=>
$obj
,
output
=>
$out
},
$class
;
}
Hide Show 9 lines of Pod
sub
SubAdministrativeAreaName {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'SubAdministrativeAreaName'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'SubAdministrativeAreaName'
} ;
}
Hide Show 9 lines of Pod
sub
PostalCodeNumber {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'Locality'
}->{
'PostalCode'
}->{
'PostalCodeNumber'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'Locality'
}->{
'PostalCode'
}->{
'PostalCodeNumber'
} ;
}
Hide Show 9 lines of Pod
sub
ThoroughfareName {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'Locality'
}->{
'Thoroughfare'
}->{
'ThoroughfareName'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'Locality'
}->{
'Thoroughfare'
}->{
'ThoroughfareName'
} ;
}
Hide Show 9 lines of Pod
sub
LocalityName {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'Locality'
}->{
'LocalityName'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'SubAdministrativeArea'
}->{
'Locality'
}->{
'LocalityName'
} ;
}
Hide Show 9 lines of Pod
sub
AdministrativeAreaName {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'AdministrativeAreaName'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'AdministrativeArea'
}->{
'AdministrativeAreaName'
} ;
}
Hide Show 9 lines of Pod
sub
CountryName {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'CountryName'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'CountryName'
} ;
}
Hide Show 9 lines of Pod
sub
CountryNameCode {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'CountryNameCode'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Country'
}->{
'CountryNameCode'
} ;
}
Hide Show 9 lines of Pod
sub
Accuracy {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'AddressDetails'
}->{
'Accuracy'
}=
$data
:
$self
->{data}->{
'AddressDetails'
}->{
'Accuracy'
} ;
}
Hide Show 9 lines of Pod
sub
address {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'address'
}=
$data
:
$self
->{data}->{
'address'
} ;
}
Hide Show 9 lines of Pod
sub
id {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'id'
}=
$data
:
$self
->{data}->{
'id'
} ;
}
Hide Show 9 lines of Pod
sub
latitude {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'Point'
}->{
'coordinates'
}->[1]=
$data
:
$self
->{data}->{
'Point'
}->{
'coordinates'
}->[1] ;
}
Hide Show 9 lines of Pod
sub
longitude {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'Point'
}->{
'coordinates'
}->[0]=
$data
:
$self
->{data}->{
'Point'
}->{
'coordinates'
}->[0] ;
}
Hide Show 11 lines of Pod
sub
altitude {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'Point'
}->{
'coordinates'
}->[2]=
$data
:
$self
->{data}->{
'Point'
}->{
'coordinates'
}->[2] ;
}
Hide Show 8 lines of Pod
sub
coordinates {
my
$self
=
shift
;
return
$self
->longitude().
','
.
$self
->latitude().
','
.
$self
->altitude ;
}
Hide Show 9 lines of Pod
sub
LLB_north {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'north'
}=
$data
:
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'north'
} ;
}
Hide Show 9 lines of Pod
sub
LLB_south {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'south'
}=
$data
:
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'south'
} ;
}
Hide Show 9 lines of Pod
sub
LLB_east {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'east'
}=
$data
:
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'east'
} ;
}
Hide Show 9 lines of Pod
sub
LLB_west {
my
(
$self
,
$data
) =
@_
;
return
$data
?
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'west'
}=
$data
:
$self
->{data}->{
'ExtendedData'
}->{
'LatLonBox'
}->{
'west'
} ;
}
Hide Show 8 lines of Pod
sub
toJSON {
my
$self
=
shift
;
return
JSON::Syck::Dump(
$self
->{
'data'
}) ;
}
Hide Show 10 lines of Pod
sub
toKML {
sub
_toKMLinternal {
my
$self
=
shift
;
my
$document
=
shift
;
my
$xml_element
=
shift
;
my
$root
=
shift
;
return
unless
(
$root
);
return
unless
(
ref
(
$root
) eq
"HASH"
);
foreach
my
$key
(
keys
(%{
$root
})){
next
if
(
$key
eq
"Accuracy"
);
my
$new_element
=
$document
->createElement(
$key
);
if
(
$self
->can(
$key
) ){
if
(
defined
(
$self
->
$key
)){
$new_element
->appendText(
$self
->
$key
);
$xml_element
->appendChild(
$new_element
);
}
}
else
{
if
(
$key
eq
'AddressDetails'
){
$new_element
->setNamespace(
"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
,
''
,0);
$new_element
->setAttribute(
'Accuracy'
,
$self
->Accuracy);
}
elsif
(
$key
eq
'LatLonBox'
){
$new_element
->setAttribute(
'north'
,
$root
->{
$key
}->{north});
$new_element
->setAttribute(
'south'
,
$root
->{
$key
}->{south});
$new_element
->setAttribute(
'east'
,
$root
->{
$key
}->{east});
$new_element
->setAttribute(
'west'
,
$root
->{
$key
}->{west});
}
$xml_element
->appendChild(
$new_element
);
_toKMLinternal(
$self
,
$document
,
$new_element
,
$root
->{
$key
})
unless
(
$key
eq
'LatLonBox'
);
}
}
}
my
$self
=
shift
;
my
$as_string
=
shift
;
my
$document
= XML::LibXML::Document->createDocument(
"1.0"
,
"UTF-8"
);
$document
->setStandalone(1);
my
$kml
=
$document
->createElement(
'kml'
);
$document
->setDocumentElement(
$kml
);
my
$placemark
=
$document
->createElement(
'Placemark'
);
$placemark
->setAttribute(
'id'
,
$self
->id);
$kml
->appendChild(
$placemark
);
my
$data
= {%{
$self
->{data}}};
delete
(
$data
->{id});
_toKMLinternal(
$self
,
$document
,
$placemark
,
$data
);
$document
->setEncoding(
"UTF-8"
);
return
$document
->toString(1)
if
(
$as_string
);
return
$document
;
}
Hide Show 6 lines of Pod
sub
toXML {
return
shift
->toKML(
@_
);
}
Hide Show 10 lines of Pod
sub
Serialize {
my
$self
=
shift
;
if
(
$self
->{output}){
return
$self
->toJSON
if
(
$self
->{output} eq
'json'
);
return
$self
->toKML(
@_
)
if
(
$self
->{output} eq
'xml'
or
$self
->{output} eq
'kml'
);
return
$self
->toJSON ;
}
else
{
return
$self
->toJSON ;
}
}
Hide Show 8 lines of Pod
sub
Serialyze {
return
Serialize(
@_
);
}
sub
_setData {
my
(
$self
,
$data
)=
@_
;
$self
->{data}=
$data
;
}
Hide Show 65 lines of Pod
1;