package App::MARC::Leader;

use strict;
use warnings;

use Class::Utils qw(set_params);
use Getopt::Std;
use MARC::File::XML (BinaryEncoding => 'utf8', RecordFormat => 'MARC21');
use MARC::Leader 0.06;
use MARC::Leader::Print 0.08;
use Unicode::UTF8 qw(encode_utf8);

our $VERSION = 0.11;

# Constructor.
sub new {
	my ($class, @params) = @_;

	# Create object.
	my $self = bless {}, $class;

	# Process parameters.
	set_params($self, @params);

	# Object.
	return $self;
}

# Run.
sub run {
	my $self = shift;

	my $marc_leader;
	# XXX Naive detect of MARC leader before getopts.
	if (defined $ARGV[-1] && length($ARGV[-1]) eq 24) {
		$marc_leader = pop @ARGV;
	}

	# Process arguments.
	$self->{'_opts'} = {
		'a' => undef,
		'd' => 0,
		'f' => undef,
		'h' => 0,
		'l' => undef,
		'v' => undef,
	};
	if (! getopts('adf:hl:v', $self->{'_opts'})
		|| $self->{'_opts'}->{'h'}
		|| (! $self->{'_opts'}->{'f'} && ! defined $marc_leader)) {

		print STDERR "Usage: $0 [-a] [-d] [-f marc_xml_file] [-h] [-l lang_code] [-v] [--version] [leader_string]\n";
		print STDERR "\t-a\t\t\tPrint with ANSI colors (or use NO_COLOR/COLOR env variables).\n";
		print STDERR "\t-d\t\t\tDon't print description.\n";
		print STDERR "\t-f marc_xml_file\tMARC XML file.\n";
		print STDERR "\t-h\t\t\tPrint help.\n";
		print STDERR "\t-l lang_code\t\tISO 639-1 language code (default is from locales).\n";
		print STDERR "\t-v\t\t\tVerbose mode.\n";
		print STDERR "\t--version\t\tPrint version.\n";
		print STDERR "\t[leader_string]\t\tMARC Leader string.\n";
		return 1;
	}

	if ($self->{'_opts'}->{'f'}) {
		my $marc_file = MARC::File::XML->in($self->{'_opts'}->{'f'});
		# XXX Check
		$marc_leader = $marc_file->next->leader;
	}

	# Parse MARC leader.
	my $leader = MARC::Leader->new(
		'verbose' => $self->{'_opts'}->{'v'},
	)->parse($marc_leader);

	# Print information.
	print encode_utf8(scalar MARC::Leader::Print->new(
		'lang' => $self->{'_opts'}->{'l'},
		'mode_ansi' => $self->{'_opts'}->{'a'},
		'mode_desc' => $self->{'_opts'}->{'d'} ? 0 : 1,
	)->print($leader));
	print "\n";

	return 0;
}

1;

__END__

=pod

=encoding utf8

=head1 NAME

App::MARC::Leader - Base class for marc-leader tool.

=head1 SYNOPSIS

 use App::MARC::Leader;

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

=head1 METHODS

=head2 C<new>

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

Constructor.

Returns instance of object.

=head2 C<run>

 my $exit_code = $app->run;

Run.

Returns 1 for error, 0 for success.

=head1 ERRORS

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

=head1 EXAMPLE1

=for comment filename=print_marc_leader_from_marc_xml_file.pl

 use strict;
 use warnings;

 use App::MARC::Leader;
 use IO::Barf qw(barf);
 use File::Temp qw(tempfile);
 use MIME::Base64;

 $ENV{'NO_COLOR'} = 1;

 # Content.
 my $marc_xml_example = <<'END';
 PD94bWwgdmVyc2lvbiA9ICIxLjAiIGVuY29kaW5nID0gIlVURi04Ij8+Cjxjb2xsZWN0aW9uIHht
 bG5zPSJodHRwOi8vd3d3LmxvYy5nb3YvTUFSQzIxL3NsaW0iIHhtbG5zOnhzaT0iaHR0cDovL3d3
 dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhzaTpzY2hlbWFMb2NhdGlvbj0iaHR0
 cDovL3d3dy5sb2MuZ292L01BUkMyMS9zbGltIGh0dHA6Ly93d3cubG9jLmdvdi9zdGFuZGFyZHMv
 bWFyY3htbC9zY2hlbWEvTUFSQzIxc2xpbS54c2QiPgogIDxyZWNvcmQgeG1sbnM9Imh0dHA6Ly93
 d3cubG9jLmdvdi9NQVJDMjEvc2xpbSIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAx
 L1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vd3d3LmxvYy5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aWVsZCB0
 YWc9IjcwMCIgaW5kMT0iMSIgaW5kMj0iICI+CiAgICAgIDxzdWJmaWVsZCBjb2RlPSJhIj5aYXBh
 ZGxvLCBMYWRpc2xhdjwvc3ViZmllbGQ+CiAgICAgIDxzdWJmaWVsZCBjb2RlPSI0Ij5hdXQ8L3N1
 YmZpZWxkPgogICAgPC9kYXRhZmllbGQ+CiAgICA8ZGF0YWZpZWxkIHRhZz0iNzEwIiBpbmQxPSIy
 IiBpbmQyPSIgIj4KICAgICAgPHN1YmZpZWxkIGNvZGU9ImEiPlZ5c29rw6EgxaFrb2xhIGVrb25v
 bWlja8OhIHYgUHJhemU8L3N1YmZpZWxkPgogICAgICA8c3ViZmllbGQgY29kZT0iNyI+a24yMDAx
 MDcwOTQwMzwvc3ViZmllbGQ+CiAgICA8L2RhdGFmaWVsZD4KICAgIDxkYXRhZmllbGQgdGFnPSI5
 OTgiIGluZDE9IiAiIGluZDI9IiAiPgogICAgICA8c3ViZmllbGQgY29kZT0iYSI+aHR0cDovL2Fs
 ZXBoLm5rcC5jei9GLz9mdW5jPWRpcmVjdCZhbXA7ZG9jX251bWJlcj0wMDAwMDAwOTYmYW1wO2xv
 Y2FsX2Jhc2U9Q05CPC9zdWJmaWVsZD4KICAgIDwvZGF0YWZpZWxkPgogIDwvcmVjb3JkPgo8L2Nv
 bGxlY3Rpb24+Cg==
 END

 my (undef, $temp_file) = tempfile();

 barf($temp_file, decode_base64($marc_xml_example));

 # Arguments.
 @ARGV = (
         '-l',
         'en',
         '-f',
         $temp_file,
 );

 # Run.
 exit App::MARC::Leader->new->run;

 # Output (ANSI colors are used with set COLOR env variable):
 # Record length: 0
 # Record status: New
 # Type of record: Language material
 # Bibliographic level: Monograph/Item
 # Type of control: No specified type
 # Character coding scheme: UCS/Unicode
 # Indicator count: Number of character positions used for indicators
 # Subfield code count: Number of character positions used for a subfield code (2)
 # Base address of data: 0
 # Encoding level: Full level
 # Descriptive cataloging form: Non-ISBD
 # Multipart resource record level: Not specified or not applicable
 # Length of the length-of-field portion: Number of characters in the length-of-field portion of a Directory entry (4)
 # Length of the starting-character-position portion: Number of characters in the starting-character-position portion of a Directory entry (5)
 # Length of the implementation-defined portion: Number of characters in the implementation-defined portion of a Directory entry (0)
 # Undefined: Undefined

=head1 EXAMPLE2

=for comment filename=print_marc_leader_from_marc_xml_file_with_ansi.pl

 use strict;
 use warnings;

 use App::MARC::Leader;
 use IO::Barf qw(barf);
 use File::Temp qw(tempfile);
 use MIME::Base64;

 # Content.
 my $marc_xml_example = <<'END';
 PD94bWwgdmVyc2lvbiA9ICIxLjAiIGVuY29kaW5nID0gIlVURi04Ij8+Cjxjb2xsZWN0aW9uIHht
 bG5zPSJodHRwOi8vd3d3LmxvYy5nb3YvTUFSQzIxL3NsaW0iIHhtbG5zOnhzaT0iaHR0cDovL3d3
 dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhzaTpzY2hlbWFMb2NhdGlvbj0iaHR0
 cDovL3d3dy5sb2MuZ292L01BUkMyMS9zbGltIGh0dHA6Ly93d3cubG9jLmdvdi9zdGFuZGFyZHMv
 bWFyY3htbC9zY2hlbWEvTUFSQzIxc2xpbS54c2QiPgogIDxyZWNvcmQgeG1sbnM9Imh0dHA6Ly93
 d3cubG9jLmdvdi9NQVJDMjEvc2xpbSIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAx
 L1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vd3d3LmxvYy5n
 b3YvTUFSQzIxL3NsaW0gaHR0cDovL3d3dy5sb2MuZ292L3N0YW5kYXJkcy9tYXJjeG1sL3NjaGVt
 YS9NQVJDMjFzbGltLnhzZCI+CiAgICA8bGVhZGVyPiAgICAgbmFtIGEyMiAgICAgICAgNDUwMDwv
 bGVhZGVyPgogICAgPGNvbnRyb2xmaWVsZCB0YWc9IjAwMSI+Y2s4MzAwMDc4PC9jb250cm9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Zz0iNzEwIiBpbmQxPSIy
 IiBpbmQyPSIgIj4KICAgICAgPHN1YmZpZWxkIGNvZGU9ImEiPlZ5c29rw6EgxaFrb2xhIGVrb25v
 bWlja8OhIHYgUHJhemU8L3N1YmZpZWxkPgogICAgICA8c3ViZmllbGQgY29kZT0iNyI+a24yMDAx
 MDcwOTQwMzwvc3ViZmllbGQ+CiAgICA8L2RhdGFmaWVsZD4KICAgIDxkYXRhZmllbGQgdGFnPSI5
 OTgiIGluZDE9IiAiIGluZDI9IiAiPgogICAgICA8c3ViZmllbGQgY29kZT0iYSI+aHR0cDovL2Fs
 ZXBoLm5rcC5jei9GLz9mdW5jPWRpcmVjdCZhbXA7ZG9jX251bWJlcj0wMDAwMDAwOTYmYW1wO2xv
 Y2FsX2Jhc2U9Q05CPC9zdWJmaWVsZD4KICAgIDwvZGF0YWZpZWxkPgogIDwvcmVjb3JkPgo8L2Nv
 bGxlY3Rpb24+Cg==
 END

 my (undef, $temp_file) = tempfile();

 barf($temp_file, decode_base64($marc_xml_example));

 # Arguments.
 @ARGV = (
         '-l',
         'en',
         '-a',
         '-f',
         $temp_file,
 );

 # Run.
 exit App::MARC::Leader->new->run;

 # Output:
 # Record length: 0
 # Record status: New
 # Type of record: Language material
 # Bibliographic level: Monograph/Item
 # Type of control: No specified type
 # Character coding scheme: UCS/Unicode
 # Indicator count: Number of character positions used for indicators
 # Subfield code count: Number of character positions used for a subfield code (2)
 # Base address of data: 0
 # Encoding level: Full level
 # Descriptive cataloging form: Non-ISBD
 # Multipart resource record level: Not specified or not applicable
 # Length of the length-of-field portion: Number of characters in the length-of-field portion of a Directory entry (4)
 # Length of the starting-character-position portion: Number of characters in the starting-character-position portion of a Directory entry (5)
 # Length of the implementation-defined portion: Number of characters in the implementation-defined portion of a Directory entry (0)
 # Undefined: Undefined

=head1 DEPENDENCIES

L<Class::Utils>,
L<Getopt::Std>,
L<MARC::File::XML>,
L<MARC::Leader>,
L<MARC::Leader::Print>,
L<Unicode::UTF8>.

=head1 REPOSITORY

L<https://github.com/michal-josef-spacek/App-MARC-Leader>

=head1 AUTHOR

Michal Josef Špaček L<mailto:skim@cpan.org>

L<http://skim.cz>

=head1 LICENSE AND COPYRIGHT

© 2023-2026 Michal Josef Špaček

BSD 2-Clause License

=head1 VERSION

0.11

=cut
