#!/usr/bin/perl 

# PODNAME: sudoc-localisation
# ABSTRACT: Génération de fichier de localisation automatique dans le Sudoc

package Main;
$Main::VERSION = '2.04';
use Modern::Perl;
use Getopt::Long;
use Pod::Usage;
use Koha::Contrib::Sudoc::BiblioReader;
use Koha::Contrib::Sudoc;
use Koha::Contrib::Sudoc::Localisation;
use AnyEvent::Processor::Conversion;

my ($help, $select, $lignes, $test, $dat, $coteabes, $peb);
$select = "SELECT biblionumber FROM biblio";
$lignes = 1000;
$coteabes = '930 $a';
$peb = 1;
GetOptions(
    'help|h'     => \$help,
    'select=s'   => \$select,
    'lignes=i'   => \$lignes,
    'test'       => \$test,
    'dat'        => \$dat,
    'coteabes=s' => \$coteabes,
    'peb!'       => \$peb,
);

if ( $help ) {
    pod2usage( -verbose => 2 );
    exit;
}

my $sudoc  = Koha::Contrib::Sudoc->new;
my $reader = Koha::Contrib::Sudoc::BiblioReader->new( koha => $sudoc->koha );
$reader->select($select) if $select;
my $writer = Koha::Contrib::Sudoc::Localisation->new(
    sudoc    => $sudoc,
    test     => $test,
    lines    => $lignes,
    dat      => $dat,
    coteabes => $coteabes,
    peb      => $peb);
my $converter = AnyEvent::Processor::Conversion->new(
   reader  => $reader,
   writer  => $writer,
   verbose => 1 
);
$converter->run();       
$writer->write_to_file();

__END__

=pod

=encoding UTF-8

=head1 NAME

sudoc-localisation - GÃ©nÃ©ration de fichier de localisation automatique dans le Sudoc

=head1 VERSION

version 2.04

=head1 AUTHOR

Frédéric Demians <f.demians@tamil.fr>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by Fréderic Demians.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007

=cut
