File Coverage

lib/Parse/Taxonomy/Auxiliary.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Parse::Taxonomy::Auxiliary;
2 8     8   32 use strict;
  8         10  
  8         218  
3 8     8   32 use Carp;
  8         8  
  8         1828  
4             our ($VERSION, @ISA, @EXPORT_OK);
5             $VERSION = '0.24';
6             @ISA = qw( Exporter );
7             @EXPORT_OK = qw(
8             path_check_fields
9             components_check_fields
10             );
11              
12             =head1 NAME
13              
14             Parse::Taxonomy::Auxiliary - Utility subroutines for Parse::Taxonomy
15              
16             =head1 SYNOPSIS
17              
18             use Parse::Taxonomy::Auxiliary qw(
19             path_check_fields
20             components_check_fields
21             );
22              
23             =cut
24              
25             =head1 SUBROUTINES
26              
27             =cut
28              
29             sub path_check_fields {
30 50     50 0 43 my ($data, $fields_ref) = @_;
31 50         82 _check_fields($data, $fields_ref, 0);
32             }
33              
34             sub components_check_fields {
35 33     33 0 33 my ($data, $fields_ref) = @_;
36 33         52 _check_fields($data, $fields_ref, 1);
37             }
38              
39             sub _check_fields {
40 83     83   74 my ($data, $fields_ref, $components) = @_;
41 83         70 my %header_fields_seen;
42 83         68 for my $f (@{$fields_ref}) {
  83         134  
43 507 100       524 if (exists $header_fields_seen{$f}) {
44 4         5 my $error_msg = '';
45 4 100       23 if ($components) {
46 2         5 $error_msg = "Duplicate field '$f' observed in 'fields' array ref";
47             }
48             else {
49 2         8 $error_msg = "Duplicate field '$f' observed in '$data->{file}'";
50             }
51 4         425 croak $error_msg;
52             }
53             else {
54 503         716 $header_fields_seen{$f}++;
55             }
56             }
57             }
58              
59             1;
60              
61             # vim: formatoptions=crqot