DX/ASDF.pm

filter: Statementstmt 98.0% 51 / 52 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.2% 77 / 96 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: 2018-11-21 09:40:40 +0200 (Tr, 21 lapkr. 2018) $
4 #$Revision: 32 $
5 #$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/jcamp-dx/tags/v0.02/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 5 require Exporter;
17 5 our @ISA = qw( Exporter );
18 5 our @EXPORT_OK = qw(
19 decode
20 );
21  
22 5 our $debug = 0;
23  
24 sub decode_FIX
25 {
26 1 ▶ my( $line ) = @_;
Subroutine decode_FIX: called CC=1 SCAR=0.0
Pod undocumented
27 1 $line =~ s/^\s+//;
28 1 $line =~ s/\s+$//;
29  
30 1 return split /\s+/, $line;
31 }
32  
33 sub decode_PAC
34 {
35 2 ▶ my( $line ) = @_;
Subroutine decode_PAC: called CC=1 SCAR=0.0
Pod undocumented
36 2 $line =~ s/^\s+//;
37 2 $line =~ s/\s+$//;
38  
39 2 my @elements = $line =~ /([ +-]?\d+)/g;
40 2 return map { s/^[ +]//; $_ } @elements;
41 }
42  
43 sub decode_SQZ
44 {
45 125 ▶ my( $line ) = @_;
Subroutine decode_SQZ: called CC=1 SCAR=0.0
Pod undocumented
46 125 $line =~ s/\s+(\d)/+$1/g;
47 125 $line =~ s/\s+-/-/g;
48  
49 125 $line =~ s/\@/+0/g;
50 125 $line =~ s/([A-I])/'+' . (ord( $1 ) - ord( 'A' ) + 1)/ge;
51 125 $line =~ s/([a-i])/-ord( $1 ) + ord( 'a' ) - 1/ge;
52 125 return decode_DIF( $line );
53 }
54  
55 sub decode_DIF
56 {
57 126 ▶ my( $line ) = @_;
Subroutine decode_DIF: called CC=15 SCAR=29.3
Pod undocumented
58 126 my @elements;
59 126 ▶ while( $line ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 4039 126 4165
60 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
61 180 next;
62 } elsif( $line =~ s/^(-?\d+)// ) {
63 210 push @elements, int( $1 );
64 210 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 210 210
65 } elsif( $line =~ s/^%(\d*)// ) {
66 65 ▶ push @elements, $elements[-1] + ($1 ne '' ? $1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$1 ne '' ? : 0 65 65
67 65 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 65 65
68 } elsif( $line =~ s/^([J-R])(\d*)// ) {
69 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
70 ((ord( $1 ) - ord( 'J' ) + 1) . ($2 // ''));
71 2211 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 2211 2211
72 } elsif( $line =~ s/^([j-r])(\d*)// ) {
73 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
74 ((ord( $1 ) - ord( 'j' ) + 1) . ($2 // ''));
75 1373 ▶ print STDERR "got $& -> $elements[-1]\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $JCAMP::DX::ASDF::debug 0 1373 1373
76 } elsif( $line =~ s/^(.)// ) {
77 0 warn "unrecognised symbol: $1";
78 }
79 }
80 126 return @elements;
81 }
82  
83 sub decode_DIFDUP
84 {
85 124 ▶ my( $line ) = @_;
Subroutine decode_DIFDUP: called CC=1 SCAR=0.0
Pod undocumented
86 124 $line =~ s/(.)([S-Z])/$1 x ( ord( $2 ) - ord( 'S' ) + 1 )/ge;
87 124 $line =~ s/(.)s/$1 x 9/g;
88 124 return decode_SQZ( $line );
89 }
90  
91 sub decode
92 {
93 122 ▶ &decode_DIFDUP;
Subroutine decode: called CC=1 SCAR=0.0
Pod undocumented
94 }
95  
96 5 1;
↑ Summary DX.pm »