Commits

Palmer, 2E0EOL  committed 193995b

Check to ensure that a code ref is passed.

  • Participants
  • Parent commits e17514a

Comments (0)

Files changed (1)

File BBBackupAgent.pm

 	OPT_TYPE_VARNAME() => \&_CheckOptTypeVarname,
 	OPT_TYPE_STRING() => \&_CheckOptTypeString,
 	OPT_TYPE_BOOL() => \&_CheckOptTypeBool,
-	OPT_TYPE_CODEREF() => undef,
+	OPT_TYPE_CODEREF() => \&_CheckOptTypeCoderef,
 	OPT_TYPE_REALFILE() => \&_CheckOptTypeRealfile,
 	OPT_TYPE_REALDIR() => \&_CheckOptTypeRealdir
 );
 	return 0;
 }
 #----------------------------------------------------------------------------
+sub _CheckOptTypeCoderef
+{
+	my $ref;
+	my $good = 0;
+	my ( $self, $OptVal, $PErrMsg ) = @_;
+	die 'Internal error' if ( !$self );
+	if ( defined($OptVal) && ($ref = ref($OptVal)) ) {
+		if ( $ref eq 'CODE' ) {
+			$good++;
+		} else {
+			$$PErrMsg = sprintf(
+				'Ref to type %s (not code)',
+				$ref
+			) if ( $PErrMsg );
+		}
+	} else {
+		if ( defined($OptVal) ) {
+			$$PErrMsg = $OptVal . ' is not a reference'
+				if ( $PErrMsg );
+		} else {
+			$$PErrMsg = 'Undefined value' if ( $PErrMsg );
+		}
+	}
+	return $good;
+}
+#----------------------------------------------------------------------------
 sub _CheckOptTypeRealdir
 {
 	my $self = shift;