split tradition language into morphology module; add license blurb to morphology...
[scpubgit/stemmatology.git] / morphology / lib / Text / Tradition / Language.pm
1 package Text::Tradition::Language;
2
3 use strict;
4 use warnings;
5 use Moose::Role;
6
7 =head1 NAME
8
9 Text::Tradition::Language - add-on role to enable language awareness and 
10 morphology functions to a Text::Tradition object.  See also 
11 L<Text::Tradition::Morphology> for individual reading morphologies.
12
13 =head1 METHODS
14
15 =head2 language
16
17 Accessor for the primary language of the tradition. Must correspond to one
18 of the Text::Tradition::Language::* modules in this package.
19
20 =cut
21
22 has 'language' => (
23         is => 'rw',
24         isa => 'Str',
25         predicate => 'has_language',
26         );
27         
28 before 'language' => sub {
29         my $self = shift;
30         if( @_ && $_[0] ne 'Default' ) {
31                 # We are trying to set the language; check that the corresponding
32                 # module exists.
33                 eval "require Text::Tradition::Language::".$_[0];
34                 if( $@ ) {
35                         throw( "Cannot load language module for @_: $@" );
36                 }
37         }
38 };
39     
40 =head2 lemmatize
41
42 Calls the appropriate lemmatization function for the language of the
43 tradition.
44
45 =cut
46
47 sub lemmatize {
48         my $self = shift;
49         unless( $self->has_language ) {
50                 throw( "Please set a language to lemmatize a tradition" );
51         }
52         my $mod = "Text::Tradition::Language::" . $self->language;
53         load( $mod );
54         $mod->can( 'lemmatize' )->( $self );
55 }
56
57 1;
58
59 =head1 LICENSE
60
61 This package is free software and is provided "as is" without express
62 or implied warranty.  You can redistribute it and/or modify it under
63 the same terms as Perl itself.
64
65 =head1 AUTHOR
66
67 Tara L Andrews E<lt>aurum@cpan.orgE<gt>