1 package Text::Tradition::Collation::Position;
23 around BUILDARGS => sub {
27 # Two ways we can be called - with the arguments we expect, or with a
28 # single argument to be parsed out into a position.
31 my( $common, $min, $max ) = parse_reference( $_[0] );
32 %args = ( 'common' => $common,
35 } elsif ( 2 <= @_ && @_ <= 3 ) {
36 my( $common, $min, $max ) = @_;
37 $max = $min unless $max;
38 %args = ( 'common' => $common,
45 return $class->$orig( %args );
50 if( $self->min > $self->max ) {
51 die "Position minimum cannot be higher than maximum";
57 if( $ref =~ /^(\d+),(\d+)(\-(\d+))?$/ ) {
58 my( $common, $min, $max ) = ( $1, $2, $4 );
59 $max = $min unless defined $max;
60 return( $common, $min, $max );
62 warn "Bad argument $ref passed to Position constructor";
69 my( $self, $other ) = @_;
70 return _cmp_bits( [ $self->common, $self->min, $self->max ],
71 [ $other->common, $other->min, $other->max ] );
77 my @abits = parse_reference( $a );
78 my @bbits = parse_reference( $b );
79 return _cmp_bits( \@abits, \@bbits );
84 return $a->[0] <=> $b->[0]
85 unless $a->[0] == $b->[0];
86 return $a->[1] <=> $b->[1]
87 unless $a->[1] == $b->[1];
88 return $a->[2] <=> $b->[2];
93 return join(',', $self->common, $self->min );
98 return join(',', $self->common, $self->max );
103 my $answer = join( ',', $self->common, $self->min );
104 $answer .= '-'. $self->max unless $self->min == $self->max;
110 return $self->min == $self->max;
114 my( $self, $other, $strict ) = @_;
116 return $self->common == $other->common
117 && $self->min == $other->min
118 && $self->max == $other->max;
120 return $self->common == $other->common
121 && $self->min <= $other->max
122 && $self->max >= $other->min;
126 # Return all the possible fixed position refs.
127 sub possible_positions {
129 my @possible = map { join( ',', $self->common, $_ ) } ( $self->min .. $self->max );
134 __PACKAGE__->meta->make_immutable;