Wikibase::Datatype::Struct::Value::Quantity - Wikibase quantity structure serialization.
use Wikibase::Datatype::Struct::Value::Quantity 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::Quantity 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 quantity to object.
Returns Wikibase::Datatype::Value::Quantity instance.
obj2struct(): Base URI is required. Object doesn't exist. Object isn't 'Wikibase::Datatype::Value::Quantity'. struct2obj(): Structure isn't for 'quantity' datatype.
use strict; use warnings; use Data::Printer; use Wikibase::Datatype::Value::Quantity; use Wikibase::Datatype::Struct::Value::Quantity qw(obj2struct); # Object. my $obj = Wikibase::Datatype::Value::Quantity->new( 'unit' => 'Q190900', 'value' => 10, ); # Get structure. my $struct_hr = obj2struct($obj, 'http://test.wikidata.org/entity/'); # Dump to output. p $struct_hr; # Output: # \ { # type "quantity", # value { # amount "+10", # unit "http://test.wikidata.org/entity/Q190900" # } # }
use strict; use warnings; use Wikibase::Datatype::Struct::Value::Quantity qw(struct2obj); # Quantity structure. my $struct_hr = { 'type' => 'quantity', 'value' => { 'amount' => '+10', 'unit' => 'http://test.wikidata.org/entity/Q190900', }, }; # Get object. my $obj = struct2obj($struct_hr); # Get type. my $type = $obj->type; # Get unit. my $unit = $obj->unit; # Get value. my $value = $obj->value; # Print out. print "Type: $type\n"; if (defined $unit) { print "Unit: $unit\n"; } print "Value: $value\n"; # Output: # Type: quantity # Unit: Q190900 # Value: 10
Error::Pure, Exporter, Readonly, URI, Wikibase::Datatype::Value::Property.
Wikibase structure serialization.
Wikibase quantity value datatype.
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© Michal Josef Špaček 2020-2021
BSD 2-Clause License
0.07
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.