some more rehoming of functionality
[scpubgit/stemmatology.git] / lib / Text / Tradition / Witness.pm
1 package Text::Tradition::Witness;
2 use Moose;
3
4 # Sigil. Required identifier for a witness.
5 has 'sigil' => (
6     is => 'ro',
7     isa => 'Str',
8     required => 1,
9     );
10
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.
14 has 'text' => (
15     is => 'rw',
16     isa => 'ArrayRef[Str]',
17     );
18
19 # Source.  This is where we read in the witness, if not from a
20 # pre-prepared collation.  It is probably a filename.
21 has 'source' => (
22     is => 'ro',
23     isa => 'Str',
24     predicate => 'has_source',
25     );
26
27 has 'path' => (
28     is => 'rw',
29     isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
30     );         
31
32 sub BUILD {
33     my $self = shift;
34     if( $self->has_source ) {
35         # Read the file and initialize the text.
36         open( WITNESS, $self->source ) or die "Could not open " 
37             . $self->file . "for reading";
38         # TODO support TEI as well as plaintext, sometime
39         my @words;
40         while(<WITNESS>) {
41             chomp;
42             push( @words, split( /\s+/, $_ ) );
43         }
44         close WITNESS;
45         $self->text( \@words );
46     }
47 }
48
49 no Moose;
50 __PACKAGE__->meta->make_immutable;