# Pluggined MooseX::Getopt::Parser parser
has parser => (
- is => 'rw',
- does => 'MooseX::Getopt::Parser',
+ is => 'rw',
+ does => 'MooseX::Getopt::Parser',
default => sub { $_[0]->_default_getopt_parser->new },
);
# Filter for classes which are searched for getopt trait
has classes_filter => (
- is => 'rw',
- isa => 'CodeRef',
- default => sub { sub { 1 } },
+ is => 'rw',
+ isa => 'CodeRef',
+ default => sub { sub { 1; } },
);
# Original @ARGV values
has ARGV => (
- is => 'rw',
- isa => 'ArrayRef[Str]',
- default => sub { [ @ARGV ] },
+ is => 'rw',
+ isa => 'ArrayRef[Str]',
+ default => sub { [@ARGV] },
);
# Unrecognized @ARGV values
has extra_argv => (
- is => 'rw',
- isa => 'ArrayRef[Str]',
+ is => 'rw',
+ isa => 'ArrayRef[Str]',
default => sub { [] },
);
# Hash with options parsed from argv
has options => (
- is => 'rw',
- isa => 'HashRef',
+ is => 'rw',
+ isa => 'HashRef',
default => sub { {} },
);
-
-sub BUILD {
- my ($self, $args) = @_;
-
- $self->build_options;
-};
+# Status returned by Getopt parser
+has status => (
+ is => 'rw',
+ isa => 'Bool',
+ predicate => 'has_status',
+);
sub build_options {
my @attrs = map { $_->_compute_getopt_attrs } $self->_compute_getopt_classes;
return $self->parser->build_options( $self, @attrs );
-}
+};
sub _compute_getopt_classes {
sub _get_cmd_flags_for_attr {
- my ($self, $attr) = @_;
+ my ( $self, $attr ) = @_;
my $flag = $attr->name;
my @aliases;
- if ($attr->does('MooseX::Getopt::Meta::Attribute::Trait')) {
- $flag = $attr->cmd_flag if $attr->has_cmd_flag;
+ if ( $attr->does('MooseX::Getopt::Meta::Attribute::Trait') ) {
+ $flag = $attr->cmd_flag if $attr->has_cmd_flag;
@aliases = @{ $attr->cmd_aliases } if $attr->has_cmd_aliases;
};
- return ($flag, @aliases);
+ return ( $flag, @aliases );
};
sub _get_cmd_type_for_attr {
- my ($self, $attr) = @_;
+ my ( $self, $attr ) = @_;
my $type;
$type = $attr->type_constraint if $attr->has_type_constraint;
- if ($attr->does('MooseX::Getopt::Meta::Attribute::Trait')) {
+ if ( $attr->does('MooseX::Getopt::Meta::Attribute::Trait') ) {
$type = $attr->cmd_type if $attr->has_cmd_type;
};
1;
+
__END__
=pod
=item B<new (%params)>
-This method creates new CLI session for L<MooseX::Getopt> and calls
-C<build_options> method.
+This method creates new CLI session object for L<MooseX::Getopt>. The
+session should be started with C<build_options> method.
=item B<build_options>
L<MooseX::Getopt::Parser>. If the options list are not empty before parsing
the command line, the old list will be included to new list.
-=item B<BUILD>
+=item B<status>
-This is a default L<Moose> constructor.
+This accessor contains a true value if L<MooseX::Getopt::Parser> was
+called via C<build_options> method and it succeeded.
=item B<meta>
Yuval Kogman, E<lt>nothingmuch@woobling.orgE<gt>
+Piotr Roszatycki, E<lt>dexter@cpan.orgE<gt>
+
=head1 CONTRIBUTORS
Ryan D Johnson, E<lt>ryan@innerfence.comE<gt>
-Piotr Roszatycki, E<lt>dexter@cpan.orgE<gt>
-
=head1 COPYRIGHT AND LICENSE
Copyright 2007-2008 by Infinity Interactive, Inc.