NAME

Wikibase::Datatype::Struct::Sitelink - Wikibase sitelink structure serialization.

SYNOPSIS

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

Returns reference to hash with structure.

struct2obj

my $obj = struct2obj($struct_hr);

Convert structure of sitelink to object.

Returns Wikibase::Datatype::Sitelink instance.

ERRORS

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

EXAMPLE1

use strict;
use warnings;

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

# Object.
my $obj = Wikibase::Datatype::Sitelink->new(
        'site' => 'enwiki',
        'title' => 'Main page',
);

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

# Dump to output.
p $struct_hr;

# Output:
# \ {
#     badges   [],
#     site     "enwiki",
#     title    "Main page"
# }

EXAMPLE2

use strict;
use warnings;

use Wikibase::Datatype::Struct::Sitelink qw(struct2obj);

# Item structure.
my $struct_hr = {
        'badges' => [],
        'site' => 'enwiki',
        'title' => 'Main page',
};

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

# Get badges.
my $badges_ar = [map { $_->value } @{$obj->badges}];

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

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

# Print out.
print 'Badges: '.(join ', ', @{$badges_ar})."\n";
print "Site: $site\n";
print "Title: $title\n";

# Output:
# Badges:
# Site: enwiki
# Title: Main page

DEPENDENCIES

Error::Pure, Exporter, Readonly, Wikibase::Datatype::Sitelink, Wikibase::Datatype::Value::Item.

SEE ALSO

Wikibase::Datatype::Struct

Wikibase structure serialization.

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