ADIF/ADI.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 94.4% 17 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 97.8% 89 / 91 CC 12 SCAR 12.8
CC
12
Cov
98%
parse_file
6.0
_process_header
4.0
_process_record
4.0
CRAP 3.6
« ADIF/ADX.pm ↑ Summary ADIF.pm »
1 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
2 # vim:ts=8:sw=2:et:sta:sts=2
3 #########
4 # Author: rmp
5 #
6 package Ham::ADIF::ADI;
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use base qw(Ham::ADIF);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 our $VERSION = q[2026.07.25];
16  
17 4 ▶sub parse_file {
Subroutine parse_file: called CC=6 SCAR=17.9
Pod documented
18 4 my ($self, $filename) = @_;
19  
20 4 my $io = IO::File->new($filename, q[r]);
21  
22 #########
23 # thank goodness ADI is case-insensitive and we're spared using sensible things like record separators
24 #
25 4 my $header = q[];
26 4 my $read_header = 1;
27 4 my $rec = q[];
28 4 my $recs = [];
29  
30 4 ▶ while(my $line = <$io>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $io)) 43 4 47
31 43 ▶ if($line =~ m{<EOR>}smx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /<EOR>/msx) 18 25 43
32 #########
33 # JA1NLX - ADI with no header
34 #
35 18 $read_header = 0;
36 }
37  
38 43 ▶ if($read_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read_header) { } 14 29 43
39 14 $header .= $line;
40 } else {
41 29 $rec .= $line;
42 }
43  
44 43 ▶ if($line =~ m{<EOH>}smix) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /<EOH>/imsx) { } 3 40 43
elsif ($line =~ /<EOR>/imsx) { } 18 22 40
45 3 $self->_process_header($header);
46 3 $read_header = 0;
47  
48 } elsif($line =~ m{<EOR>}smix) {
49 18 push @{$recs}, $self->_process_record($rec);
50 18 $rec = q[];
51 }
52 }
53  
54 4 return $recs;
55 }
56  
57 18 ▶sub _process_record {
Subroutine _process_record: called CC=4 SCAR=13.9
58 18 my ($self, $rec) = @_;
59  
60 18 my $struct = {};
61 18 for my $tag (split m{[\r\n<]+}smx, $rec) {
62 380 ▶ if(!$tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag) 18 362 380
63 18 next;
64 }
65  
66 362 my ($tagname, $length, $type, $value) = $tag =~ m{(.*?):(\d+)(:D)?>(.*?)\s*$}smix;
67 362 ▶ if(!$tagname) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagname) 18 344 362
68 18 next;
69 }
70  
71 344 $struct->{lc $tagname} = $value;
72 }
73  
74 18 return $struct;
75 }
76  
77 3 ▶sub _process_header {
Subroutine _process_header: called CC=4 SCAR=14.0
78 3 my ($self, $header) = @_;
79  
80 3 my $struct = {};
81 3 for my $tag (split m{[\r\n]+}smx, $header) {
82 14 ▶ if(!$tag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tag) 0 14 14
83 0 next;
84 }
85  
86 14 my ($tagname, $length, $datatype, $value, $enum) = $tag =~ m{<(.*?):(\d+)(?::(.*?))?>(.*?)(?:,[{](.*?)[}])?$}smix;
87 14 ▶ if(!$tagname) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagname) 12 2 14
88 12 next;
89 }
90  
91 2 $struct->{lc $tagname} = $value;
92 }
93  
94 3 return $struct;
95 }
96  
97 2 1;
98  
99 __END__
« ADIF/ADX.pm ↑ Summary ADIF.pm »