1 package App::Rgit::Command;
8 use App::Rgit::Utils qw<:codes>;
12 App::Rgit::Command - Base class for App::Rgit commands.
20 our $VERSION = '0.08';
24 Base class for L<App::Rgit> commands.
26 This is an internal class to L<rgit>.
32 my $arc = App::Rgit::Command->new(
37 Creates a new command object for C<$cmd> that is bound to be called with arguments C<@args>.
42 __PACKAGE__->action($_ => 'Once') for qw<daemon gui help init version>, ' ';
46 $class = ref $class || $class;
51 $cmd = ' ' unless defined $cmd;
53 my $action = $class->action($cmd);
55 if ($class eq __PACKAGE__) {
58 Carp::confess("Command $cmd should be executed as a $action")
59 unless $class->isa($action);
62 eval "require $action; 1" or Carp::confess("Couldn't load $action: $@");
66 args => $args{args} || [ ],
67 policy => $args{policy},
73 my $pkg = $arc->action($cmd);
74 $arc->action($cmd => $pkg);
76 If C<$pkg> is supplied, handles command C<$cmd> with C<$pkg> objects.
77 Otherwise, returns the current class for C<$cmd>.
82 my ($self, $cmd, $pkg) = @_;
83 if (not defined $cmd) {
84 return unless defined $self and ref $self and $self->isa(__PACKAGE__);
87 unless (defined $pkg) {
88 return __PACKAGE__ . '::Each' unless defined $commands{$cmd};
89 return $commands{$cmd}
91 $pkg = __PACKAGE__ . '::' . $pkg unless $pkg =~ /:/;
92 $commands{$cmd} = $pkg;
97 my $code = $arc->report($conf, $repo, $status);
99 Reports that the execution of the command in C<$repo> exited with C<$status> to the current command's policy.
100 Returns what policy C<report> method returned, which should be one of the policy codes listed in C<App::Rgit::Utils>.
107 my $code = $self->policy->handle(@_);
109 return defined $code ? $code : NEXT;
123 eval "sub $_ { \$_[0]->{$_} }" for qw<cmd args policy>;
128 my $code = $arc->run($conf);
130 Runs the command with a L<App::Rgit::Config> configuration object.
131 Handles back the code to return to the system and the last policy.
132 Implemented in subclasses.
140 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
142 You can contact me by mail or on C<irc.perl.org> (vincent).
146 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>.
147 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
151 You can find documentation for this module with the perldoc command.
153 perldoc App::Rgit::Command
155 =head1 COPYRIGHT & LICENSE
157 Copyright 2008,2009,2010 Vincent Pit, all rights reserved.
159 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
163 1; # End of App::Rgit::Command