blib/lib/Geo/GNS/Parser.pm

filter: Statementstmt 41.0% 16 / 39 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 33.3% 20 / 60 CC 9 SCAR 42.2
CC
9
Cov
29%
parse_file
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 67.8
↑ Summary
1 package Geo::GNS::Parser;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 require Exporter;
5 1 our @ISA = qw(Exporter);
6 1 our @EXPORT_OK = qw/parse_file @fields/;
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '0.02';
9  
10 1 our $data_dir = '/home/ben/data/gns';
11  
12 # See L<http://geonames.nga.mil/gns/html/gis_countryfiles.html> for
13 # explanations.
14  
15 1 our @fields = qw/RC UFI UNI LAT LONG DMS_LAT DMS_LONG MGRS JOG FC DSG
16 PC CC1 ADM1 POP ELEV CC2 NT LC SHORT_FORM GENERIC SORT_NAME_RO
17 FULL_NAME_RO FULL_NAME_ND_RO SORT_NAME_RG FULL_NAME_RG FULL_NAME_ND_RG
18 NOTE MODIFY_DATE/;
19  
20 sub parse_file
21 0 ▶{
Subroutine parse_file: not called CC=9 SCAR=45.0
Pod documented
22 0 my (%options) = @_;
23 0 my $file = $options{file};
24 0 my $data = $options{data};
25 0 my $callback = $options{callback};
26 0 my $callback_data = $options{callback_data};
27 0 ▶ if (! $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 0 0
28 0 croak "Specify a file with 'file =>'";
29 }
30 0 ▶ if ($file !~ m!/!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file =~ m[/]) 0 0 0
31 0 $file = "$data_dir/$file";
32 }
33 0 ▶ open my $input, "<:encoding(utf8)", $file or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $input, "<:encoding(utf8)", $file or die $! 0 0 0
34 0 ▶ while (<$input>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $input)) 0 0 0
35 0 my @parts = split /\t/;
36 0 ▶ if (@parts != 29) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts != 29) 0 0 0
37 0 die "$file:$.: bad line containing " . scalar (@parts) . " parts.\n";
38 }
39 0 my %line;
40 0 @line{@fields} = @parts;
41 0 my $ufi = $line{UFI};
42 0 ▶ if ($callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback) 0 0 0
43 0 &{$callback} ($callback_data, \%line);
44 }
45 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
46 0 push @$data, \%line;
47 }
48 }
49 0 ▶ close $input or die $!;
Branch: 1 branch
BranchTrueFalseTotal
close $input or die $! 0 0 0
50 }
51  
52 1 1;
↑ Summary