#!/usr/bin/perl

# Copyright (C) 2009 John J. Chew, III <jjchew@math.utoronto.ca>
# All Rights Reserved

package TSH::ParseArgs::RepeatsSince;

use strict;
use warnings;

use TSH::ParseArgs::Integer;
use TSH::Utility;

=pod

=head1 NAME

TSH::ParseArgs::Repeats - handle a command-line argument that should be a number of allowable repeats in a pairing algorithm, with optional round after which repeats should be counted

=head1 SYNOPSIS

  my $parser = new TSH::ParseArgs::RepeatsSince;

=head1 ABSTRACT

This Perl module is used by C<ParseArgs.pm> to parse command-line arguments.

=cut

=head1 DESCRIPTION

=over 4

=cut

our(@ISA) = qw(TSH::ParseArgs::Integer);

sub initialise ($);
sub new ($);
sub Parse ($$);
sub Usage ($);

=item $parserp->initialise();

Used internally to (re)initialise the object.

=cut

sub initialise ($) {
  my $this = shift;
  $this->Minimum(0);
  $this->Description('a number of repeats allowed, optionally followed by a ">" and a round number after which repeats should be counted');
  return $this;
  }

=item $parserp = new ParserArgs::RepeatsSince

Create a new instance

=cut

sub new ($) { TSH::Utility::new(@_); }

=item $argument_description = $this->Parse($line_parser)

Return the checked value of the command-line argument,
or () if the argument is invalid.

=cut

sub Parse ($$) {
  my $this = shift;
  my $line_parser = shift;
  my $max = 10000;
  my $since = undef;
  $line_parser->SetShared('round_error', 'epabre');
  my $value = $line_parser->GetArg();
  if (!defined $value) {
    $line_parser->Error("You need to specify a number of repeats with this command.");
    return ();
    }
  if ($value =~ s/>(\d+)$//) { $since = $1; }
  $line_parser->UnGetArg($value);
# $line_parser->SetShared('round_value', $value);
  return ($this->SUPER::Parse($line_parser), $since);
  }

=item $argument_description = $this->Usage()

Briefly describe this argument's usage (in a word or hyphenated phrase)

=cut

sub Usage ($) {
  my $this = shift;
  return 'number-of-repeats[>since-round]';
  }

=back

=cut

1;




