NAME
Wikibase::Datatype::Struct::Value::Quantity - Wikibase quantity value structure serialization.
SYNOPSIS
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::Quantity 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 quantity to object.
Returns Wikibase::Datatype::Value::Quantity instance.
ERRORS
obj2struct():
Base URI is required.
Object doesn't exist.
Object isn
't '
Wikibase::Datatype::Value::Quantity'.
struct2obj():
Structure isn
't for '
quantity' datatype.
EXAMPLE1
use
strict;
use
warnings;
use
Data::Printer;
# Object.
my
$obj
= Wikibase::Datatype::Value::Quantity->new(
'unit'
=>
'Q190900'
,
'value'
=> 10,
);
# Get structure.
# Dump to output.
p
$struct_hr
;
# Output:
# \ {
# type "quantity",
# value {
# amount "+10",
# }
# }
EXAMPLE2
use
strict;
use
warnings;
# Quantity structure.
my
$struct_hr
= {
'type'
=>
'quantity'
,
'value'
=> {
'amount'
=>
'+10'
,
},
};
# Get object.
my
$obj
= struct2obj(
$struct_hr
);
# Get type.
my
$type
=
$obj
->type;
# Get unit.
my
$unit
=
$obj
->unit;
# Get value.
my
$value
=
$obj
->value;
# Print out.
"Type: $type\n"
;
if
(
defined
$unit
) {
"Unit: $unit\n"
;
}
"Value: $value\n"
;
# Output:
# Type: quantity
# Unit: Q190900
# Value: 10
DEPENDENCIES
Error::Pure, Exporter, Readonly, URI, Wikibase::Datatype::Value::Property.
SEE ALSO
- Wikibase::Datatype::Struct
-
Wikibase structure serialization.
- Wikibase::Datatype::Value::Quantity
-
Wikibase quantity 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-2025 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.14