NAME
Wikibase::Datatype::Struct::Value::Globecoordinate - Wikibase globe coordinate value structure serialization.
SYNOPSIS
use Wikibase::Datatype::Struct::Value::Globecoordinate qw(obj2struct struct2obj);
my $struct_hr = obj2struct($obj, $base_uri);
my $obj = struct2obj($struct_hr);
DESCRIPTION
This conversion is between objects defined in Wikibase::Datatype and structures serialized via JSON to MediaWiki.
SUBROUTINES
obj2struct
my $struct_hr = obj2struct($obj, $base_uri);
Convert Wikibase::Datatype::Value::Globecoordinate instance to structure. $base_uri
is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/).
Returns reference to hash with structure.
struct2obj
my $obj = struct2obj($struct_hr);
Convert structure of globe coordinate to object.
Returns Wikibase::Datatype::Value::Globecoordinate instance.
ERRORS
obj2struct():
Base URI is required.
Object doesn't exist.
Object isn't 'Wikibase::Datatype::Value::Globecoordinate'.
struct2obj():
Structure isn't for 'globecoordinate' datatype.
EXAMPLE1
use strict;
use warnings;
use Data::Printer;
use Wikibase::Datatype::Value::Globecoordinate;
use Wikibase::Datatype::Struct::Value::Globecoordinate qw(obj2struct);
# Object.
my $obj = Wikibase::Datatype::Value::Globecoordinate->new(
'value' => [49.6398383, 18.1484031],
);
# Get structure.
my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/');
# Dump to output.
p $struct_hr;
# Output:
# \ {
# type "globecoordinate",
# value {
# altitude "null",
# globe "http://test.wikidata.org/entity/Q2",
# latitude 49.6398383,
# longitude 18.1484031,
# precision 1e-07
# }
# }
EXAMPLE2
use strict;
use warnings;
use Wikibase::Datatype::Struct::Value::Globecoordinate qw(struct2obj);
# Globe coordinate structure.
my $struct_hr = {
'type' => 'globecoordinate',
'value' => {
'altitude' => 'null',
'globe' => 'http://test.wikidata.org/entity/Q2',
'latitude' => 49.6398383,
'longitude' => 18.1484031,
'precision' => 1e-07,
},
};
# Get object.
my $obj = struct2obj($struct_hr);
# Get globe.
my $globe = $obj->globe;
# Get longitude.
my $longitude = $obj->longitude;
# Get latitude.
my $latitude = $obj->latitude;
# Get precision.
my $precision = $obj->precision;
# Get type.
my $type = $obj->type;
# Get value.
my $value_ar = $obj->value;
# Print out.
print "Globe: $globe\n";
print "Latitude: $latitude\n";
print "Longitude: $longitude\n";
print "Precision: $precision\n";
print "Type: $type\n";
print 'Value: '.(join ', ', @{$value_ar})."\n";
# Output:
# Globe: Q2
# Latitude: 49.6398383
# Longitude: 18.1484031
# Precision: 1e-07
# Type: globecoordinate
# Value: 49.6398383, 18.1484031
DEPENDENCIES
Error::Pure, Exporter, Readonly, URI, Wikibase::Datatype::Value::Globecoordinate.
SEE ALSO
- Wikibase::Datatype::Struct
-
Wikibase structure serialization.
- Wikibase::Datatype::Value::Globecoordinate
-
Wikibase globe coordinate value datatype.
REPOSITORY
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2020-2024 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.13