diff options
Diffstat (limited to 'Master/texmf-dist/source/bibtex/biber/lib/Biber/Output/Base.pm')
-rw-r--r-- | Master/texmf-dist/source/bibtex/biber/lib/Biber/Output/Base.pm | 334 |
1 files changed, 0 insertions, 334 deletions
diff --git a/Master/texmf-dist/source/bibtex/biber/lib/Biber/Output/Base.pm b/Master/texmf-dist/source/bibtex/biber/lib/Biber/Output/Base.pm deleted file mode 100644 index 84f33ee1b84..00000000000 --- a/Master/texmf-dist/source/bibtex/biber/lib/Biber/Output/Base.pm +++ /dev/null @@ -1,334 +0,0 @@ -package Biber::Output::Base; -#use feature 'unicode_strings'; - -use Biber::Entry; -use IO::File; -use Log::Log4perl qw( :no_extra_logdie_message ); -my $logger = Log::Log4perl::get_logger('main'); - -=encoding utf-8 - -=head1 NAME - -Biber::Output::Base - base class for Biber output modules. - -=cut - -=head2 new - - Initialize a Biber::Output::Base object - -=cut - -sub new { - my $class = shift; - my $obj = shift; - my $self; - if (defined($obj) and ref($obj) eq 'HASH') { - $self = bless $obj, $class; - } - else { - $self = bless {}, $class; - } - return $self; -} - -=head2 set_output_target_file - - Set the output target file of a Biber::Output::Base object - A convenience around set_output_target so we can keep track of the - filename - -=cut - -sub set_output_target_file { - my $self = shift; - my $file = shift; - $self->{output_target_file} = $file; - my $enc_out; - if (Biber::Config->getoption('bblencoding')) { - $enc_out = ':encoding(' . Biber::Config->getoption('bblencoding') . ')'; - } - my $TARGET = IO::File->new($file, ">$enc_out") or $logger->logdie("Failed to open $file : $!"); - $self->set_output_target($TARGET); -} - - -=head2 set_output_target - - Set the output target of a Biber::Output::Base object - -=cut - -sub set_output_target { - my $self = shift; - my $target = shift; - $logger->logdie('Output target must be a IO::Handle object!') unless $target->isa('IO::Handle'); - $self->{output_target} = $target; - return; -} - -=head2 set_output_head - - Set the output head of a Biber::Output::Base object - $data could be anything - the caller is expected to know. - -=cut - -sub set_output_head { - my $self = shift; - my $data = shift; - $self->{output_data}{HEAD} = $data; - return; -} - -=head2 set_output_tail - - Set the output tail of a Biber::Output::Base object - $data could be anything - the caller is expected to know. - -=cut - -sub set_output_tail { - my $self = shift; - my $data = shift; - $self->{output_data}{TAIL} = $data; - return; -} - - -=head2 get_output_head - - Get the output head of a Biber::Output object - $data could be anything - the caller is expected to know. - Mainly used in debugging - -=cut - -sub get_output_head { - my $self = shift; - return $self->{output_data}{HEAD}; -} - -=head2 get_output_tail - - Get the output tail of a Biber::Output object - $data could be anything - the caller is expected to know. - Mainly used in debugging - -=cut - -sub get_output_tail { - my $self = shift; - return $self->{output_data}{TAIL}; -} - - -=head2 add_output_head - - Add to the head output data of a Biber::Output::Base object - The base class method just does a string append - -=cut - -sub add_output_head { - my $self = shift; - my $data = shift; - $self->{output_data}{HEAD} .= $data; - return; -} - -=head2 add_output_tail - - Add to the tail output data of a Biber::Output::Base object - The base class method just does a string append - -=cut - -sub add_output_tail { - my $self = shift; - my $data = shift; - $self->{output_data}{TAIL} .= $data; - return; -} - - -=head2 set_output_section - - Records the section object in the output object - We need some information from this when writing the .bbl - -=cut - -sub set_output_section { - my $self = shift; - my $secnum = shift; - my $section = shift; - $self->{section}{$secnum} = $section; - return; -} - -=head2 get_output_section - - Retrieve the output section object - -=cut - -sub get_output_section { - my $self = shift; - my $secnum = shift; - return $self->{section}{$secnum}; -} - - -=head2 get_output_entries - - Get the sorted order output data for all entries in a list as array ref - -=cut - -sub get_output_entries { - my $self = shift; - my $section = shift; - my $list = shift; - return [ map {$self->{output_data}{ENTRIES}{$section}{index}{$_}} @{$list->get_keys}]; -} - -=head2 get_output_entry - - Get the output data for a specific entry. - Used really only in tests as it instantiates list dynamic information so - we can see it in tests - -=cut - -sub get_output_entry { - my $self = shift; - my $list = shift; - my $key = shift; - my $section = shift; - $section = '0' if not defined($section); # default - mainly for tests - # Force a return of undef if there is no output for this key to avoid - # dereferencing errors in tests - my $out = $self->{output_data}{ENTRIES}{$section}{index}{lc($key)}; - my $out_string = $list->instantiate_entry($out, $key); - return $out ? $out_string : undef; -} - -=head2 set_los - - Set the output list of shorthands for a section - -=cut - -sub set_los { - my $self = shift; - my $shs = shift; - my $section = shift; - $self->{output_data}{LOS}{$section} = $shs; - return; -} - -=head2 get_los - - Get the output list of shorthands for a section as an array - -=cut - -sub get_los { - my $self = shift; - my $section = shift; - return @{$self->{output_data}{LOS}{$section}} -} - - -=head2 set_output_entry - - Add an entry output to a Biber::Output::Base object - The base class method just does a dump - -=cut - -sub set_output_entry { - my $self = shift; - my $entry = shift; - my $section = shift; - my $struc = shift; - $self->{output_data}{ENTRIES}{$section}{index}{lc($entry->get_field('citekey'))} = $entry->dump; - return; -} - -=head2 output - - Generic base output method - -=cut - -sub output { - my $self = shift; - my $data = $self->{output_data}; - my $target = $self->{output_target}; - my $target_string = "Target"; # Default - if ($self->{output_target_file}) { - $target_string = $self->{output_target_file}; - } - - $logger->debug('Preparing final output using class ' . __PACKAGE__ . '...'); - - $logger->info("Writing '$target_string' with encoding '" . Biber::Config->getoption('bblencoding') . "'"); - - print $target $data->{HEAD} or $logger->logdie("Failure to write head to $target_string: $!"); - - foreach my $secnum (sort keys %{$data->{ENTRIES}}) { - print $target "SECTION: $secnum\n\n"; - foreach my $list (@{$self->get_output_section($secnum)->get_lists}) { - my $listlabel = $list->get_label; - my $listtype = $list->get_type; - print $target " LIST: $listlabel\n\n"; - foreach my $k ($list->get_keys) { - if ($listtype eq 'entry') { - my $entry_string = $data->{ENTRIES}{$secnum}{index}{$k}; - print $target $entry_string or $logger->logdie("Failure to write entry '$k' to $target_string: $!"); - } - elsif ($listtype eq 'shorthand') { - next if Biber::Config->getblxoption('skiplos', $section->bibentry($k), $k); - print $target $k or $logger->logdie("Failure to write list element to $target_string: $!"); - } - } - } - } - - print $target $data->{TAIL} or $logger->logdie("Failure to write tail to $target_string: $!"); - - $logger->info("Output to $target_string"); - close $target or $logger->logdie("Failure to close $target_string: $!"); - return; -} - -=head1 AUTHORS - -François Charette, C<< <firmicus at gmx.net> >> -Philip Kime C<< <philip at kime.org.uk> >> - -=head1 BUGS - -Please report any bugs or feature requests on our sourceforge tracker at -L<https://sourceforge.net/tracker2/?func=browse&group_id=228270>. - -=head1 COPYRIGHT & LICENSE - -Copyright 2009-2011 François Charette and Philip Kime, all rights reserved. - -This module is free software. You can redistribute it and/or -modify it under the terms of the Artistic License 2.0. - -This program is distributed in the hope that it will be useful, -but without any warranty; without even the implied warranty of -merchantability or fitness for a particular purpose. - -=cut - -1; - -# vim: set tabstop=2 shiftwidth=2 expandtab: - |