Skip to content

Commit

Permalink
Add Wikibase::Datatype::Value::Lexeme
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-josef-spacek committed Oct 27, 2023
1 parent 7bd94bf commit 983a643
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.32
- Add Wikibase::Datatype::Value::Lexeme.
- Add fixtures for statement of given name with Michal value.
- Add missing Sense to Value doc.
- Improve doc comments.
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ lib/Wikibase/Datatype/Utils.pm
lib/Wikibase/Datatype/Value.pm
lib/Wikibase/Datatype/Value/Globecoordinate.pm
lib/Wikibase/Datatype/Value/Item.pm
lib/Wikibase/Datatype/Value/Lexeme.pm
lib/Wikibase/Datatype/Value/Monolingual.pm
lib/Wikibase/Datatype/Value/Property.pm
lib/Wikibase/Datatype/Value/Quantity.pm
Expand Down Expand Up @@ -423,6 +424,11 @@ t/Wikibase-Datatype-Value-Item/02-version.t
t/Wikibase-Datatype-Value-Item/03-new.t
t/Wikibase-Datatype-Value-Item/04-type.t
t/Wikibase-Datatype-Value-Item/05-value.t
t/Wikibase-Datatype-Value-Lexeme/01-use.t
t/Wikibase-Datatype-Value-Lexeme/02-version.t
t/Wikibase-Datatype-Value-Lexeme/03-new.t
t/Wikibase-Datatype-Value-Lexeme/04-type.t
t/Wikibase-Datatype-Value-Lexeme/05-value.t
t/Wikibase-Datatype-Value-Monolingual/01-use.t
t/Wikibase-Datatype-Value-Monolingual/02-version.t
t/Wikibase-Datatype-Value-Monolingual/03-new.t
Expand Down Expand Up @@ -591,6 +597,8 @@ xt/Wikibase-Datatype-Value-Globecoordinate/01-pod_coverage.t
xt/Wikibase-Datatype-Value-Globecoordinate/02-pod.t
xt/Wikibase-Datatype-Value-Item/01-pod_coverage.t
xt/Wikibase-Datatype-Value-Item/02-pod.t
xt/Wikibase-Datatype-Value-Lexeme/01-pod_coverage.t
xt/Wikibase-Datatype-Value-Lexeme/02-pod.t
xt/Wikibase-Datatype-Value-Monolingual/01-pod_coverage.t
xt/Wikibase-Datatype-Value-Monolingual/02-pod.t
xt/Wikibase-Datatype-Value-Property/01-pod_coverage.t
Expand Down
3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ TODO
62. Add multiple values to Item.
63. Add MediainfoStatement with reference and qualifiers
Example: https://commons.wikimedia.org/wiki/File:Middelburg_(NL),_Bevrijdingsmonument_--_2022_--_4907.jpg
64.
64. Add lexeme value to some fixture (like Q1246129)
65.

Applied
=======
Expand Down
2 changes: 2 additions & 0 deletions lib/Wikibase/Datatype/Snak.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Readonly::Hash our %DATA_TYPES => (
'time' => 'Wikibase::Datatype::Value::Time',
'url' => 'Wikibase::Datatype::Value::String',
'wikibase-item' => 'Wikibase::Datatype::Value::Item',
'wikibase-lexeme' => 'Wikibase::Datatype::Value::Lexeme',
'wikibase-property' => 'Wikibase::Datatype::Value::Property',
'wikibase-sense' => 'Wikibase::Datatype::Value::Sense',
);
Expand Down Expand Up @@ -144,6 +145,7 @@ Parameter is required.
- time (Wikibase::Datatype::Value::Time)
- url (Wikibase::Datatype::Value::String)
- wikibase-item (Wikibase::Datatype::Value::Item)
- wikibase-lexeme (Wikibase::Datatype::Value::Lexeme)
- wikibase-property (Wikibase::Datatype::Value::Property)
- wikibase-sense (Wikibase::Datatype::Value::Sense)
Expand Down
158 changes: 158 additions & 0 deletions lib/Wikibase/Datatype/Value/Lexeme.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package Wikibase::Datatype::Value::Lexeme;

use strict;
use warnings;

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

our $VERSION = 0.32;

extends 'Wikibase::Datatype::Value';

sub type {
return 'lexeme';
}

sub BUILD {
my $self = shift;

check_lexeme($self, 'value');

return;
}

1;

__END__
=pod
=encoding utf8
=head1 NAME
Wikibase::Datatype::Value::Lexeme - Wikibase lexeme value datatype.
=head1 SYNOPSIS
use Wikibase::Datatype::Value::Lexeme;
my $obj = Wikibase::Datatype::Value::Lexeme->new(%params);
my $type = $obj->type;
my $value = $obj->value;
=head1 DESCRIPTION
This datatype is item class for representation of wikibase lexeme (e.g. L42284).
=head1 METHODS
=head2 C<new>
my $obj = Wikibase::Datatype::Value::Lexeme->new(%params);
Constructor.
Returns instance of object.
=over 8
=item * C<value>
Value of instance.
Parameter must be in form /^L\d+$/ (regexp).
Parameter is required.
=back
=head2 C<type>
my $type = $obj->type;
Get type. This is constant 'item'.
Returns string.
=head2 C<value>
my $value = $obj->value;
Get value.
Returns string.
=head1 ERRORS
new():
From Wikibase::Datatype::Utils::check_entity():
Parameter 'value' must begin with 'Q' and number after it.
From Wikibase::Datatype::Value::new():
Parameter 'value' is required.
=head1 EXAMPLE
=for comment filename=create_and_print_value_lexeme.pl
use strict;
use warnings;
use Wikibase::Datatype::Value::Lexeme;
# Object.
my $obj = Wikibase::Datatype::Value::Lexeme->new(
'value' => 'L42284',
);
# Get value.
my $value = $obj->value;
# Get type.
my $type = $obj->type;
# Print out.
print "Type: $type\n";
print "Value: $value\n";
# Output:
# Type: item
# Value: L42284
=head1 DEPENDENCIES
L<Error::Pure>,
L<Mo>,
L<Wikibase::Datatype::Utils>,
L<Wikibase::Datatype::Value>.
=head1 SEE ALSO
=over
=item L<Wikibase::Datatype::Value>
Wikibase datatypes.
=back
=head1 REPOSITORY
L<https://github.com/michal-josef-spacek/Wikibase-Datatype>
=head1 AUTHOR
Michal Josef Špaček L<mailto:skim@cpan.org>
L<http://skim.cz>
=head1 LICENSE AND COPYRIGHT
© 2020-2023 Michal Josef Špaček
BSD 2-Clause License
=head1 VERSION
0.32
=cut
14 changes: 14 additions & 0 deletions t/Wikibase-Datatype-Value-Lexeme/01-use.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use strict;
use warnings;

use Test::More 'tests' => 3;
use Test::NoWarnings;

BEGIN {

# Test.
use_ok('Wikibase::Datatype::Value::Lexeme');
}

# Test.
require_ok('Wikibase::Datatype::Value::Lexeme');
9 changes: 9 additions & 0 deletions t/Wikibase-Datatype-Value-Lexeme/02-version.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use strict;
use warnings;

use Test::More 'tests' => 2;
use Test::NoWarnings;
use Wikibase::Datatype::Value::Lexeme;

# Test.
is($Wikibase::Datatype::Value::Lexeme::VERSION, 0.32, 'Version.');
32 changes: 32 additions & 0 deletions t/Wikibase-Datatype-Value-Lexeme/03-new.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use strict;
use warnings;

use English;
use Error::Pure::Utils qw(clean);
use Test::More 'tests' => 4;
use Test::NoWarnings;
use Wikibase::Datatype::Value::Lexeme;

# Test.
my $obj = Wikibase::Datatype::Value::Lexeme->new(
'value' => 'L42284',
);
isa_ok($obj, 'Wikibase::Datatype::Value::Lexeme');

# Test.
eval {
Wikibase::Datatype::Value::Lexeme->new;
};
is($EVAL_ERROR, "Parameter 'value' is required.\n",
"Parameter 'value' is required.");
clean();

# Test.
eval {
Wikibase::Datatype::Value::Lexeme->new(
'value' => 'foo',
);
};
is($EVAL_ERROR, "Parameter 'value' must begin with 'L' and number after it.\n",
"Bad 'value' parameter.");
clean();
13 changes: 13 additions & 0 deletions t/Wikibase-Datatype-Value-Lexeme/04-type.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use strict;
use warnings;

use Test::More 'tests' => 2;
use Test::NoWarnings;
use Wikibase::Datatype::Value::Lexeme;

# Test.
my $obj = Wikibase::Datatype::Value::Lexeme->new(
'value' => 'L42284',
);
my $ret = $obj->type;
is($ret, 'lexeme', 'Get type().');
13 changes: 13 additions & 0 deletions t/Wikibase-Datatype-Value-Lexeme/05-value.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use strict;
use warnings;

use Test::More 'tests' => 2;
use Test::NoWarnings;
use Wikibase::Datatype::Value::Lexeme;

# Test.
my $obj = Wikibase::Datatype::Value::Lexeme->new(
'value' => 'L42284',
);
my $ret = $obj->value;
is($ret, 'L42284', 'Get value().');
10 changes: 10 additions & 0 deletions xt/Wikibase-Datatype-Value-Lexeme/01-pod_coverage.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use strict;
use warnings;

use Test::NoWarnings;
use Test::Pod::Coverage 'tests' => 2;

# Test.
pod_coverage_ok('Wikibase::Datatype::Value::Lexeme',
{ 'also_private' => ['BUILD'] },
'Wikibase::Datatype::Value::Lexeme is covered.');
16 changes: 16 additions & 0 deletions xt/Wikibase-Datatype-Value-Lexeme/02-pod.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use strict;
use warnings;

use English qw(-no_match_vars);
use File::Object;
use Test::More 'tests' => 2;
use Test::NoWarnings;

# Test.
SKIP: {
if ($PERL_VERSION lt v5.8.0) {
skip 'Perl version lesser then 5.8.0.', 1;
}
require Test::Pod;
Test::Pod::pod_file_ok(File::Object->new->up(2)->file('lib', 'Wikibase', 'Datatype', 'Value', 'Lexeme.pm')->s);
};

0 comments on commit 983a643

Please sign in to comment.