use App::Rgit::Command;
use App::Rgit::Config;
-use App::Rgit::Utils qw/validate/;
=head1 NAME
=cut
sub new {
- my ($class, %args) = &validate;
+ my $class = shift;
+ $class = ref $class || $class;
+
+ my %args = @_;
+
my $config = App::Rgit::Config->new(
root => $args{root},
git => $args{git},
debug => $args{debug},
);
return unless defined $config;
+
my $command = App::Rgit::Command->new(
cmd => $args{cmd},
args => $args{args},
policy => $args{policy},
);
return unless defined $command;
+
bless {
config => $config,
command => $command,
sub run {
my $self = shift;
+
$self->command->run($self->config);
}
use Carp qw/croak/;
-use App::Rgit::Utils qw/validate :codes/;
+use App::Rgit::Utils qw/:codes/;
=head1 NAME
__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: $@";
bless {
cmd => $cmd,
use File::Spec::Functions qw/file_name_is_absolute/;
use App::Rgit::Repository;
-use App::Rgit::Utils qw/validate :levels/;
+use App::Rgit::Utils qw/:levels/;
use constant IS_WIN32 => $^O eq 'MSWin32';
=cut
sub new {
- my ($class, %args) = &validate;
+ my $class = shift;
+ $class = ref $class || $class;
+
+ my %args = @_;
my $root = $args{root};
return unless defined $root and -d $root;
*WIFSIGNALED = sub { shift() & 127 } unless eval { WIFSIGNALED(0); 1 };
}
-use App::Rgit::Utils qw/validate/;
-
=head1 NAME
App::Rgit::Repository - Class representing a Git repository.
=cut
sub new {
- my ($class, %args) = &validate;
+ my $class = shift;
+ $class = ref $class || $class;
+
+ my %args = @_;
+
my $dir = $args{dir};
$dir = abs_path $dir if defined $dir and not file_name_is_absolute $dir;
$dir = cwd unless defined $dir;
+
my ($repo, $bare, $name, $work);
if ($args{fake}) {
$repo = $work = $dir;
$work = $repo;
}
}
+
bless {
fake => !!$args{fake},
repo => $repo,
CRIT => 0,
};
-=head1 FUNCTIONS
-
-=head2 C<validate @method_args>
-
-Sanitize arguments passed to methods.
-
-=cut
-
-sub validate {
- my $class = shift;
- croak 'Optional arguments must be passed as key/value pairs' if @_ % 2;
- $class = ref($class) || $class;
- $class = caller unless $class;
- return $class, @_;
-}
-
=head1 EXPORT
-C<validate> is only exported on request, either by its name or by the C<'funcs'> tag.
-
C<NEXT> C<REDO>, C<LAST> and C<SAVE> are only exported on request, either by their name or by the C<'codes'> tags.
C<INFO>, C<WARN>, C<ERR> and C<CRIT> are only exported on request, either by their name or by the C<'levels'> tags.
our @EXPORT = ();
our %EXPORT_TAGS = (
- funcs => [ qw/validate/ ],
codes => [ qw/SAVE NEXT REDO LAST/ ],
levels => [ qw/INFO WARN ERR CRIT/ ],
);
use Cwd qw/cwd/;
use File::Spec::Functions qw/catdir/;
-use Test::More tests => 45;
+use Test::More tests => 42;
use App::Rgit;
local $SIG{__WARN__} = sub { die @_ };
-eval { App::Rgit->new(qw/foo bar baz/) };
-like($@, qr!Optional\s+arguments\s+must\s+be\s+passed\s+as\s+keys?\s*/\s*values?\s+pairs?!, 'App::Rgit->new(even): croaks');
-
my $res = eval { App::Rgit->new() };
is($@, '', 'App::Rgit->new(): no root: does not croak');
is($res, undef, 'App::Rgit->new(): no root: returns undef');
is($@, '', '$ar->new(): no args: does not croak');
isa_ok($res, 'App::Rgit', '$ar->new(): no args: returns an object');
-$res = eval { App::Rgit::new(undef, root => 't', git => 't/bin/git', cmd => 'version'); };
-is($@, '', 'undef->App::Rgit::new(): no args: does not croak');
-isa_ok($res, 'App::Rgit','undef->App::Rgit::new(): no args: returns an object');
-
use App::Rgit::Command;
eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') };