1 package Text::Tradition::Witness;
4 # Sigil. Required identifier for a witness.
11 # Text. This is an array of strings (i.e. word tokens).
12 # TODO Think about how to handle this for the case of pre-prepared
13 # collations, where the tokens are in the graph already.
16 isa => 'ArrayRef[Str]',
17 predicate => 'has_text',
20 # Source. This is where we read in the witness, if not from a
21 # pre-prepared collation. It is probably a filename.
25 predicate => 'has_source',
30 isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
31 predicate => 'has_path',
34 has 'post_correctione' => (
37 predicate => 'has_post_correctione',
43 if( $self->has_source ) {
44 # Read the file and initialize the text.
45 open( WITNESS, $self->source ) or die "Could not open "
46 . $self->file . "for reading";
47 # TODO support TEI as well as plaintext, sometime
51 push( @words, split( /\s+/, $_ ) );
54 $self->text( \@words );
58 # If the text is not present, and the path is, and this is a 'get'
59 # request, generate text from path.
64 if( $self->has_path && !$self->has_text && !@_ ) {
65 my @words = map { $_->label } @{$self->path};
66 $self->$orig( \@words );
73 __PACKAGE__->meta->make_immutable;