X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FText%2FTradition%2FCollation%2FReading.pm;h=d1c69f7a449fb4bbb78ba1136f1bce3aaa306283;hb=7f52eac8cd00b160ea9e828790cbd093dc444feb;hp=d0d03857039e3202485a42e3e014fcf9daa20da4;hpb=49d4f2accb29737fdbaa42f75062d2055c4bc2ef;p=scpubgit%2Fstemmatology.git diff --git a/lib/Text/Tradition/Collation/Reading.pm b/lib/Text/Tradition/Collation/Reading.pm index d0d0385..d1c69f7 100644 --- a/lib/Text/Tradition/Collation/Reading.pm +++ b/lib/Text/Tradition/Collation/Reading.pm @@ -2,7 +2,6 @@ package Text::Tradition::Collation::Reading; use Moose; use overload '""' => \&_stringify, 'fallback' => 1; -use Text::Tradition::Collation; =head1 NAME @@ -37,6 +36,8 @@ Options include: =item is_lacuna - The 'reading' represents a known gap in the text. +=item is_ph - A temporary placeholder for apparatus parsing purposes. Do not use unless you know what you are doing. + =item rank - The sequence number of the reading. This should probably not be set manually. =back @@ -80,7 +81,7 @@ has 'text' => ( required => 1, writer => 'alter_text', ); - + has 'is_start' => ( is => 'ro', isa => 'Bool', @@ -98,6 +99,18 @@ has 'is_lacuna' => ( isa => 'Bool', default => undef, ); + +has 'is_ph' => ( + is => 'ro', + isa => 'Bool', + default => undef, + ); + +has 'is_common' => ( + is => 'rw', + isa => 'Bool', + default => undef, + ); has 'rank' => ( is => 'rw', @@ -115,12 +128,11 @@ around BUILDARGS => sub { } else { $args = { @_ }; } - + # If one of our special booleans is set, we change the text and the # ID to match. - if( exists $args->{'is_lacuna'} && !exists $args->{'text'} ) { - $args->{'text'} = sprintf( "#LACUNA_%s#", $args->{'id'} ); + $args->{'text'} = '#LACUNA#'; } elsif( exists $args->{'is_start'} ) { $args->{'id'} = '#START#'; # Change the ID to ensure we have only one $args->{'text'} = '#START#'; @@ -128,6 +140,8 @@ around BUILDARGS => sub { } elsif( exists $args->{'is_end'} ) { $args->{'id'} = '#END#'; # Change the ID to ensure we have only one $args->{'text'} = '#END#'; + } elsif( exists $args->{'is_ph'} ) { + $args->{'text'} = $args->{'id'}; } $class->$orig( $args ); @@ -143,15 +157,64 @@ of text found in a witness. sub is_meta { my $self = shift; - return $self->is_start || $self->is_end || $self->is_lacuna; + return $self->is_start || $self->is_end || $self->is_lacuna || $self->is_ph; } -# Some syntactic sugar +=head1 Convenience methods + +=head2 related_readings + +Calls Collation's related_readings with $self as the first argument. + +=cut + sub related_readings { my $self = shift; return $self->collation->related_readings( $self, @_ ); } +=head2 witnesses + +Calls Collation's reading_witnesses with $self as the first argument. + +=cut + +sub witnesses { + my $self = shift; + return $self->collation->reading_witnesses( $self, @_ ); +} + +=head2 predecessors + +Returns a list of Reading objects that immediately precede $self in the collation. + +=cut + +sub predecessors { + my $self = shift; + my @pred = $self->collation->sequence->predecessors( $self->id ); + return map { $self->collation->reading( $_ ) } @pred; +} + +=head2 successors + +Returns a list of Reading objects that immediately follow $self in the collation. + +=cut + +sub successors { + my $self = shift; + my @succ = $self->collation->sequence->successors( $self->id ); + return map { $self->collation->reading( $_ ) } @succ; +} + +=head2 set_identical( $other_reading) + +Backwards compatibility method, to add a transposition relationship +between $self and $other_reading. Don't use this. + +=cut + sub set_identical { my( $self, $other ) = @_; return $self->collation->add_relationship( $self, $other,