X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FApp%2FRgit%2FCommand.pm;h=348b8c40aab70ef4c659ba8167ca287222b95807;hb=1c5bf56c6f80e4cd818c341b34ba3410f34ed514;hp=cf58e94b80e8f241a00ecdccb101221d80686a1a;hpb=5578058510412fff726cb88b2c78075c43c59303;p=perl%2Fmodules%2Frgit.git diff --git a/lib/App/Rgit/Command.pm b/lib/App/Rgit/Command.pm index cf58e94..348b8c4 100644 --- a/lib/App/Rgit/Command.pm +++ b/lib/App/Rgit/Command.pm @@ -5,9 +5,7 @@ use warnings; use Carp qw/croak/; -use Object::Tiny qw/cmd args policy/; - -use App::Rgit::Utils qw/validate :codes/; +use App::Rgit::Utils qw/:codes/; =head1 NAME @@ -15,11 +13,11 @@ App::Rgit::Command - Base class for App::Rgit commands. =head1 VERSION -Version 0.03 +Version 0.06 =cut -our $VERSION = '0.03'; +our $VERSION = '0.06'; =head1 DESCRIPTION @@ -39,22 +37,29 @@ my %commands; __PACKAGE__->action($_ => 'Once') for qw/daemon gui help init version/, ' '; sub new { - my ($class, %args) = &validate; + my $class = shift; + $class = ref $class || $class; + + my %args = @_; + my $cmd = $args{cmd}; $cmd = ' ' unless defined $cmd; + my $action = $class->action($cmd); + if ($class eq __PACKAGE__) { $class = $action; } else { croak "Command $cmd should be executed as a $action" unless $class->isa($action); } + eval "require $action; 1" or croak "Couldn't load $action: $@"; - $class->SUPER::new( + bless { cmd => $cmd, args => $args{args} || [ ], policy => $args{policy}, - ); + }, $class; } =head2 C<< action $cmd [ => $pkg ] >> @@ -80,13 +85,16 @@ sub action { =head2 C +Reports that the execution of the command in C<$repo> exited with C<$status> to the current command's policy. +Returns what policy C method returned, which should be one of the policy codes listed in C. + =cut sub report { my ($self) = @_; - my $cb = $self->policy; - return $_[3] ? LAST : NEXT unless $cb; - my $code = $cb->(@_); + + my $code = $self->policy->report(@_); + return defined $code ? $code : NEXT; } @@ -96,7 +104,13 @@ sub report { =head2 C -Accessors. +Read-only accessors. + +=cut + +BEGIN { + eval "sub $_ { \$_[0]->{$_} }" for qw/cmd args policy/; +} =head2 C @@ -111,7 +125,7 @@ L. =head1 AUTHOR Vincent Pit, C<< >>, L. - + You can contact me by mail or on C (vincent). =head1 BUGS @@ -126,7 +140,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2008 Vincent Pit, all rights reserved. +Copyright 2008-2009 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.