Wikibase::Datatype::Struct::Value - Wikibase value structure serialization.
use Wikibase::Datatype::Struct::Value 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::Value 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 value to object.
Returns Wikibase::Datatype::Value instance.
obj2struct(): Object doesn't exist. Object isn't 'Wikibase::Datatype::Value'. Type '%s' is unsupported. struct2obj(): Entity type '%s' is unsupported. Type doesn't exist. Type '%s' is unsupported.
use strict; use warnings; use Data::Printer; use Wikibase::Datatype::Value::Time; use Wikibase::Datatype::Struct::Value qw(obj2struct); # Object. my $obj = Wikibase::Datatype::Value::Time->new( 'precision' => 10, 'value' => '+2020-09-01T00:00:00Z', ); # Get structure. my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); # Dump to output. p $struct_hr; # Output: # \ { # type "time", # value { # after 0, # before 0, # calendarmodel "http://test.wikidata.org/entity/Q1985727", # precision 10, # time "+2020-09-01T00:00:00Z", # timezone 0 # } # }
use strict; use warnings; use Wikibase::Datatype::Struct::Value qw(struct2obj); # Time structure. my $struct_hr = { 'type' => 'time', 'value' => { 'after' => 0, 'before' => 0, 'calendarmodel' => 'http://test.wikidata.org/entity/Q1985727', 'precision' => 10, 'time' => '+2020-09-01T00:00:00Z', 'timezone' => 0, }, }; # Get object. my $obj = struct2obj($struct_hr); # Get calendar model. my $calendarmodel = $obj->calendarmodel; # Get precision. my $precision = $obj->precision; # Get type. my $type = $obj->type; # Get value. my $value = $obj->value; # Print out. print "Calendar model: $calendarmodel\n"; print "Precision: $precision\n"; print "Type: $type\n"; print "Value: $value\n"; # Output: # Calendar model: Q1985727 # Precision: 10 # Type: time # Value: +2020-09-01T00:00:00Z
Error::Pure, Exporter, Readonly, Wikibase::Datatype::Value, Wikibase::Datatype::Struct::Value::Globecoordinate, Wikibase::Datatype::Struct::Value::Item, Wikibase::Datatype::Struct::Value::Monolingual, Wikibase::Datatype::Struct::Value::Property, Wikibase::Datatype::Struct::Value::Quantity, Wikibase::Datatype::Struct::Value::String, Wikibase::Datatype::Struct::Value::Time.
Wikibase structure serialization.
Wikibase globe coordinate value datatype.
Wikibase item value datatype.
Wikibase monolingual value datatype.
Wikibase property value datatype.
Wikibase quantity value datatype.
Wikibase string value datatype.
Wikibase time value datatype.
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© 2020-2022 Michal Josef Špaček
BSD 2-Clause License
0.09
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.