DX/ASDF.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran 66.6% 16 / 24 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 6 totaltotal 80.4% 78 / 97 CC 15 SCAR 25.7
CC
15
Cov
86%
decode_DIF
18.8
BEGIN
1.0
BEGIN
1.0
CRAP 13.1
↑ Summary DX.pm »
1 #------------------------------------------------------------------------------
2 #$Author: andrius $
3 #$Date: 2021-02-10 13:44:25 +0200 (Tr, 10 vas. 2021) $
4 #$Revision: 94 $
5 #$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/JCAMP-DX/tags/v0.03/lib/JCAMP/DX/ASDF.pm $
6 #------------------------------------------------------------------------------
7 #*
8 # Encoder/decoder for ASDF formats.
9 #**
10  
11 package JCAMP::DX::ASDF;
12  
13 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: encoder/decoder for ASDF formats
17 5 our $VERSION = '0.03'; # VERSION
18  
19 5 require Exporter;
20 5 our @ISA = qw( Exporter );
21 5 our @EXPORT_OK = qw(
22 decode
23 );
24  
25 5 our $debug = 0;
26  
27 sub decode_FIX
28 1 ▶{
Subroutine decode_FIX: called CC=1 SCAR=0.0
Pod undocumented
29 1 my( $line ) = @_;
30 1 $line =~ s/^\s+//;
31 1 $line =~ s/\s+$//;
32  
33 1 return split /\s+/, $line;
34 }
35  
36 sub decode_PAC
37 2 ▶{
Subroutine decode_PAC: called CC=1 SCAR=0.0
Pod undocumented
38 2 my( $line ) = @_;
39 2 $line =~ s/^\s+//;
40 2 $line =~ s/\s+$//;
41  
42 2 my @elements = $line =~ /([ +-]?\d+)/g;
43 2 return map { s/^[ +]//; $_ } @elements;
44 }
45  
46 sub decode_SQZ
47 125 ▶{
Subroutine decode_SQZ: called CC=1 SCAR=0.0
Pod undocumented
48 125 my( $line ) = @_;
49 125 $line =~ s/\s+(\d)/+$1/g;
50 125 $line =~ s/\s+-/-/g;
51  
52 125 $line =~ s/\@/+0/g;
53 125 $line =~ s/([A-I])/'+' . (ord( $1 ) - ord( 'A' ) + 1)/ge;
54 125 $line =~ s/([a-i])/-ord( $1 ) + ord( 'a' ) - 1/ge;
55 125 return decode_DIF( $line );
56 }
57  
58 sub decode_DIF
59 126 ▶{
Subroutine decode_DIF: called CC=15 SCAR=29.3
Pod undocumented
60 126 my( $line ) = @_;
61 126 my @elements;
62 126 ▶ while( $line ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 4039 126 4165
63 4039 ▶ if( $line =~ s/^\+// ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($line =~ s/^\+//) { } 180 3859 4039
elsif ($line =~ s/^(-?\d+)//) { } 210 3649 3859
elsif ($line =~ s/^%(\d*)//) { } 65 3584 3649
elsif ($line =~ s/^([J-R])(\d*)//) { } 2211 1373 3584
elsif ($line =~ s/^([j-r])(\d*)//) { } 1373 0 1373
elsif ($line =~ s/^(.)//) { } 0 0 0
64 180 next;
65 } elsif( $line =~ s/^(-?\d+)// ) {
66 210 push @elements, int( $1 );
67 210 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 210 210
68 } elsif( $line =~ s/^%(\d*)// ) {
69 65 ▶ push @elements, $elements[-1] + ($1 ne '' ? $1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$1 ne '' ? : 0 65 65
70 65 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 65 65
71 } elsif( $line =~ s/^([J-R])(\d*)// ) {
72 2211 ▶ push @elements, $elements[-1] +
Condition50%1/2
$2 // ""
l!l
22110
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
73 ((ord( $1 ) - ord( 'J' ) + 1) . ($2 // ''));
74 2211 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 2211 2211
75 } elsif( $line =~ s/^([j-r])(\d*)// ) {
76 1373 ▶ push @elements, $elements[-1] -
Condition50%1/2
$2 // ""
l!l
13730
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
77 ((ord( $1 ) - ord( 'j' ) + 1) . ($2 // ''));
78 1373 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 1373 1373
79 } elsif( $line =~ s/^(.)// ) {
80 0 warn "unrecognised symbol: $1";
81 }
82 }
83 126 return @elements;
84 }
85  
86 sub decode_DIFDUP
87 124 ▶{
Subroutine decode_DIFDUP: called CC=1 SCAR=0.0
Pod undocumented
88 124 my( $line ) = @_;
89 124 $line =~ s/(.)([S-Z])/$1 x ( ord( $2 ) - ord( 'S' ) + 1 )/ge;
90 124 $line =~ s/(.)s/$1 x 9/g;
91 124 return decode_SQZ( $line );
92 }
93  
94 sub decode
95 122 ▶{
Subroutine decode: called CC=1 SCAR=0.0
Pod undocumented
96 122 &decode_DIFDUP;
97 }
98  
99 5 1;
↑ Summary DX.pm »