]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind/Action.pm
Move and improve the subclass validation logic into a new helper module
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Action.pm
index fbdffe639da60c1a0b1fba5fab8f7fab368a0c09..ca3fbd2abd3460ef341d3a9cf212d804e64c73fc 100644 (file)
@@ -23,6 +23,8 @@ Actions are called each time a tool encounter an error and decide what to do wit
 
 =cut
 
+use Test::Valgrind::Util;
+
 use base qw<Test::Valgrind::Component Test::Valgrind::Carp>;
 
 =head1 METHODS
@@ -43,11 +45,10 @@ sub new {
  my %args = @_;
 
  if ($class eq __PACKAGE__) {
-  my $action = delete $args{action} || 'Test';
-  $action =~ s/[^\w:]//g;
-  $action = __PACKAGE__ . "::$action" if $action !~ /::/;
-  $class->_croak("Couldn't load action $action: $@")
-                                               unless eval "require $action; 1";
+  my ($action, $msg) = Test::Valgrind::Util::validate_subclass(
+   $args{action} || 'Test',
+  );
+  $class->_croak($msg) unless defined $action;
   return $action->new(%args);
  }