* Perltidy.
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Session.pm
index bdb0417..e0bfff0 100644 (file)
@@ -11,45 +11,45 @@ use constant _default_getopt_parser => 'MooseX::Getopt::Parser::Default';
 
 # 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 {
@@ -58,7 +58,7 @@ sub build_options {
     my @attrs = map { $_->_compute_getopt_attrs } $self->_compute_getopt_classes;
 
     return $self->parser->build_options( $self, @attrs );
-}
+};
 
 
 sub _compute_getopt_classes {
@@ -73,29 +73,29 @@ 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;
     };
 
@@ -105,6 +105,7 @@ sub _get_cmd_type_for_attr {
 
 1;
 
+
 __END__
 
 =pod
@@ -141,8 +142,8 @@ L<MooseX::Getopt::Parser>.
 
 =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>
 
@@ -181,9 +182,10 @@ This accessor contains an arrayref of options parsed from command line by
 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>
 
@@ -215,12 +217,12 @@ Brandon L. Black, E<lt>blblack@gmail.comE<gt>
 
 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.