1 package Text::Tradition::Language;
13 Text::Tradition::Language - add-on role to enable language awareness and
14 morphology functions to a Text::Tradition object. Please see
15 L<Text::Tradition::Morphology> for more information on the morphology
22 Accessor for the primary language of the tradition. Must correspond to one
23 of the Text::Tradition::Language::* modules in this package.
29 use_ok( 'Text::Tradition' ); # with Language
31 # Test setting and recovering language
32 my $t = Text::Tradition->new( input => 'Self', file => 't/data/legendfrag.xml' );
33 warning_like { $t->language( 'Klingon' ); } qr/^Cannot load language/,
34 "Got expected warning for setting of unsupported language";
35 $t->language( 'English' );
36 is( $t->language, 'English', "Successfully set supported language" );
38 # Test bad attempt to lemmatize - proper lemmatization is tested separately
39 my $bt = Text::Tradition->new( input => 'Self', file => 't/data/besoin.xml' );
42 ok( 0, "Failed to throw error on lemmatizing without language" );
43 } catch( Text::Tradition::Error $e ) {
44 is( $e->message, "Please set a language to lemmatize a tradition",
45 "Got correct error thrown for lemmatization without set language" );
47 ok( 0, "Unexpected error on bad lemmatization attempt" );
57 predicate => 'has_language',
60 before 'language' => sub {
62 if( @_ && $_[0] ne 'Default' ) {
63 # We are trying to set the language; check that the corresponding
66 load( "Text::Tradition::Language::".$_[0] );
68 warn( "Cannot load language module for @_: $e" );
75 Calls the appropriate lemmatization function for the language of the
82 unless( $self->has_language ) {
83 $self->throw( "Please set a language to lemmatize a tradition" );
85 my $mod = "Text::Tradition::Language::" . $self->language;
89 $self->throw( "Cannot load language module for " . $self->language );
91 $self->throw( "Language module $mod has no lemmatize function" )
92 unless $mod->can( 'lemmatize' );
93 $mod->can( 'lemmatize' )->( $self );