add first-cut module for stemma analysis
[scpubgit/stemmatology.git] / lib / Text / Tradition / Witness.pm
index 1eccbb0..656c185 100644 (file)
@@ -1,5 +1,6 @@
 package Text::Tradition::Witness;
 use Moose;
+use Moose::Util::TypeConstraints;
 
 # Sigil. Required identifier for a witness.
 has 'sigil' => (
@@ -14,6 +15,7 @@ has 'sigil' => (
 has 'text' => (
     is => 'rw',
     isa => 'ArrayRef[Str]',
+    predicate => 'has_text',
     );
 
 # Source.  This is where we read in the witness, if not from a
@@ -24,6 +26,21 @@ has 'source' => (
     predicate => 'has_source',
     );
 
+# Path.  This is an array of Reading nodes that should mirror the
+# text above.
+has 'path' => (
+    is => 'rw',
+    isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
+    predicate => 'has_path',
+    );        
+
+has 'uncorrected_path' => (
+    is => 'rw',
+    isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
+    predicate => 'has_ante_corr',
+    );
+    
+
 sub BUILD {
     my $self = shift;
     if( $self->has_source ) {
@@ -41,5 +58,19 @@ sub BUILD {
     }
 }
 
+# If the text is not present, and the path is, and this is a 'get'
+# request, generate text from path.
+around text => sub {
+    my $orig = shift;
+    my $self = shift;
+
+    if( $self->has_path && !$self->has_text && !@_ ) {
+       my @words = map { $_->label } @{$self->path};
+       $self->$orig( \@words );
+    }
+    
+    $self->$orig( @_ );
+};
+
 no Moose;
 __PACKAGE__->meta->make_immutable;