make sure all tests work in all combos, save the broken Directory deletion; POD doc...
[scpubgit/stemmatology.git] / morphology / lib / Text / Tradition / Language.pm
CommitLineData
e92d4229 1package Text::Tradition::Language;
2
3use strict;
4use warnings;
332750fc 5use Module::Load;
e92d4229 6use Moose::Role;
7
332750fc 8requires 'throw';
9
e92d4229 10=head1 NAME
11
12Text::Tradition::Language - add-on role to enable language awareness and
8943ff68 13morphology functions to a Text::Tradition object. Please see
14L<Text::Tradition::Morphology> for more information on the morphology
15add-on distribution.
e92d4229 16
17=head1 METHODS
18
19=head2 language
20
21Accessor for the primary language of the tradition. Must correspond to one
22of the Text::Tradition::Language::* modules in this package.
23
24=cut
25
26has 'language' => (
27 is => 'rw',
28 isa => 'Str',
29 predicate => 'has_language',
30 );
31
32before 'language' => sub {
33 my $self = shift;
34 if( @_ && $_[0] ne 'Default' ) {
35 # We are trying to set the language; check that the corresponding
36 # module exists.
37 eval "require Text::Tradition::Language::".$_[0];
38 if( $@ ) {
39 throw( "Cannot load language module for @_: $@" );
40 }
41 }
42};
43
44=head2 lemmatize
45
46Calls the appropriate lemmatization function for the language of the
47tradition.
48
49=cut
50
51sub lemmatize {
52 my $self = shift;
53 unless( $self->has_language ) {
54 throw( "Please set a language to lemmatize a tradition" );
55 }
56 my $mod = "Text::Tradition::Language::" . $self->language;
57 load( $mod );
58 $mod->can( 'lemmatize' )->( $self );
59}
60
611;
62