Commit | Line | Data |
dd3b58b0 |
1 | package Text::Tradition::Witness; |
2 | use Moose; |
3 | |
784877d9 |
4 | # Sigil. Required identifier for a witness. |
dd3b58b0 |
5 | has '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 |
12 | has '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. |
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 | |
dd3b58b0 |
41 | no Moose; |
42 | __PACKAGE__->meta->make_immutable; |