2 package MooseX::Getopt::GLD;
5 use Getopt::Long::Descriptive;
7 with 'MooseX::Getopt::Basic';
9 around _getopt_spec => sub {
14 around _getopt_get_options => sub {
16 my ($class, $params, $opt_spec) = @_;
17 return Getopt::Long::Descriptive::describe_options($class->_usage_format(%$params), @$opt_spec);
21 my ( $class, %params ) = @_;
23 my ( @options, %name_to_init_arg );
25 my $constructor_params = $params{params};
27 foreach my $opt ( @{ $params{options} } ) {
30 $opt->{doc} || ' ', # FIXME new GLD shouldn't need this hack
32 ( ( $opt->{required} && !exists($constructor_params->{$opt->{init_arg}}) ) ? (required => $opt->{required}) : () ),
34 # remove this 'feature' because it didn't work
35 # all the time, and so is better to not bother
36 # since Moose will handle the defaults just
39 #( exists $opt->{default} ? (default => $opt->{default}) : () ),
43 my $identifier = lc($opt->{name});
44 $identifier =~ s/\W/_/g; # Getopt::Long does this to all option names
46 $name_to_init_arg{$identifier} = $opt->{init_arg};
49 return ( \@options, \%name_to_init_arg );
60 MooseX::Getopt::GLD - A Moose role for processing command line options with Getopt::Long::Descriptive
68 with 'MooseX::Getopt::GLD';
70 has 'out' => (is => 'rw', isa => 'Str', required => 1);
71 has 'in' => (is => 'rw', isa => 'Str', required => 1);
73 # ... rest of the class here
80 my $app = My::App->new_with_options();
81 # ... rest of the script here
83 ## on the command line
84 % perl my_app_script.pl -in file.input -out file.dump
88 =head1 COPYRIGHT AND LICENSE
90 Copyright 2007-2009 by Infinity Interactive, Inc.
92 L<http://www.iinteractive.com>
94 This library is free software; you can redistribute it and/or modify
95 it under the same terms as Perl itself.