NAME
Wikibase::Datatype::Struct::Value::Item - Wikibase item value structure serialization.
SYNOPSIS
use Wikibase::Datatype::Struct::Value::Item qw(obj2struct struct2obj);
my $struct_hr = obj2struct($obj);
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);
Convert Wikibase::Datatype::Value::Item instance to structure.
Returns reference to hash with structure.
struct2obj
my $obj = struct2obj($struct_hr);
Convert structure of item to object.
Returns Wikibase::Datatype::Value::Item instance.
ERRORS
obj2struct():
Object doesn't exist.
Object isn't 'Wikibase::Datatype::Value::Item'.
struct2obj():
Structure isn't for 'item' datatype.
EXAMPLE1
use strict;
use warnings;
use Data::Printer;
use Wikibase::Datatype::Value::Item;
use Wikibase::Datatype::Struct::Value::Item qw(obj2struct);
# Object.
my $obj = Wikibase::Datatype::Value::Item->new(
'value' => 'Q123',
);
# Get structure.
my $struct_hr = obj2struct($obj);
# Dump to output.
p $struct_hr;
# Output:
# \ {
# type "wikibase-entityid",
# value {
# entity-type "item",
# id "Q123",
# numeric-id 123
# }
# }
EXAMPLE2
use strict;
use warnings;
use Wikibase::Datatype::Struct::Value::Item qw(struct2obj);
# Item structure.
my $struct_hr = {
'type' => 'wikibase-entityid',
'value' => {
'entity-type' => 'item',
'id' => 'Q123',
'numberic-id' => 123,
},
};
# Get object.
my $obj = struct2obj($struct_hr);
# Get value.
my $value = $obj->value;
# Get type.
my $type = $obj->type;
# Print out.
print "Type: $type\n";
print "Value: $value\n";
# Output:
# Type: item
# Value: Q123
DEPENDENCIES
Error::Pure, Exporter, Readonly, Wikibase::Datatype::Value::Item.
SEE ALSO
- Wikibase::Datatype::Struct
-
Wikibase structure serialization.
- Wikibase::Datatype::Value::Item
-
Wikibase item 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-2023 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.12