X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FWitness.pm;h=4215f87833329091b995b9f03c1549f14f9db233;hb=784877d9f8a915367c1015df8383fc65b49e156b;hp=a647bc346994e16906a8d58cb9a345c9c29f313a;hpb=c5104dc0979bd916e6090ed929fa4c378c74833e;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Witness.pm b/lib/Text/Tradition/Witness.pm index a647bc3..4215f87 100644 --- a/lib/Text/Tradition/Witness.pm +++ b/lib/Text/Tradition/Witness.pm @@ -1,17 +1,42 @@ -#!/usr/bin/env perl - package Text::Tradition::Witness; use Moose; +# Sigil. Required identifier for a witness. has 'sigil' => ( - is => 'rw', + is => 'ro', isa => 'Str', ); +# Text. This might be an array of strings, but it might also be an +# array of graph nodes. has 'text' => ( is => 'rw', isa => 'Array', ); +# File. This is where we read in the witness, if not from a +# pre-prepared collation. +has 'file' => ( + is => 'ro', + isa => 'Str', + ); + +sub BUILD { + my $self = shift; + if( $self->has_file ) { + # Read the file and initialize the text. + open( WITNESS, $self->file ) or die "Could not open " + . $self->file . "for reading"; + # TODO support TEI as well as plaintext, sometime + my @words; + while() { + chomp; + push( @words, split( /\s+/, $_ ) ); + } + close WITNESS; + $self->text( @words ); + } +} + no Moose; __PACKAGE__->meta->make_immutable;