The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Wikibase::Datatype::Struct::MediainfoStatement - Wikibase mediainfo statement structure serialization.

SYNOPSIS

 use Wikibase::Datatype::Struct::MediainfoStatement 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::MediainfoStatement 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 statement to object.

Returns Wikibase::Datatype::MediainfoStatement instance.

ERRORS

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

EXAMPLE1

 use strict;
 use warnings;

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

 # Object.
 my $obj = Wikibase::Datatype::MediainfoStatement->new(
         'id' => 'M123$00C04D2A-49AF-40C2-9930-C551916887E8',

         # instance of (P31) human (Q5)
         'snak' => Wikibase::Datatype::MediainfoSnak->new(
                  'datavalue' => Wikibase::Datatype::Value::Item->new(
                          'value' => 'Q5',
                  ),
                  'property' => 'P31',
         ),
         'property_snaks' => [
                 # of (P642) alien (Q474741)
                 Wikibase::Datatype::MediainfoSnak->new(
                          'datavalue' => Wikibase::Datatype::Value::Item->new(
                                  'value' => 'Q474741',
                          ),
                          'property' => 'P642',
                 ),
         ],
 );

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

 # Dump to output.
 p $struct_hr;

 # Output:
 # \ {
 #     id                 "M123$00C04D2A-49AF-40C2-9930-C551916887E8",
 #     mainsnak           {
 #         datavalue   {
 #             type    "wikibase-entityid",
 #             value   {
 #                 entity-type   "item",
 #                 id            "Q5",
 #                 numeric-id    5
 #             }
 #         },
 #         property    "P31",
 #         snaktype    "value"
 #     },
 #     qualifiers         {
 #         P642   [
 #             [0] {
 #                 datavalue   {
 #                     type    "wikibase-entityid",
 #                     value   {
 #                         entity-type   "item",
 #                         id            "Q474741",
 #                         numeric-id    474741
 #                     }
 #                 },
 #                 property    "P642",
 #                 snaktype    "value"
 #             }
 #         ]
 #     },
 #     qualifiers-order   [
 #         [0] "P642"
 #     ],
 #     rank               "normal",
 #     type               "statement"
 # }

EXAMPLE2

 use strict;
 use warnings;

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

 # Item structure.
 my $struct_hr = {
         'id' => 'M123$00C04D2A-49AF-40C2-9930-C551916887E8',
         'mainsnak' => {
                 'datavalue' => {
                         'type' => 'wikibase-entityid',
                         'value' => {
                                 'entity-type' => 'item',
                                 'id' => 'Q5',
                                 'numeric-id' => 5,
                         },
                 },
                 'property' => 'P31',
                 'snaktype' => 'value',
         },
         'qualifiers' => {
                 'P642' => [{
                         'datavalue' => {
                                 'type' => 'wikibase-entityid',
                                 'value' => {
                                         'entity-type' => 'item',
                                         'id' => 'Q474741',
                                         'numeric-id' => 474741,
                                 },
                         },
                         'property' => 'P642',
                         'snaktype' => 'value',
                 }],
         },
         'qualifiers-order' => [
                 'P642',
         ],
         'rank' => 'normal',
         'type' => 'statement',
 };

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

 # Print out.
 print 'Id: '.$obj->id."\n";
 print 'Statements: '.$obj->snak->property.' -> '.$obj->snak->datavalue->value."\n";
 print "Qualifiers:\n";
 foreach my $property_snak (@{$obj->property_snaks}) {
         print "\t".$property_snak->property.' -> '.
                 $property_snak->datavalue->value."\n";
 }
 print 'Rank: '.$obj->rank."\n";

 # Output:
 # Id: M123$00C04D2A-49AF-40C2-9930-C551916887E8
 # Statements: P31 -> Q5
 # Qualifiers:
 #         P642 -> Q474741
 # Rank: normal

DEPENDENCIES

Error::Pure, Exporter, Readonly, Wikibase::Datatype::MediainfoStatement, Wikibase::Datatype::Struct::Snak, Wikibase::Datatype::Struct::Utils.

SEE ALSO

Wikibase::Datatype::Struct

Wikibase structure serialization.

Wikibase::Datatype::Statement

Wikibase statement datatype.

Wikibase::Datatype::MediainfoStatement

Wikibase mediainfo statement 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