Wikibase::Datatype::Struct::MediainfoStatement - Wikibase mediainfo statement structure serialization.
use Wikibase::Datatype::Struct::MediainfoStatement qw(obj2struct struct2obj); my $struct_hr = obj2struct($obj, $base_uri); my $obj = struct2obj($struct_hr);
This conversion is between objects defined in Wikibase::Datatype and structures serialized via JSON to MediaWiki.
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/).
$base_uri
Returns reference to hash with structure.
struct2obj
my $obj = struct2obj($struct_hr);
Convert structure of mediainfo statement to object.
Returns Wikibase::Datatype::MediainfoStatement instance.
obj2struct(): Base URI is required. Object doesn't exist. Object isn't 'Wikibase::Datatype::MediainfoStatement'.
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" # }
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
Error::Pure, Exporter, Readonly, Wikibase::Datatype::MediainfoStatement, Wikibase::Datatype::Struct::Reference, Wikibase::Datatype::Struct::Snak, Wikibase::Datatype::Struct::Utils.
Wikibase structure serialization.
Wikibase statement datatype.
Wikibase mediainfo statement datatype.
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2020-2023 Michal Josef Špaček
BSD 2-Clause License
0.12
To install Wikibase::Datatype::Struct, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Wikibase::Datatype::Struct
CPAN shell
perl -MCPAN -e shell install Wikibase::Datatype::Struct
For more information on module installation, please visit the detailed CPAN module installation guide.