Implements feature suggestion RT#58715 by storing the Usage object, fixes
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / GLD.pm
index 819455d..5edb937 100644 (file)
@@ -1,11 +1,26 @@
-
 package MooseX::Getopt::GLD;
+# ABSTRACT: A Moose role for processing command line options with Getopt::Long::Descriptive
+
 use Moose::Role;
 
-use Getopt::Long::Descriptive;
+use Getopt::Long::Descriptive 0.081;
 
 with 'MooseX::Getopt::Basic';
 
+has usage => (
+    is => 'rw', isa => 'Getopt::Long::Descriptive::Usage',
+    traits => ['NoGetopt'],
+);
+
+# captures the options: --help --usage --?
+has help_flag => (
+    is => 'ro', isa => 'Bool',
+    traits => ['Getopt'],
+    cmd_flag => 'help',
+    cmd_aliases => [ qw(usage ?) ],
+    documentation => 'Prints this usage information.',
+);
+
 around _getopt_spec => sub {
     shift;
     shift->_gld_spec(@_);
@@ -31,9 +46,9 @@ sub _gld_spec {
             {
                 ( ( $opt->{required} && !exists($constructor_params->{$opt->{init_arg}}) ) ? (required => $opt->{required}) : () ),
                 # NOTE:
-                # remove this 'feature' because it didn't work 
+                # remove this 'feature' because it didn't work
                 # all the time, and so is better to not bother
-                # since Moose will handle the defaults just 
+                # since Moose will handle the defaults just
                 # fine anyway.
                 # - SL
                 #( exists $opt->{default}  ? (default  => $opt->{default})  : () ),
@@ -49,15 +64,9 @@ sub _gld_spec {
     return ( \@options, \%name_to_init_arg );
 }
 
-no Moose::Role; 1;
-
-__END__
-
-=pod
+no Moose::Role;
 
-=head1 NAME
-
-MooseX::Getopt::GLD - A Moose role for processing command line options with Getopt::Long::Descriptive
+1;
 
 =head1 SYNOPSIS
 
@@ -83,15 +92,4 @@ MooseX::Getopt::GLD - A Moose role for processing command line options with Geto
   ## on the command line
   % perl my_app_script.pl -in file.input -out file.dump
 
-=head1 DESCRIPTION
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2007-2009 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
 =cut