NAME

Wikibase::Datatype::Struct::MediainfoSnak - Wikibase mediainfo snak structure serialization.

SYNOPSIS

use Wikibase::Datatype::Struct::MediainfoSnak 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::MediainfoSnak 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 mediainfo snak to object.

Returns Wikibase::Datatype::MediainfoSnak instance.

ERRORS

obj2struct():
        Base URI is required.
        Object doesn't exist.
        Object isn't 'Wikibase::Datatype::MediainfoSnak'.

EXAMPLE1

use strict;
use warnings;

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

# Object.
# instance of (P31) human (Q5)
my $obj = Wikibase::Datatype::MediainfoSnak->new(
         'datavalue' => Wikibase::Datatype::Value::Item->new(
                 'value' => 'Q5',
         ),
         'property' => 'P31',
);

# Get structure.
my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/');

# Dump to output.
p $struct_hr;

# Output:
# \ {
#     datavalue   {
#         type    "wikibase-entityid",
#         value   {
#             entity-type   "item",
#             id            "Q5",
#             numeric-id    5
#         }
#     },
#     property    "P31",
#     snaktype    "value"
# }

EXAMPLE2

use strict;
use warnings;

use Wikibase::Datatype::Struct::MediainfoSnak qw(struct2obj);

# Item structure.
my $struct_hr = {
        'datavalue' => {
                'type' => 'wikibase-entityid',
                'value' => {
                        'entity-type' => 'item',
                        'id' => 'Q5',
                        'numeric-id' => 5,
                },
        },
        'property' => 'P31',
        'snaktype' => 'value',
};

# Get object.
my $obj = struct2obj($struct_hr);

# Get value.
my $datavalue = $obj->datavalue->value;

# Get property.
my $property = $obj->property;

# Get snak type.
my $snaktype = $obj->snaktype;

# Print out.
print "Property: $property\n";
print "Value: $datavalue\n";
print "Snak type: $snaktype\n";

# Output:
# Property: P31
# Value: Q5
# Snak type: value

DEPENDENCIES

Error::Pure, Exporter, Readonly, Wikibase::Datatype::MediainfoSnak, Wikibase::Datatype::Struct::Value.

SEE ALSO

Wikibase::Datatype::Struct

Wikibase structure serialization.

Wikibase::Datatype::Struct::Snak

Wikibase snak structure serialization.

Wikibase::Datatype::Snak

Wikibase snak 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-2023 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.12