work in progress, tests are failing, and parameterized role is not flexible enough...
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt.pm
index cc2e19a..f8133ed 100644 (file)
@@ -1,9 +1,21 @@
 package MooseX::Getopt;
 # ABSTRACT: A Moose role for processing command line options
 
-use Moose::Role 0.56;
+use MooseX::Role::Parameterized;
 
-with 'MooseX::Getopt::GLD';
+parameter getopt_conf => (
+    isa => 'ArrayRef[Str]',
+    default => sub { [ 'pass_through' ] },
+);
+
+role {
+
+    my $p = shift;
+    my $getopt_conf = $p->getopt_conf;
+
+    with 'MooseX::Getopt::GLD' => { getopt_conf => $getopt_conf };
+
+};
 
 no Moose::Role;
 
@@ -17,6 +29,10 @@ no Moose::Role;
 
   with 'MooseX::Getopt';
 
+  # or
+
+  with 'MooseX::Getopt' => { getopt_conf => [ 'getopt_compat', 'bundling', ... ] };
+
   has 'out' => (is => 'rw', isa => 'Str', required => 1);
   has 'in'  => (is => 'rw', isa => 'Str', required => 1);
 
@@ -76,6 +92,13 @@ Options specified in multiple places follow the following
 precendence order: commandline overrides configfile, which
 overrides explicit new_with_options parameters.
 
+=head2 Global options
+
+This role is a parameterized role. It accepts a HashRef of parameters. For now
+there is only one configuration parameter, C<getopt_conf>. This parameter is an
+ArrayRef of strings, which are L<Getopt::Long> configuraion options (see
+"Configuring Getopt::Long" in L<Getopt::Long>). See L<SYNOPSIS> for an example.
+
 =head2 Supported Type Constraints
 
 =over 4
@@ -195,8 +218,9 @@ If L<Getopt::Long/GetOptions> fails (due to invalid arguments),
 C<new_with_options> will throw an exception.
 
 If L<Getopt::Long::Descriptive> is installed and any of the following
-command line params are passed, the program will exit with usage 
-information. You can add descriptions for each option by including a
+command line params are passed, the program will exit with usage
+information (and the option's state will be stored in the help_flag
+attribute). You can add descriptions for each option by including a
 B<documentation> option for each attribute to document.
 
   --?
@@ -204,7 +228,7 @@ B<documentation> option for each attribute to document.
   --usage
 
 If you have L<Getopt::Long::Descriptive> the C<usage> param is also passed to
-C<new>.
+C<new> as the usage option.
 
 =method B<ARGV>
 
@@ -217,8 +241,26 @@ This accessor contains an arrayref of leftover C<@ARGV> elements that
 L<Getopt::Long> did not parse.  Note that the real C<@ARGV> is left
 un-mangled.
 
+=method B<usage>
+
+This accessor contains the L<Getopt::Long::Descriptive::Usage> object (if
+L<Getopt::Long::Descriptive> is used).
+
+=method B<help_flag>
+
+This accessor contains the boolean state of the --help, --usage and --?
+options (true if any of these options were passed on the command line).
+
 =method B<meta>
 
 This returns the role meta object.
 
+=method B<process_argv (%params)>
+
+This does most of the work of C<new_with_options>, analyzing the parameters
+and argv, except for actually calling the constructor. It returns a
+L<MooseX::Getopt::ProcessedArgv> object. C<new_with_options> uses this
+method internally, so modifying this method via subclasses/roles will affect
+C<new_with_options>.
+
 =cut