Start fleshing out some of these classes
[scpubgit/stemmatology.git] / lib / Text / Tradition / Witness.pm
CommitLineData
dd3b58b0 1package Text::Tradition::Witness;
2use Moose;
3
784877d9 4# Sigil. Required identifier for a witness.
dd3b58b0 5has 'sigil' => (
784877d9 6 is => 'ro',
dd3b58b0 7 isa => 'Str',
8 );
9
784877d9 10# Text. This might be an array of strings, but it might also be an
11# array of graph nodes.
dd3b58b0 12has 'text' => (
13 is => 'rw',
14 isa => 'Array',
15 );
16
784877d9 17# File. This is where we read in the witness, if not from a
18# pre-prepared collation.
19has 'file' => (
20 is => 'ro',
21 isa => 'Str',
22 );
23
24sub BUILD {
25 my $self = shift;
26 if( $self->has_file ) {
27 # Read the file and initialize the text.
28 open( WITNESS, $self->file ) or die "Could not open "
29 . $self->file . "for reading";
30 # TODO support TEI as well as plaintext, sometime
31 my @words;
32 while(<WITNESS>) {
33 chomp;
34 push( @words, split( /\s+/, $_ ) );
35 }
36 close WITNESS;
37 $self->text( @words );
38 }
39}
40
dd3b58b0 41no Moose;
42__PACKAGE__->meta->make_immutable;