File Coverage

blib/lib/MARC/Moose/Writer.pm
Criterion Covered Total %
statement 3 13 23.0
branch n/a
condition n/a
subroutine 1 4 25.0
pod 3 3 100.0
total 7 20 35.0


line stmt bran cond sub pod time code
1             package MARC::Moose::Writer;
2             # ABSTRACT: A Moose::Role to write somewhere MARC::Moose records
3             $MARC::Moose::Writer::VERSION = '1.0.44';
4 1     1   1048 use Moose;
  1         2  
  1         5  
5              
6             with 'MooseX::RW::Writer';
7              
8              
9              
10              
11             has formater => (
12             is => 'rw',
13             isa => 'MARC::Moose::Formater',
14             default => sub { MARC::Moose::Formater::Text->new() }
15             );
16              
17              
18              
19             has fh => ( is => 'rw' );
20              
21              
22              
23             sub begin {
24 0     0 1   my $self = shift;
25 0           my $fh = $self->fh;
26 0           print $fh $self->formater->begin();
27             };
28              
29              
30              
31             sub end {
32 0     0 1   my $self = shift;
33 0           my $fh = $self->fh;
34 0           print $fh $self->formater->end();
35             };
36              
37              
38              
39             sub write {
40 0     0 1   my ($self, $record) = @_;
41 0           my $fh = $self->fh;
42 0           print $fh $self->formater->format($record);
43 0           $self->count( $self->count + 1);
44             }
45              
46              
47             1;
48              
49             __END__
50              
51             =pod
52              
53             =encoding UTF-8
54              
55             =head1 NAME
56              
57             MARC::Moose::Writer - A Moose::Role to write somewhere MARC::Moose records
58              
59             =head1 VERSION
60              
61             version 1.0.44
62              
63             =head1 ATTRIBUTES
64              
65             =head2 formater
66              
67             A L<MARC::Moose::Formater> to be used to format records to write. By defaut,
68             it's a L<MARC::Moose::Formater::Text> formater.
69              
70             =head2 fh
71              
72             A file handle to which writing records. This can be a string with:
73              
74             open my $fh, ">", \$str;
75              
76             =head1 METHODS
77              
78             =head2 begin
79              
80             Method to be call before beginning writing record with L<write> method. By
81             default, this is just a call to the formater C<begin> method.
82              
83             =head2 end
84              
85             Method to be call at the end of the writing process, afet the last record has
86             been written, the last call to L<write>. By default, this is just a call to the
87             formater C<end> method.
88              
89             =head2 write($record)
90              
91             Write L<MARC::Moose::Record> $record into whatever data stream, a file, a
92             socket, etc. It uses the L<formater> to format the record. In this base class,
93             the record is printed on STDOUT.
94              
95             =head1 AUTHOR
96              
97             Frédéric Demians <f.demians@tamil.fr>
98              
99             =head1 COPYRIGHT AND LICENSE
100              
101             This software is copyright (c) 2021 by Frédéric Demians.
102              
103             This is free software; you can redistribute it and/or modify it under
104             the same terms as the Perl 5 programming language system itself.
105              
106             =cut