App-MARC-Validator

 view release on metacpan or  search on metacpan

Validator.pm  view on Meta::CPAN

	my @plugin_reports;
	foreach my $plugin_obj (@{$self->{'_plugins'}}) {
		push @plugin_reports, $plugin_obj->report;
	}
	my $report = Data::MARC::Validator::Report->new(
		'datetime' => DateTime->now,
		'plugins' => \@plugin_reports,
	);

	my $json = obj_to_json($self, $report);

	# Save to file.
	if (defined $self->{'_opts'}->{'o'}) {
		barf($self->{'_opts'}->{'o'}, encode_utf8($json));

	# Print to STDOUT.
	} else {
		print encode_utf8($json);
	}

	return 0;
}

sub _postprocess_plugins {
	my $self = shift;

	foreach my $plugin_obj (@{$self->{'_plugins'}}) {
		$plugin_obj->postprocess;
	}

	return;
}

sub _usage {
	my $self = shift;

	print STDERR "Usage: $0 [-d] [-f] [-h] [-i id] [-l] [-o output_file] [-p] [-r] [-u use_string] [-v] [--version] marc_xml_file..\n";
	print STDERR "\t-d\t\tDebug mode.\n";
	print STDERR "\t-f\t\tList of filter plugins.\n";
	print STDERR "\t-h\t\tPrint help.\n";
	print STDERR "\t-i id\t\tRecord identifier (default value is 001).\n";
	print STDERR "\t-l\t\tList of plugins.\n";
	print STDERR "\t-o output_file\tOutput file (default is STDOUT).\n";
	print STDERR "\t-p\t\tPretty print JSON output.\n";
	print STDERR "\t-r\t\tRecommendations.\n";
	print STDERR "\t-u use_string\tUse string to prefer plugin or filter (default situation is use all).\n";
	print STDERR "\t\t\te.g. plugin:MARC::Validator::Plugin::Field008\n";
	print STDERR "\t-v\t\tVerbose mode.\n";
	print STDERR "\t--version\tPrint version.\n";
	print STDERR "\tmarc_xml_file..\tMARC XML file(s).\n";

	return;
}

sub _use_plugins {
	my $self = shift;

	if (! defined $self->{'_opts'}->{'u'}) {
		return ();
	}
	my @use_options = split m/,/, $self->{'_opts'}->{'u'};
	my @use_plugins;
	foreach my $use_option (@use_options) {
		my ($type, $name) = split m/:/ms, $use_option, 2;
		if ($type eq 'plugin') {
			push @use_plugins, $name;
		}
	}

	return @use_plugins;
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

App::MARC::Validator - Base class for marc-validator script.

=head1 SYNOPSIS

 use App::MARC::Validator;

 my $app = App::MARC::Validator->new;
 my $exit_code = $app->run;

=head1 METHODS

=head2 C<new>

 my $app = App::MARC::Validator->new;

Constructor.

Returns instance of object.

=head2 C<run>

 my $exit_code = $app->run;

Run MARC validation command line application.

Returns 1 for error, 0 for success.

=head1 ERRORS

 new():
         From Class::Utils::set_params():
                 Unknown parameter '%s'.

=head1 DEPENDENCIES

L<App::MARC::Validator::Utils>,
L<Class::Utils>,
L<Data::MARC::Validator::Report>,
L<DateTime>,
L<English>,
L<Getopt::Std>,
L<IO::Barf>,



( run in 1.335 second using v1.01-cache-2.11-cpan-af0e5977854 )