changed interface for Tradition init
[scpubgit/stemmatology.git] / lib / Text / Tradition / Witness.pm
index f570365..161cfa4 100644 (file)
@@ -26,31 +26,30 @@ 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]',
     predicate => 'has_path',
     );        
 
-has 'post_correctione' => (
+has 'uncorrected_path' => (
     is => 'rw',
-    isa => 'Str',
-    predicate => 'has_post_correctione',
+    isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
+    predicate => 'has_ante_corr',
     );
 
-subtype 'Correction',
-    as 'ArrayRef',
-    where { @{$_} == 3 &&
-           $_->[0]->isa( 'Int' ) &&
-           $_->[1]->isa( 'Int' ) &&
-           $_->[2]->isa( 'ArrayRef[Text::Tradition::Collation::Reading]' );
-    },
-    message { 'Correction must be a tuple of [offset, length, list]' };
+# Manuscript name or similar
+has 'identifier' => (
+    is => 'ro',
+    isa => 'Str',
+    );
 
-has 'corrections' => (
+# Any other info we have
+has 'other_info' => (
     is => 'ro',
-    isa => 'ArrayRef[Correction]',
-    default => sub { [] },
+    isa => 'Str',
     );
     
 
@@ -58,16 +57,19 @@ 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.
     }
 }
 
@@ -85,27 +87,5 @@ around text => sub {
     $self->$orig( @_ );
 };
 
-sub add_correction {
-    my( $self, $offset, $length, @replacement ) = @_;
-    # Rely on Moose for type checking of the arguments
-    push( @{$self->corrections}, [ $offset, $length, \@replacement ] );
-}
-
-sub corrected_path {
-    my $self = shift;
-
-    my @new_path;
-    push( @new_path, @{$self->path} );
-    my $drift = 0;
-    foreach my $correction ( @{$self->corrections} ) {
-       my( $offset, $length, $items ) = @$correction;
-       my $realoffset = $offset + $drift;
-       splice( @new_path, $realoffset, $length, @$items );
-       $drift += @$items - $length;
-    }
-    return \@new_path;
-}
-    
-
 no Moose;
 __PACKAGE__->meta->make_immutable;