make sure all tests work in all combos, save the broken Directory deletion; POD doc...
[scpubgit/stemmatology.git] / morphology / lib / Text / Tradition / Language.pm
1 package Text::Tradition::Language;
2
3 use strict;
4 use warnings;
5 use Module::Load;
6 use Moose::Role;
7
8 requires 'throw';
9
10 =head1 NAME
11
12 Text::Tradition::Language - add-on role to enable language awareness and 
13 morphology functions to a Text::Tradition object.  Please see
14 L<Text::Tradition::Morphology> for more information on the morphology 
15 add-on distribution.
16
17 =head1 METHODS
18
19 =head2 language
20
21 Accessor for the primary language of the tradition. Must correspond to one
22 of the Text::Tradition::Language::* modules in this package.
23
24 =cut
25
26 has 'language' => (
27         is => 'rw',
28         isa => 'Str',
29         predicate => 'has_language',
30         );
31         
32 before '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
46 Calls the appropriate lemmatization function for the language of the
47 tradition.
48
49 =cut
50
51 sub 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
61 1;
62