changed interface for Tradition init
[scpubgit/stemmatology.git] / lib / Text / Tradition / Witness.pm
index 934bb51..161cfa4 100644 (file)
@@ -26,6 +26,8 @@ has 'source' => (
     predicate => 'has_source',
     );
 
+# Path.  This is an array of Reading nodes that should mirror the
+# text above.
 has 'path' => (
     is => 'rw',
     isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
@@ -37,22 +39,37 @@ has 'uncorrected_path' => (
     isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
     predicate => 'has_ante_corr',
     );
+
+# Manuscript name or similar
+has 'identifier' => (
+    is => 'ro',
+    isa => 'Str',
+    );
+
+# Any other info we have
+has 'other_info' => (
+    is => 'ro',
+    isa => 'Str',
+    );
     
 
 sub BUILD {
     my $self = shift;
     if( $self->has_source ) {
        # Read the file and initialize the text.
-       open( WITNESS, $self->source ) or die "Could not open " 
-           . $self->file . "for reading";
-       # TODO support TEI as well as plaintext, sometime
-       my @words;
-       while(<WITNESS>) {
-           chomp;
-           push( @words, split( /\s+/, $_ ) );
-       }
-       close WITNESS;
-       $self->text( \@words );
+       my $rc;
+       eval { no warnings; $rc = open( WITNESS, $self->source ); };
+       # If we didn't open a file, assume it is a string.
+       if( $rc ) {
+           my @words;
+           while(<WITNESS>) {
+               chomp;
+               push( @words, split( /\s+/, $_ ) );
+           }
+           close WITNESS;
+           $self->text( \@words );
+       } # else the text is in the source string, probably
+         # XML, and we are doing nothing with it.
     }
 }
 
@@ -70,6 +87,5 @@ around text => sub {
     $self->$orig( @_ );
 };
 
-
 no Moose;
 __PACKAGE__->meta->make_immutable;