Tamil/AuthoritiesLoader.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 76 CC 5 SCAR 22.3
CC
5
Cov
0%
process
20.0
run
6.0
BEGIN
2.0
CRAP 9.3
1 package Koha::Contrib::Tamil::AuthoritiesLoader;
2 #ABSTRACT: Authorities loader into a Koha instance
3 $Koha::Contrib::Tamil::AuthoritiesLoader::VERSION = '0.074';
4 use Moose;
5  
6 extends 'AnyEvent::Processor';
7  
8 use Carp;
9 use IO::File;
10 use C4::Context;
11  
12  
13 # Le nom du fichier les autorités
14 # Le fichier est au format:
15 # NP<TAB>a|Demians-Archimbaud<TAB>b|Frédéric
16 has input => ( is => 'rw', isa => 'Str' );
17  
18 # Le filehandle du fichier lu
19 has input_fh => ( is => 'rw', isa => 'IO::File' );
20  
21 # L'équivalence type auth vers tag autorité
22 # Lue dans la table auth_types
23 # { NP => '100', CO => '200' }
24 has type_to_tag => ( is => 'rw', isa => 'HashRef' );
25  
26  
27 sub run {
28 my $self = shift;
29  
30 # On récupère l'équivalence type d'autorité => tag
31 my %ttt;
32 my $dbh = C4::Context->dbh();
33 my $sth = $dbh->prepare( q(
34 SELECT authtypecode, auth_tag_to_report
35 FROM auth_types ) );
36 $sth->execute;
37 while ( my ( $authtypecode, $auth_tag_to_report ) = $sth->fetchrow ) {
38 $ttt{ $authtypecode } = $auth_tag_to_report;
39 }
40 $self->type_to_tag( \%ttt );
41  
42 my $fh = IO::File->new( $self->input, 'r' );
43 if ( $fh ) {
44 $self->input_fh( $fh );
45 $self->SUPER::run();
46 }
47 else {
48 croak "Unable to open file: " . $self->input;
49 }
50 };
51  
52  
53  
54 sub process {
55 my $self = shift;
56  
57 my $fh = $self->input_fh;
58 my $line = $fh->getline();
59 if ( $line ) {
60 chop $line;
61 $self->SUPER::process();
62 my ( $type, $sub ) = $line =~ /(\w+)\t(.*)/;
63 my ( @subfields ) = split /\t|\|/, $sub;
64 my $ttt = $self->type_to_tag;
65 unless ( $ttt->{ $type } ) {
66 croak "Unknown authority type code: " . $type;
67 }
68 if ( $#subfields > 0 ) {
69 my $record = MARC::Record->new();
70 my $leader = $record->leader();
71 substr($leader, 5, 3) = 'naa';
72 substr($leader, 9, 1) = 'a'; # encodage utf8
73 $record->encoding( 'UTF-8' );
74 $record->leader($leader);
75 $record->append_fields( MARC::Field->new(
76 $ttt->{ $type }, '', '', @subfields));
77 #print "TYPE: $type\n", $record->as_formatted(), "\n\n";
78 my ($authid) = AddAuthority($record, 0, $type);
79 }
80 return 1;
81 }
82  
83 # Fin du traitement
84 close $self->input_fh;
85  
86 return 0;
87 }
88  
89  
90  
91 no Moose;
92 __PACKAGE__->meta->make_immutable;
93  
94 1;
95  
96 __END__