Fix/pica_keep.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 94.5% 35 / 37 CC 2 SCAR 2.3
CC
2
Cov
97%
fix
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Importer/PICA.pm ↑ Summary Exporter/PICA.pm »
1 package Catmandu::Fix::pica_keep;
2  
3 1 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '1.18';
6  
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use PICA::Data qw(pica_path pica_fields);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 has pathes => (
13 fix_arg => 'collect',
14 3 ▶ coerce => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
15 3 [ map { pica_path($_) } map { split /\s*,\s*/ } @{ $_[0] } ]
16 }
17 1 );
18  
19 3 ▶sub fix {
Subroutine fix: called CC=2 SCAR=7.0
Pod undocumented
20 3 my ( $self, $data ) = @_;
21 3 ▶ if ( reftype( $data->{record} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($data->{"record"}) eq "ARRAY") 3 0 3
22 3 $data->{record} = pica_fields( $data, @{ $self->pathes } );
23 }
24 3 return $data;
25 }
26  
27 =head1 NAME
28  
29 Catmandu::Fix::pica_keep - reduce PICA record to selected fields
30  
31 =head1 SYNOPSIS
32  
33 # keep level 0 fields
34 pica_keep('0.../*')
35  
36 # keep two specific fields only
37 pica_keep(003@,021A) # pathes can passed as multiple arguments
38 pica_keep("003@,021A") # equivalent: one argument with multiple pathes
39  
40 =head1 FUNCTIONS
41  
42 =head2 pica_keep(PATH,PATH...)
43  
44 Reduce PICA record to fields referenced by L<PICA Path expressions|https://format.gbv.de/query/picapath>.
45 Multiple expressions can be separated by C<,> and optional space or given as multiple arguments.
46 Path expressions should not contain subfields.
47  
48 =head2 SEE ALSO
49  
50 Function C<pica_fields> of L<PICA::Data>, L<PICA::Path>, L<Catmandu::Fix::pica_remove>.
51  
52 =cut
53  
54 1 1;
« Importer/PICA.pm ↑ Summary Exporter/PICA.pm »