1 package Text::Tradition::Collation::Position;
23 # This gets set if we are tracking a more specifically-positioned
30 around BUILDARGS => sub {
34 # Two ways we can be called - with the arguments we expect, or with a
35 # single argument to be parsed out into a position.
38 my( $common, $min, $max ) = parse_reference( $_[0] );
39 %args = ( 'common' => $common,
42 } elsif ( 2 <= @_ && @_ <= 3 ) {
43 my( $common, $min, $max ) = @_;
44 $max = $min unless $max;
45 %args = ( 'common' => $common,
52 return $class->$orig( %args );
57 if( $self->min > $self->max ) {
58 die "Position minimum cannot be higher than maximum";
64 if( $ref =~ /^(\d+),(\d+)(\-(\d+))?$/ ) {
65 my( $common, $min, $max ) = ( $1, $2, $4 );
66 $max = $min unless defined $max;
67 return( $common, $min, $max );
69 warn "Bad argument $ref passed to Position constructor";
76 my( $self, $other ) = @_;
77 return _cmp_bits( [ $self->common, $self->min, $self->max ],
78 [ $other->common, $other->min, $other->max ] );
84 my @abits = parse_reference( $a );
85 my @bbits = parse_reference( $b );
86 return _cmp_bits( \@abits, \@bbits );
91 return $a->[0] <=> $b->[0]
92 unless $a->[0] == $b->[0];
93 return $a->[1] <=> $b->[1]
94 unless $a->[1] == $b->[1];
95 return $a->[2] <=> $b->[2];
100 return join(',', $self->common, $self->min );
105 return join(',', $self->common, $self->max );
110 my $answer = join( ',', $self->common, $self->min );
111 $answer .= '-'. $self->max unless $self->min == $self->max;
117 return $self->min == $self->max;
121 my( $self, $other, $strict ) = @_;
123 return $self->common == $other->common
124 && $self->min == $other->min
125 && $self->max == $other->max;
127 return $self->common == $other->common
128 && $self->min <= $other->max
129 && $self->max >= $other->min;
133 # Return all the possible fixed position refs.
134 sub possible_positions {
136 my @possible = map { join( ',', $self->common, $_ ) } ( $self->min .. $self->max );
141 __PACKAGE__->meta->make_immutable;