]> git.vpit.fr Git - perl/modules/rgit.git/commitdiff
Get rid of validate()
authorVincent Pit <vince@profvince.com>
Tue, 23 Feb 2010 00:32:47 +0000 (01:32 +0100)
committerVincent Pit <vince@profvince.com>
Tue, 23 Feb 2010 00:32:47 +0000 (01:32 +0100)
lib/App/Rgit.pm
lib/App/Rgit/Command.pm
lib/App/Rgit/Config.pm
lib/App/Rgit/Repository.pm
lib/App/Rgit/Utils.pm
t/15-failures.t

index 1c8873d714b3a8a360a6091c38f123b658467a39..ea9df10da2367299fe37c7ad995f43e9db3b69b1 100644 (file)
@@ -5,7 +5,6 @@ use warnings;
 
 use App::Rgit::Command;
 use App::Rgit::Config;
 
 use App::Rgit::Command;
 use App::Rgit::Config;
-use App::Rgit::Utils qw/validate/;
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -34,19 +33,25 @@ Creates a new L<App::Rgit> object that's bound to execute the command C<$cmd> on
 =cut
 
 sub new {
 =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 $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;
  my $command = App::Rgit::Command->new(
   cmd    => $args{cmd},
   args   => $args{args},
   policy => $args{policy},
  );
  return unless defined $command;
+
  bless {
   config  => $config,
   command => $command,
  bless {
   config  => $config,
   command => $command,
@@ -61,6 +66,7 @@ Actually run the commands.
 
 sub run {
  my $self = shift;
 
 sub run {
  my $self = shift;
+
  $self->command->run($self->config);
 }
 
  $self->command->run($self->config);
 }
 
index 3a34822317dc3a37c2b5c738528f53bd96b57d5a..348b8c40aab70ef4c659ba8167ca287222b95807 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use Carp qw/croak/;
 
 
 use Carp qw/croak/;
 
-use App::Rgit::Utils qw/validate :codes/;
+use App::Rgit::Utils qw/:codes/;
 
 =head1 NAME
 
 
 =head1 NAME
 
@@ -37,16 +37,23 @@ my %commands;
 __PACKAGE__->action($_ => 'Once') for qw/daemon gui help init version/, ' ';
 
 sub new {
 __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 $cmd = $args{cmd};
  $cmd = ' ' unless defined $cmd;
+
  my $action = $class->action($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);
  }
  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,
  eval "require $action; 1" or croak "Couldn't load $action: $@";
  bless {
   cmd    => $cmd,
index 76a605085b6fc0a8777fde3669abe033505c18f2..1cac51d6a75854b7c2e8c9c78f216ec717d09106 100644 (file)
@@ -8,7 +8,7 @@ use Cwd qw/abs_path/;
 use File::Spec::Functions qw/file_name_is_absolute/;
 
 use App::Rgit::Repository;
 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';
 
 
 use constant IS_WIN32 => $^O eq 'MSWin32';
 
@@ -39,7 +39,10 @@ Creates a new configuration object based on the root directory C<$root> and usin
 =cut
 
 sub new {
 =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;
 
  my $root = $args{root};
  return unless defined $root and -d $root;
index fd19bab29210aafb9a0a518d845b1d782e047627..1d8d490c16ea6c6e84db0ade55e760612fa1bcbe 100644 (file)
@@ -14,8 +14,6 @@ BEGIN {
  *WIFSIGNALED = sub { shift() & 127 } unless eval { WIFSIGNALED(0); 1 };
 }
 
  *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.
 =head1 NAME
 
 App::Rgit::Repository - Class representing a Git repository.
@@ -44,10 +42,15 @@ If the C<fake> option is passed, C<$dir> isn't checked to be a valid C<git> repo
 =cut
 
 sub new {
 =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 $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;
  my ($repo, $bare, $name, $work);
  if ($args{fake}) {
   $repo = $work = $dir;
@@ -77,6 +80,7 @@ sub new {
    $work = $repo;
   }
  }
    $work = $repo;
   }
  }
+
  bless {
   fake => !!$args{fake},
   repo => $repo,
  bless {
   fake => !!$args{fake},
   repo => $repo,
index 7a4c3b36779a8a4aef2e3949544f8ff5e26d6c57..cfe191dfc69993617ee9650279eb8831e41f83e7 100644 (file)
@@ -51,26 +51,8 @@ use constant {
  CRIT => 0,
 };
 
  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
 
 =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.
 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.
@@ -81,7 +63,6 @@ use base qw/Exporter/;
 
 our @EXPORT         = ();
 our %EXPORT_TAGS    = (
 
 our @EXPORT         = ();
 our %EXPORT_TAGS    = (
- funcs  => [ qw/validate/ ],
  codes  => [ qw/SAVE NEXT REDO LAST/ ],
  levels => [ qw/INFO WARN ERR CRIT/ ],
 );
  codes  => [ qw/SAVE NEXT REDO LAST/ ],
  levels => [ qw/INFO WARN ERR CRIT/ ],
 );
index 296ffc843cfb144abcdd02969daf2090306d6323..3217e23d990080058329012c1fd08fb4932e7754 100644 (file)
@@ -6,15 +6,12 @@ use warnings;
 use Cwd qw/cwd/;
 use File::Spec::Functions qw/catdir/;
 
 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 @_ };
 
 
 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');
 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');
@@ -43,10 +40,6 @@ $res = eval { $res->new(root => 't', git => 't/bin/git', cmd => 'version'); };
 is($@,       '',          '$ar->new(): no args: does not croak');
 isa_ok($res, 'App::Rgit', '$ar->new(): no args: returns an object');
 
 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') };
 use App::Rgit::Command;
 
 eval { App::Rgit::Command::Once->App::Rgit::Command::new(cmd => 'dongs') };