1 package Text::Tradition::Collation::Reading;
4 use Moose::Util::TypeConstraints;
6 use Text::Tradition::Collation::Relationship;
8 extends 'Graph::Easy::Node';
12 => where { $_ =~ /^\d+\,\d+$/ },
13 message { 'Position must be of the form x,y' };
18 predicate => 'has_position',
21 # This contains an array of reading objects; the array is a pool,
22 # shared by the reading objects inside the pool. When a reading is
23 # added to the pool, all the same_as attributes should be updated.
26 isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
29 # Deal with the non-arg option for Graph::Easy's constructor.
30 around BUILDARGS => sub {
35 if( @_ == 1 && ref( $_[0] ) ne 'HASH' ) {
36 return $class->$orig( 'name' => $_[0] );
38 return $class->$orig( @_ );
42 # Initialize the identity pool.
44 my( $self, $args ) = @_;
45 $self->same_as( [ $self ] );
49 # Wrapper function around 'label' attribute.
52 $self->set_attribute( 'label', $_[0] );
54 return $self->get_attribute( 'label' );
58 my( $self, $merged_node ) = @_;
59 # Adopt the identity pool of the other node.
60 my @now_identical = grep { $_ ne $merged_node } @{$merged_node->same_as};
61 my $new_pool = _merge_array_pool( \@now_identical, $self->same_as )
64 # TODO Adopt the relationship attributes of the other node.
67 ## Dealing with transposed readings. These methods are only really
68 ## applicable if we have a linear collation graph.
71 my( $self, $other_node ) = @_;
72 my $enlarged_pool = _merge_array_pool( $self->same_as,
73 $other_node->same_as );
75 # ...and set this node to point to the enlarged pool.
76 $self->same_as( $enlarged_pool );
79 sub identical_readings {
81 my @same = grep { $_ ne $self } @{$self->same_as};
85 sub _merge_array_pool {
86 my( $pool, $main_pool ) = @_;
88 foreach ( @$main_pool ) {
89 # Note which nodes are already in the main pool so that we
91 $poolhash{$_->name} = 1;
95 # Add the remaining nodes to the main pool...
96 push( @$main_pool, $_ ) unless $poolhash{$_->name};
103 my $pool = $self->same_as;
104 return $pool->[0]->name ne $self->name;
109 return $self->same_as->[0];
112 ## Keep track of which readings are unchanged across witnesses.
116 return $self->get_attribute( 'class' ) eq 'common';
121 $self->set_attribute( 'class', 'common' );
126 $self->set_attribute( 'class', 'variant' );
130 __PACKAGE__->meta->make_immutable;
134 ######################################################
135 ## copied from Graph::Easy::Parser docs
136 ######################################################
137 # when overriding nodes, we also need ::Anon
139 package Text::Tradition::Collation::Reading::Anon;
141 use MooseX::NonMoose;
142 extends 'Text::Tradition::Collation::Reading';
143 extends 'Graph::Easy::Node::Anon';
145 __PACKAGE__->meta->make_immutable;
148 # use base qw/Text::Tradition::Collation::Reading/;
149 # use base qw/Graph::Easy::Node::Anon/;
151 ######################################################
154 package Text::Tradition::Collation::Reading::Empty;
156 use MooseX::NonMoose;
157 extends 'Graph::Easy::Node::Empty';
159 __PACKAGE__->meta->make_immutable;
162 # use base qw/Text::Tradition::Collation::Reading/;
164 ######################################################