NAME

Wikibase::Datatype::Struct::Value::Monolingual - Wikibase monolingual value structure serialization.

SYNOPSIS

use Wikibase::Datatype::Struct::Value::Monolingual 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::Monolingual instance to structure.

Returns reference to hash with structure.

struct2obj

my $obj = struct2obj($struct_hr);

Convert structure of monolingual to object.

Returns Wikibase::Datatype::Value::Monolingual instance.

ERRORS

obj2struct():
        Object doesn't exist.
        Object isn't 'Wikibase::Datatype::Value::Monolingual'.

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

EXAMPLE1

use strict;
use warnings;

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

# Object.
my $obj = Wikibase::Datatype::Value::Monolingual->new(
        'language' => 'en',
        'value' => 'English text',
);

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

# Dump to output.
p $struct_hr;

# Output:
# \ {
#     type    "monolingualtext",
#     value   {
#         language   "en",
#         text       "English text"
#     }
# }

EXAMPLE2

use strict;
use warnings;

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

# Monolingualtext structure.
my $struct_hr = {
        'type' => 'monolingualtext',
        'value' => {
                'language' => 'en',
                'text' => 'English text',
        },
};

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

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

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

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

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

# Output:
# Language: en
# Type: monolingualtext
# Value: English text

DEPENDENCIES

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

SEE ALSO

Wikibase::Datatype::Struct

Wikibase structure serialization.

Wikibase::Datatype::Value::Monolingual

Wikibase monolingual 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

© 2020-2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.13