split off stemma analysis modules from base Tradition layer
[scpubgit/stemmatology.git] / base / lib / Text / Tradition / Collation.pm
similarity index 98%
rename from lib/Text/Tradition/Collation.pm
rename to base/lib/Text/Tradition/Collation.pm
index 022c2bc..d652850 100644 (file)
@@ -897,6 +897,7 @@ readings.  This is the native transfer format for a tradition.
 =begin testing
 
 use Text::Tradition;
+use TryCatch;
 
 my $READINGS = 311;
 my $PATHS = 361;
@@ -930,11 +931,20 @@ is( scalar $st->collation->paths, $PATHS, "Reparsed collation has all paths" );
 is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" );
 
 # Now add a stemma, write to GraphML, and look at the output.
-my $stemma = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
-is( ref( $stemma ), 'Text::Tradition::Stemma', "Parsed dotfile into stemma" );
-is( $tradition->stemmata, 1, "Tradition now has the stemma" );
-$graphml = $c->as_graphml;
-like( $graphml, qr/digraph/, "Digraph declaration exists in GraphML" );
+my $SKIP_STEMMA;
+try {
+       $tradition->enable_stemmata;
+} catch {
+       $SKIP_STEMMA = 1;
+}
+SKIP: {
+       skip "Analysis module not present", 3 if $SKIP_STEMMA;
+       my $stemma = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
+       is( ref( $stemma ), 'Text::Tradition::Stemma', "Parsed dotfile into stemma" );
+       is( $tradition->stemmata, 1, "Tradition now has the stemma" );
+       $graphml = $c->as_graphml;
+       like( $graphml, qr/digraph/, "Digraph declaration exists in GraphML" );
+}
 
 # Now add a user, write to GraphML, and look at the output.
 unlike( $graphml, qr/testuser/, "Test user name does not exist in GraphML yet" );
@@ -950,6 +960,7 @@ like( $graphml, qr/testuser/, "Test user name now exists in GraphML" );
 
 =cut
 
+## TODO MOVE this to Tradition.pm
 sub as_graphml {
     my( $self, $options ) = @_;
        $self->calculate_ranks unless $self->_graphcalc_done;
@@ -1013,12 +1024,15 @@ sub as_graphml {
        }
     # Extra custom keys for complex objects that should be saved in some form.
     # The subroutine should return a string, or undef/empty.
-    $graph_attributes{'stemmata'} = sub { 
-       my @stemstrs;
-               map { push( @stemstrs, $_->editable( {linesep => ''} ) ) } 
-                       $self->tradition->stemmata;
-               join( "\n", @stemstrs );
-       };
+    if( $tmeta->has_method('stemmata') ) {
+               $graph_attributes{'stemmata'} = sub { 
+                       my @stemstrs;
+                       map { push( @stemstrs, $_->editable( {linesep => ''} ) ) } 
+                               $self->tradition->stemmata;
+                       join( "\n", @stemstrs );
+               };
+       }
+       
     $graph_attributes{'user'} = sub { 
        $self->tradition->user ? $self->tradition->user->id : undef 
     };