1 package Text::Tradition::Witness;
3 use Moose::Util::TypeConstraints;
5 # Sigil. Required identifier for a witness.
12 # Text. This is an array of strings (i.e. word tokens).
13 # TODO Think about how to handle this for the case of pre-prepared
14 # collations, where the tokens are in the graph already.
17 isa => 'ArrayRef[Str]',
18 predicate => 'has_text',
21 # Source. This is where we read in the witness, if not from a
22 # pre-prepared collation. It is probably a filename.
26 predicate => 'has_source',
29 # Path. This is an array of Reading nodes that should mirror the
33 isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
34 predicate => 'has_path',
37 has 'uncorrected_path' => (
39 isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
40 predicate => 'has_ante_corr',
43 # Manuscript name or similar
49 # Any other info we have
58 if( $self->has_source ) {
59 # Read the file and initialize the text.
61 eval { no warnings; $rc = open( WITNESS, $self->source ); };
62 # If we didn't open a file, assume it is a string.
67 push( @words, split( /\s+/, $_ ) );
70 $self->text( \@words );
71 } # else the text is in the source string, probably
72 # XML, and we are doing nothing with it.
76 # If the text is not present, and the path is, and this is a 'get'
77 # request, generate text from path.
82 if( $self->has_path && !$self->has_text && !@_ ) {
83 my @words = map { $_->label } @{$self->path};
84 $self->$orig( \@words );
91 __PACKAGE__->meta->make_immutable;