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

NAME

Wikibase::Datatype::Struct::Value::String - Wikibase string structure serialization.

SYNOPSIS

 use Wikibase::Datatype::Struct::Value::String qw(obj2struct struct2obj);

 my $struct_hr = obj2struct($obj);
 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);

Convert Wikibase::Datatype::Value::String instance to structure.

Returns reference to hash with structure.

struct2obj

 my $obj = struct2obj($struct_hr);

Convert structure of string to object.

Returns Wikibase::Datatype::Value::String instance.

ERRORS

 obj2struct():
         Object isn't 'Wikibase::Datatype::Value::String'.

 struct2obj():
         Structure isn't for 'string' datatype.

EXAMPLE1

 use strict;
 use warnings;

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

 # Object.
 my $obj = Wikibase::Datatype::Value::String->new(
         'value' => 'foo',
 );

 # Get structure.
 my $struct_hr = obj2struct($obj);

 # Dump to output.
 p $struct_hr;

 # Output:
 # \ {
 #     type    "string",
 #     value   "foo"
 # }

EXAMPLE2

 use strict;
 use warnings;

 use Wikibase::Datatype::Struct::Value::String qw(struct2obj);

 # String structure.
 my $struct_hr = {
         'type' => 'string',
         'value' => 'foo',
 };

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

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

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

 # Print out.
 print "Type: $type\n";
 print "Value: $value\n";

 # Output:
 # Type: string
 # Value: foo

DEPENDENCIES

Error::Pure, Exporter, Readonly, Wikibase::Datatype::Value::String.

SEE ALSO

Wikibase::Datatype::Struct

Wikibase structure serialization.

Wikibase::Datatype::Value::String

Wikibase string value 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

© Michal Josef Špaček 2020

BSD 2-Clause License

VERSION

0.01