tests passing with new library, yay
[scpubgit/stemmatology.git] / lib / Text / Tradition / Witness.pm
index 90db6ca..cb461c5 100644 (file)
@@ -14,6 +14,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
@@ -21,8 +22,15 @@ has 'text' => (
 has 'source' => (
     is => 'ro',
     isa => 'Str',
+    predicate => 'has_source',
     );
 
+has 'path' => (
+    is => 'rw',
+    isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
+    predicate => 'has_path',
+    );        
+
 sub BUILD {
     my $self = shift;
     if( $self->has_source ) {
@@ -40,5 +48,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;