NAME

Wikibase::Datatype::Utils - Wikibase datatype utilities.

SYNOPSIS

use Wikibase::Datatype::Utils qw(check_datetime check_entity check_language check_lexeme check_property check_sense);

check_datetime($self, $key);
check_entity($self, $key);
check_language($self, $key);
check_lexeme($self, $key);
check_property($self, $key);
check_sense($self, $key);

DESCRIPTION

Datatype utilities for checking of data objects.

SUBROUTINES

check_datetime

check_datetime($self, $key);

Check parameter defined by $key if it's datetime for Wikibase. Format of value is variation of ISO 8601 with some changes (like 00 as valid month).

Returns undef.

check_entity

check_entity($self, $key);

Check parameter defined by $key if it's entity (/^Q\d+/).

Returns undef.

check_language

check_language($self, $key);

Check parameter defined by $key if it's ISO 639-1 language code and if language exists.

Returns undef.

check_lexeme

check_lexeme($self, $key);

Check parameter defined by $key if it's entity (/^L\d+/).

Returns undef.

check_property

check_property($self, $key);

Check parameter defined by $key if it's property (/^P\d+/).

Returns undef.

check_sense

check_sense($self, $key);

Check parameter defined by $key if it's property (/^L\d+\-S\d+$/).

Returns undef.

ERRORS

check_datetime():
        Parameter '%s' has bad date time.
                Value: %s
        Parameter '%s' has bad date time day value.
                Value: %s
        Parameter '%s' has bad date time hour value.
                Value: %s
        Parameter '%s' has bad date time minute value.
                Value: %s
        Parameter '%s' has bad date time month value.
                Value: %s
        Parameter '%s' has bad date time second value.
                Value: %s

check_entity():
        Parameter '%s' must begin with 'Q' and number after it.";

check_language():
        Language code '%s' isn't ISO 639-1 code.
        Language with ISO 639-1 code '%s' doesn't exist.

check_lexeme():
        Parameter '%s' must begin with 'L' and number after it.";

check_property():
        Parameter '%s' must begin with 'P' and number after it.";

check_sense():
        Parameter '%s' must begin with 'L' and number, dash, S and number after it.

EXAMPLE1

use strict;
use warnings;

use Wikibase::Datatype::Utils qw(check_datetime);

my $self = {
        'key' => '+0134-11-00T00:00:00Z',
        'precision' => 10
};
check_datetime($self, 'key');

# Print out.
print "ok\n";

# Output:
# ok

EXAMPLE2

use strict;
use warnings;

use Wikibase::Datatype::Utils qw(check_datetime);

$Error::Pure::TYPE = 'Error';

my $self = {
        'key' => '+0134-34-00T00:01:00Z',
};
check_datetime($self, 'key');

# Print out.
print "ok\n";

# Output:
# #Error [/../Wikibase/Datatype/Utils.pm:?] Parameter 'key' has bad date time month value.

EXAMPLE3

use strict;
use warnings;

use Wikibase::Datatype::Utils qw(check_entity);

my $self = {
        'key' => 'Q123',
};
check_entity($self, 'key');

# Print out.
print "ok\n";

# Output:
# ok

EXAMPLE4

use strict;
use warnings;

use Error::Pure;
use Wikibase::Datatype::Utils qw(check_entity);

$Error::Pure::TYPE = 'Error';

my $self = {
        'key' => 'bad_entity',
};
check_entity($self, 'key');

# Print out.
print "ok\n";

# Output like:
# #Error [/../Wikibase/Datatype/Utils.pm:?] Parameter 'key' must begin with 'Q' and number after it.

EXAMPLE5

use strict;
use warnings;

use Wikibase::Datatype::Utils qw(check_lexeme);

my $self = {
        'key' => 'L123',
};
check_lexeme($self, 'key');

# Print out.
print "ok\n";

# Output:
# ok

EXAMPLE6

use strict;
use warnings;

use Error::Pure;
use Wikibase::Datatype::Utils qw(check_lexeme);

$Error::Pure::TYPE = 'Error';

my $self = {
        'key' => 'bad_entity',
};
check_lexeme($self, 'key');

# Print out.
print "ok\n";

# Output like:
# #Error [/../Wikibase/Datatype/Utils.pm:?] Parameter 'key' must begin with 'L' and number after it.

EXAMPLE7

use strict;
use warnings;

use Wikibase::Datatype::Utils qw(check_property);

my $self = {
        'key' => 'P123',
};
check_property($self, 'key');

# Print out.
print "ok\n";

# Output:
# ok

EXAMPLE8

use strict;
use warnings;

use Error::Pure;
use Wikibase::Datatype::Utils qw(check_property);

$Error::Pure::TYPE = 'Error';

my $self = {
        'key' => 'bad_property',
};
check_property($self, 'key');

# Print out.
print "ok\n";

# Output like:
# #Error [/../Wikibase/Datatype/Utils.pm:?] Parameter 'key' must begin with 'P' and number after it.

EXAMPLE9

use strict;
use warnings;

use Wikibase::Datatype::Utils qw(check_sense);

my $self = {
        'key' => 'L34727-S1',
};
check_sense($self, 'key');

# Print out.
print "ok\n";

# Output:
# ok

EXAMPLE10

use strict;
use warnings;

use Error::Pure;
use Wikibase::Datatype::Utils qw(check_sense);

$Error::Pure::TYPE = 'Error';

my $self = {
        'key' => 'bad_sense',
};
check_sense($self, 'key');

# Print out.
print "ok\n";

# Output like:
# #Error [/../Wikibase/Datatype/Utils.pm:?] Parameter 'key' must begin with 'L' and number, dash, S and number after it.

DEPENDENCIES

DateTime, Exporter, Error::Pure, List::Util, Readonly.

SEE ALSO

Wikibase::Datatype

Wikibase datatypes.

Mo::utils

Mo utilities.

Mo::utils::Language

Mo language utilities.

REPOSITORY

https://github.com/michal-josef-spacek/Wikibase-Datatype

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2020-2023 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.33