NAME

Wikibase::Datatype::Struct::Value::Property - Wikibase property structure serialization.

SYNOPSIS

 use Wikibase::Datatype::Struct::Value::Property 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::Property instance to structure.

Returns reference to hash with structure.

struct2obj

 my $obj = struct2obj($struct_hr);

Convert structure of property to object.

Returns Wikibase::Datatype::Value::Property instance.

ERRORS

 obj2struct():
         Object doesn't exist.
         Object isn't 'Wikibase::Datatype::Value::Property'.

 struct2obj():
         Structure isn't for 'property' datatype.

EXAMPLE1

 use strict;
 use warnings;

 use Data::Printer;
 use Wikibase::Datatype::Value::Property;
 use Wikibase::Datatype::Struct::Value::Property qw(obj2struct);

 # Object.
 my $obj = Wikibase::Datatype::Value::Property->new(
         'value' => 'P123',
 );

 # Get structure.
 my $struct_hr = obj2struct($obj);

 # Dump to output.
 p $struct_hr;

 # Output:
 # \ {
 #     type    "wikibase-entityid",
 #     value   {
 #         entity-type   "property",
 #         id            "P123",
 #         numeric-id    123
 #     }
 # }

EXAMPLE2

 use strict;
 use warnings;

 use Wikibase::Datatype::Struct::Value::Property qw(struct2obj);

 # Property structure.
 my $struct_hr = {
         'type' => 'wikibase-entityid',
         'value' => {
                 'entity-type' => 'property',
                 'id' => 'P123',
                 'numeric-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: property
 # Value: P123

DEPENDENCIES

Error::Pure, Exporter, Readonly, Wikibase::Datatype::Value::Property.

SEE ALSO

Wikibase::Datatype::Struct

Wikibase structure serialization.

Wikibase::Datatype::Value::Property

Wikibase property value datatype.

REPOSITORY

https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2020-2022 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.09