1 package App::Rgit::Command;
8 use Object::Tiny qw/cmd args policy/;
10 use App::Rgit::Utils qw/validate :codes/;
14 App::Rgit::Command - Base class for App::Rgit commands.
22 our $VERSION = '0.05';
26 Base class for L<App::Rgit> commands.
28 This is an internal class to L<rgit>.
32 =head2 C<< new cmd => $cmd, args => \@args >>
34 Creates a new command object for C<$cmd> that is bound to be called with arguments C<@args>.
39 __PACKAGE__->action($_ => 'Once') for qw/daemon gui help init version/, ' ';
42 my ($class, %args) = &validate;
44 $cmd = ' ' unless defined $cmd;
45 my $action = $class->action($cmd);
46 if ($class eq __PACKAGE__) {
49 croak "Command $cmd should be executed as a $action"
50 unless $class->isa($action);
52 eval "require $action; 1" or croak "Couldn't load $action: $@";
55 args => $args{args} || [ ],
56 policy => $args{policy},
60 =head2 C<< action $cmd [ => $pkg ] >>
62 If C<$pkg> is supplied, handles command C<$cmd> with C<$pkg> objects.
63 Otherwise, returns the current class for C<$cmd>.
68 my ($self, $cmd, $pkg) = @_;
69 if (not defined $cmd) {
70 return unless defined $self and ref $self and $self->isa(__PACKAGE__);
73 unless (defined $pkg) {
74 return __PACKAGE__ . '::Each' unless defined $commands{$cmd};
75 return $commands{$cmd}
77 $pkg = __PACKAGE__ . '::' . $pkg unless $pkg =~ /:/;
78 $commands{$cmd} = $pkg;
81 =head2 C<report $conf, $repo, $status>
83 Reports that the execution of the command in C<$repo> exited with C<status> to the current command's policy.
84 Returns what the policy callback returned, which should be one of the policy codes listed in C<App::Rgit::Utils>.
90 my $cb = $self->policy;
91 return $_[3] ? LAST : NEXT unless $cb;
93 return defined $code ? $code : NEXT;
106 Runs the command with a L<App::Rgit::Config> configuration object.
107 Handles back the code to return to the system and the last policy.
108 Implemented in subclasses.
116 Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>.
118 You can contact me by mail or on C<irc.perl.org> (vincent).
122 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.
126 You can find documentation for this module with the perldoc command.
128 perldoc App::Rgit::Command
130 =head1 COPYRIGHT & LICENSE
132 Copyright 2008 Vincent Pit, all rights reserved.
134 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
138 1; # End of App::Rgit::Command