#!/usr/bin/env perl

# blows up if we use strict before this, damn source filter
use Perl6::Perldoc::Parser;

use strict;
use warnings;
use Getopt::Long qw(:config auto_help bundling);
use Pod::Usage;

our $VERSION = '0.02';

GetOptions(
    'F|file=s' => \my $from_file,
    'f|format=s' => \(my $format = 'ansi'),
) or pod2usage();

if (!defined $from_file) {
    die "You must supply --file with an argument; see --help\n";
}

if ($format ne 'text' && $format ne 'ansi') {
    die "Format '$format' is unsupported\n";
}

if ($format eq 'text') {
    require Perl6::Perldoc::To::Text;
}
else {
    require Perl6::Perldoc::To::Ansi;
}

print Perl6::Perldoc::Parser->parse($from_file, {all_pod=>'auto'})
                            ->report_errors()
                            ->to_text();

=head1 NAME

grok - Perl 6 documentation reader

=head1 SYNOPSIS

B<grok> <options>

 Options:
   -F FILE, --file=FILE         A file to read Pod from
   -f FORMAT, --format=FORMAT   The output format, ansi(default) or text

=cut
