1 package App::Rgit::Command;
8 use App::Rgit::Utils qw/validate :codes/;
12 App::Rgit::Command - Base class for App::Rgit commands.
20 our $VERSION = '0.06';
24 Base class for L<App::Rgit> commands.
26 This is an internal class to L<rgit>.
30 =head2 C<< new cmd => $cmd, args => \@args >>
32 Creates a new command object for C<$cmd> that is bound to be called with arguments C<@args>.
37 __PACKAGE__->action($_ => 'Once') for qw/daemon gui help init version/, ' ';
40 my ($class, %args) = &validate;
42 $cmd = ' ' unless defined $cmd;
43 my $action = $class->action($cmd);
44 if ($class eq __PACKAGE__) {
47 croak "Command $cmd should be executed as a $action"
48 unless $class->isa($action);
50 eval "require $action; 1" or croak "Couldn't load $action: $@";
53 args => $args{args} || [ ],
54 policy => $args{policy},
58 =head2 C<< action $cmd [ => $pkg ] >>
60 If C<$pkg> is supplied, handles command C<$cmd> with C<$pkg> objects.
61 Otherwise, returns the current class for C<$cmd>.
66 my ($self, $cmd, $pkg) = @_;
67 if (not defined $cmd) {
68 return unless defined $self and ref $self and $self->isa(__PACKAGE__);
71 unless (defined $pkg) {
72 return __PACKAGE__ . '::Each' unless defined $commands{$cmd};
73 return $commands{$cmd}
75 $pkg = __PACKAGE__ . '::' . $pkg unless $pkg =~ /:/;
76 $commands{$cmd} = $pkg;
79 =head2 C<report $conf, $repo, $status>
81 Reports that the execution of the command in C<$repo> exited with C<$status> to the current command's policy.
82 Returns what policy C<report> method returned, which should be one of the policy codes listed in C<App::Rgit::Utils>.
89 my $code = $self->policy->report(@_);
91 return defined $code ? $code : NEXT;
105 eval "sub $_ { \$_[0]->{$_} }" for qw/cmd args policy/;
110 Runs the command with a L<App::Rgit::Config> configuration object.
111 Handles back the code to return to the system and the last policy.
112 Implemented in subclasses.
120 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
122 You can contact me by mail or on C<irc.perl.org> (vincent).
126 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.
130 You can find documentation for this module with the perldoc command.
132 perldoc App::Rgit::Command
134 =head1 COPYRIGHT & LICENSE
136 Copyright 2008-2009 Vincent Pit, all rights reserved.
138 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
142 1; # End of App::Rgit::Command