1 package App::Rgit::Command;
8 use Object::Tiny qw/cmd cwd_as_repo args repos/;
10 use App::Rgit::Utils qw/validate/;
11 use App::Rgit::Repository;
15 App::Rgit::Command - Base class for App::Rgit commands.
23 our $VERSION = '0.01';
27 Base class for L<App::Rgit> commands.
29 This is an internal class to L<rgit>.
33 =head2 C<< new cmd => $cmd, args => \@args, repos => \@repos >>
35 Creates a new command object for C<$cmd> that will called for all repositories C<@repos> with arguments C<@args>.
40 __PACKAGE__->action($_ => 'Once') for qw/version help daemon init/, ' ';
43 my ($class, %args) = &validate;
45 $cmd = ' ' unless defined $cmd;
46 my $action = $class->action($cmd);
47 croak "Command $cmd shouldn't be executed as an $action"
48 unless $class eq __PACKAGE__ or $class->isa($action);
49 my @repos = grep $_->isa('App::Rgit::Repository'),
50 ref $args{repos} eq 'ARRAY' ? @{$args{repos}} : $args{repos};
51 eval "require $action; 1" or croak "Couldn't load $action: $@";
52 my $r = App::Rgit::Repository->new(fake => 1);
53 return unless defined $r;
56 args => $args{args} || [ ],
62 =head2 C<< action $cmd [ => $pkg ] >>
64 If C<$pkg> is supplied, handles command C<$cmd> with C<$pkg> objects.
65 Otherwise, returns the current class for C<$cmd>.
70 my ($self, $cmd, $pkg) = @_;
71 $cmd = $self->cmd if !defined $cmd
72 and defined $self and $self->isa(__PACKAGE__);
73 return unless defined $cmd;
74 unless (defined $pkg) {
75 return __PACKAGE__ . '::Each' unless defined $commands{$cmd};
76 return $commands{$cmd}
78 $pkg = __PACKAGE__ . '::' . $pkg unless $pkg =~ /:/;
79 $commands{$cmd} = $pkg;
94 Runs the command with a L<App::Rgit::Config> configuration object.
95 Stops as soon as one of the executed commands fails, and returns the corresponding exit code.
96 Returns zero when all went fine.
97 Implemented in subclasses.
105 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
107 You can contact me by mail or on C<irc.perl.org> (vincent).
111 Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
115 You can find documentation for this module with the perldoc command.
117 perldoc App::Rgit::Command
119 =head1 COPYRIGHT & LICENSE
121 Copyright 2008 Vincent Pit, all rights reserved.
123 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
127 1; # End of App::Rgit::Command