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',
36 if( $self->has_source ) {
37 # Read the file and initialize the text.
38 open( WITNESS, $self->source ) or die "Could not open "
39 . $self->file . "for reading";
40 # TODO support TEI as well as plaintext, sometime
44 push( @words, split( /\s+/, $_ ) );
47 $self->text( \@words );
51 # If the text is not present, and the path is, and this is a 'get'
52 # request, generate text from path.
57 if( $self->has_path && !$self->has_text && !@_ ) {
58 my @words = map { $_->label } @{$self->path};
59 $self->$orig( \@words );
66 __PACKAGE__->meta->make_immutable;