Start fleshing out some of these classes
[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                 );
9
10 # Text.  This might be an array of strings, but it might also be an
11 # array of graph nodes.
12 has 'text' => (
13                is => 'rw',
14                isa => 'Array',
15                );
16
17 # File.  This is where we read in the witness, if not from a
18 # pre-prepared collation.
19 has 'file' => (
20                is => 'ro',
21                isa => 'Str',
22                );
23
24 sub 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
41 no Moose;
42 __PACKAGE__->meta->make_immutable;