#!/usr/bin/env perl

use strict;
use warnings FATAL => 'all';
use App::War;
use Getopt::Long;
use Pod::Usage;

our $VERSION = $App::War::VERSION;

=pod

=head1 NAME

war - break one big decision into lots of little decisions

=head1 SYNOPSIS

    war [-h|--help] [--man] [--version]
    war sourcefile

=head1 DESCRIPTION

Imagine you're at a department store, trying to choose one china pattern
out of a dozen or more alternatives.  How do you do it?  If none stands out
as the clear winner, you might apply a process of elimination to your
choices, until a winner emerges.

This application applies a process similar to that described above: first,
the set of alternatives is defined.  Then the alternatives are presented
pairwise to the user, who chooses one "winner" from each pair.  The process
continues until an unambiguous ordering of the alternatives is known.

=head1 OPTIONS

=over 4

=item B<-h>, B<--help>

Shows simple command-line options.

=item B<--man>

Shows detailed script information.

=item B<--version>

Shows the current script version.

=item C<sourcefile>

A text file containing the items to be ranked.  Blank lines are ignored, as
well as lines starting with the C<#> character.

=back

=head1 SEE ALSO

L<App::War>

=head1 AUTHOR

John Trammell, C<< <johntrammell [at] gmail.com> >>

=cut

our %OPT = ();
my @OPTIONS = qw/ help|h man version|v /;
GetOptions(\%OPT,@OPTIONS) || pod2usage;
if ($OPT{version}) { die "Using App::War v$VERSION\n" }
if ($OPT{man}) { pod2usage(-verbose => 2); }
if ($OPT{help} || !@ARGV) { pod2usage(-exitval => 0); }

# get items
my @items = _items(shift);

# fight the war
my $war = App::War->new(items => \@items)->run;

# print the results
print $war->report;

# read the items from the file specified on the command line
sub _items {
    my $file = shift;
    open(my $h,q(<),$file) or die $!;
    return grep { /\S/ && !/^#/ } map { chomp; $_ } <$h>;
}

