lib/Net/SinFP3/Input/Signature.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 130 CC 9 SCAR 38.8
CC
9
Cov
0%
_parseSignature
90.0
new
2.0
run
2.0
CRAP 48.6
1 #
2 # $Id: Signature.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $
3 #
4 package Net::SinFP3::Input::Signature;
5 use strict;
6 use warnings;
7  
8 use base qw(Net::SinFP3::Input);
9 __PACKAGE__->cgBuildIndices;
10  
11 use Net::SinFP3::Ext::S;
12 use Net::SinFP3::Next::Active;
13  
14 use Data::Dumper;
15  
16 sub new {
17 my $self = shift->SUPER::new(
18 @_,
19 );
20  
21 return $self;
22 }
23  
24 sub run {
25 my $self = shift->SUPER::run(@_) or return;
26  
27 # We only have one next object
28 $self->last(1);
29  
30 my $p = $self->_parseSignature();
31  
32 return Net::SinFP3::Next::Active->new(
33 global => $self->global,
34 s1 => Net::SinFP3::Ext::S->new(%{$p->[0]}),
35 s2 => Net::SinFP3::Ext::S->new(%{$p->[1]}),
36 s3 => Net::SinFP3::Ext::S->new(%{$p->[2]}),
37 );
38 }
39  
40 sub _parseSignature {
41 my $self = shift;
42  
43 my $log = $self->global->log;
44  
45 print "Please enter active signature:\n";
46 my @lines = ();
47 while (<>) {
48 chomp;
49 push @lines, $_;
50 }
51  
52 my $buf = join('', @lines);
53 if (! defined($buf) || ! length($buf)) {
54 $log->fatal("No input given");
55 }
56  
57 my $patternsS1;
58 my $patternsS2;
59 my $patternsS3;
60 for my $line (@lines) {
61 #$log->debug("LINE[$line]");
62 if ($line =~ m/^\s*S1:\s*(B.*?F.*?W.*?O.*?M.*?S.*?L.*).*?$/s) {
63 $patternsS1 = $1;
64 }
65 elsif ($line =~ m/^\s*S2:\s*(B.*?F.*?W.*?O.*?M.*?S.*?L.*).*?$/s) {
66 $patternsS2 = $1;
67 }
68 elsif ($line =~ m/^\s*S3:\s*(B.*?F.*?W.*?O.*?M.*?S.*?L.*).*?$/s) {
69 $patternsS3 = $1;
70 }
71 }
72  
73 $log->debug("patternsS1[$patternsS1]");
74 $log->debug("patternsS2[$patternsS2]");
75 $log->debug("patternsS3[$patternsS3]");
76  
77 if ((! defined($patternsS1) || ! length($patternsS1))
78 || (! defined($patternsS2) || ! length($patternsS2))
79 || (! defined($patternsS3) || ! length($patternsS3))) {
80 $log->fatal("No valid active signature found in given string");
81 }
82  
83 $log->debug("[$patternsS1]");
84 $log->debug("[$patternsS2]");
85 $log->debug("[$patternsS3]");
86  
87 my @patternsS1 = split(/\s+/, $patternsS1);
88 my @patternsS2 = split(/\s+/, $patternsS2);
89 my @patternsS3 = split(/\s+/, $patternsS3);
90  
91 if (@patternsS1 < 6) {
92 $log->fatal("patternsS1: ",Dumper(\@patternsS1));
93 }
94 if (@patternsS2 < 6) {
95 $log->fatal("patternsS2: ",Dumper(\@patternsS2));
96 }
97 if (@patternsS3 < 6) {
98 $log->fatal("patternsS3: ",Dumper(\@patternsS3));
99 }
100  
101 my $s1 = {
102 B => $patternsS1[0],
103 F => $patternsS1[1],
104 W => $patternsS1[2],
105 O => $patternsS1[3],
106 M => $patternsS1[4],
107 S => $patternsS1[5],
108 L => $patternsS1[6],
109 };
110  
111 my $s2 = {
112 B => $patternsS2[0],
113 F => $patternsS2[1],
114 W => $patternsS2[2],
115 O => $patternsS2[3],
116 M => $patternsS2[4],
117 S => $patternsS2[5],
118 L => $patternsS2[6],
119 };
120  
121 my $s3 = {
122 B => $patternsS3[0],
123 F => $patternsS3[1],
124 W => $patternsS3[2],
125 O => $patternsS3[3],
126 M => $patternsS3[4],
127 S => $patternsS3[5],
128 L => $patternsS3[6],
129 };
130  
131 return [ $s1, $s2, $s3 ];
132 }
133  
134 1;
135  
136 __END__