File Coverage

blib/lib/MARC/Moose/Lint/Checker.pm
Criterion Covered Total %
statement 3 5 60.0
branch n/a
condition n/a
subroutine 1 2 50.0
pod 1 1 100.0
total 5 8 62.5


line stmt bran cond sub pod time code
1             package MARC::Moose::Lint::Checker;
2             # ABSTRACT: A Moose::Role to 'lint' biblio record
3             $MARC::Moose::Lint::Checker::VERSION = '1.0.44';
4 4     4   5236 use Moose::Role;
  4         19264  
  4         17  
5              
6              
7             sub check {
8 0     0 1   my ($self, $record) = @_;
9 0           return ();
10             }
11              
12              
13             1;
14              
15             __END__
16              
17             =pod
18              
19             =encoding UTF-8
20              
21             =head1 NAME
22              
23             MARC::Moose::Lint::Checker - A Moose::Role to 'lint' biblio record
24              
25             =head1 VERSION
26              
27             version 1.0.44
28              
29             =head1 DESCRIPTION
30              
31             A MARC biblio record, MARC21, UNIMARC, whatever, can be validated against
32             rules. By extending this class, you defines your own validation rules. Then the
33             'lint' object can be given to a L<MARC::Moose::Record> or a
34             L<MARC::Moose::Reader>
35              
36             =head1 METHODS
37              
38             =head2 check( I<record> )
39              
40             This method checks a biblio record, based on the current 'lint' object. The
41             biblio record is a L<MARC::Moose::Record> object. An array of validation
42             errors/warnings is returned. Those errors are just plain text explanation on
43             the reasons why the record doesn't comply with validation rules. This role
44             could be applied directly to a L<MARC::Moose::Record> object or to
45             L<MARC::Moose::Parser> object.
46              
47             =head1 SYNOPSYS
48              
49             package LintPPN;
50              
51             use Moose;
52             with 'MARC::Moose::Lint::Checker'
53              
54             sub check {
55             my ($self, $record) = @_;
56             my @warnings = ();
57             if ( my $ppn = $record->field('001') ) {
58             if ( $ppn->value !~ /^PPN[0-9]*$/ ) {
59             push @warning, "Invalid PPN in 001 field";
60             }
61             }
62             else {
63             push @warning, "No 001 field";
64             }
65             return @warnings;
66             }
67              
68             package Main;
69              
70             use MARC::Moose::Reader::File::Iso2709;
71             use MARC::Moose::Parser::Iso2709;
72              
73             # Dump as text all biblio records without valid PPN
74             my $reader = $MARC::Moose::Reader::File::Iso2709(
75             file => 'biblio.mrc',
76             parser => MARC::Moose::Parser::Iso2709->new( lint => LintPPN->new() ));
77             while ( my $record = $reader->read() ) {
78             if ( my @warnings = $record->check() ) {
79             say $record->as('Text');
80             }
81             }
82              
83             =head1 SEE ALSO
84              
85             =over 4
86              
87             =item *
88              
89             L<MARC::Moose>
90              
91             =item *
92              
93             L<MARC::Moose::Lint::Checker::RulesFile>
94              
95             =item *
96              
97             L<MARC::Moose::Lint::Processor>
98              
99             =back
100              
101             =head1 AUTHOR
102              
103             Frédéric Demians <f.demians@tamil.fr>
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2021 by Frédéric Demians.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =cut