#!/usr/bin/perl 
use strict;
use warnings;
use Acme::MetaSyntactic;
use Getopt::Long;

my $usage = << 'EOT';
Usage: meta [ options ] theme [ count ]
Available options:
  --help            : print this message and exit
  --whitespace|--ws : return metasyntactical names separated by whitespace
  --version         : print version information and exit
  --themes          : print the list of themes and exit
  --remote          : fetch the remote list (if available) and print it
EOT

my %conf = ( whitespace => 0 );
GetOptions( \%conf, "whitespace|ws!", "version", "themes", "help", "remote" )
  or die $usage;

# informative options
print STDERR
"meta, a simple front-end to Acme::MetaSyntactic version $Acme::MetaSyntactic::VERSION\n"
  if $conf{version};
print STDERR $usage if $conf{help};
print map "$_\n", Acme::MetaSyntactic->themes if $conf{themes};
exit if $conf{themes} || $conf{version} || $conf{help};

# real processing starts here
$\ = $/;
my $sep = $conf{whitespace} ? ' ' : $\;

my $theme = shift || $Acme::MetaSyntactic::Theme;
die "Theme '$theme' does not exist!\n"
  . "Available themes: @{[ Acme::MetaSyntactic->themes ]}\n"
  unless Acme::MetaSyntactic->has_theme( $theme );

my $meta = Acme::MetaSyntactic->new( $theme );

if ( $conf{remote} ) {
    my $module = "Acme::MetaSyntactic::$theme";
    eval "require $module;";
    die "Theme '$theme' is not updatable!\n"
        unless $module->has_remotelist();
    print join $sep, sort $module->remote_list();
}
else {
    my $count = shift;
    $count = 1 unless defined $count;
    print join $sep, $meta->name($count);
}

__END__

=head1 NAME

meta - A simple front-end to Acme::MetaSyntactic

=head1 SYNOPSIS

B<meta> [ I<--whitespace|ws> ] [ I<--remote> ] [ I<--help> ] [ I<--version> ] I<theme> [ I<count> ]

=head1 DESCRIPTION

B<meta> is a simple front-end to Acme::MetaSyntactic.

A few examples should make it easy to understand what it does and how
it works:

    $ meta
    baz
    $ meta batman
    powie
    $ meta donmartin 3
    kloong
    thoof_foing
    weeooweeeoooo
    $ meta -ws browser 4
    arachne netscape voyager w3m

In short, the default theme is C<foo>, the default count is 1, the default
separator is C<$/>, but you can replace it by whitespace with I<--ws>.

=head1 COMMAND-LINE OPTIONS

The following command-line options are available:

=over 4

=item I<--whitespace>, I<--ws>

Print all items on a single line, separated by space.

=item I<--remote>

Fetch the remote list (if available) and print it.

=item I<--themes>

Print the list of available themes.

=item I<--version>

Print version information.

=item I<--help>

Print a short help message.

=back

=head1 SUCCESS STORIES

B<meta> is the script of choice for a new generation of hackers.
Here are a few comments from satisfied users:

=over 4

=item *

I<C<Acme::MetaSyntactic> makes me more productive when I have to write
regression tests for my Perl modules. No more do I spend time looking
for variable names! It simply changed my life.>

-- Rafael Garcia-Suarez, pumpking,
used AMS when writing tests for Sub::Identify.

=back

=head1 AUTHOR

Philippe "BooK" Bruhat, C<< <book@cpan.org> >>.

=head1 COPYRIGHT & LICENSE

Copyright 2005 Philippe 'BooK' Bruhat, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

