blib/lib/App/nauniq.pm

filter: Statementstmt 98.3% 60 / 61 Branchbran 93.1% 41 / 44 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 95.6% 111 / 116 CC 24 SCAR 29.5
CC
24
Cov
96%
run
23.0
__ANON__
2.0
BEGIN
1.0
CRAP 19.2
↑ Summary script/nauniq »
1 package App::nauniq;
2  
3 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 30 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7 30 our $DATE = '2025-09-24'; # DATE
8 30 our $DIST = 'App-nauniq'; # DIST
9 30 our $VERSION = '0.112'; # VERSION
10  
11 28 ▶sub run {
Subroutine run: called CC=23 SCAR=31.4
Pod undocumented
12 28 my %opts = @_;
13  
14 28 my $ifh; # input handle
15 28 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) { } 6 22 28
16 6 my $fname = shift @ARGV;
17 6 ▶ if ($fname eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fname eq '-') { } 4 2 6
18 4 $ifh = *STDIN;
19 } else {
20 2 ▶ open $ifh, "<", $fname or die "Can't open input file $fname: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $ifh, "<", $fname or die "Can't open input file ${fname}: $!\n" 2 0 2
21 }
22 } else {
23 22 $ifh = *STDIN;
24 }
25  
26 28 my $phase = 2;
27 28 my $ofh; # output handle
28 28 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) { } 5 23 28
29 5 my $fname = shift @ARGV;
30 5 ▶ if ($fname eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fname eq '-') { } 0 5 5
31 0 $ofh = *STDOUT;
32 } else {
33 open $ofh,
34 5 ▶ ($opts{read_output} ? "+" : "") . ($opts{append} ? ">>" : ">"),
Branch: 3 branches
BranchTrueFalseTotal
open $ofh, ($opts{"read_output"} ? "+" : "") . ($opts{"append"} ? ">>" : ">"), $fname or die "Can't open output file ${fname}: $!\n" 5 0 5
$opts{'read_output'} ? : 2 3 5
$opts{'append'} ? : 3 2 5
35 $fname
36 or die "Can't open output file $fname: $!\n";
37 5 ▶ if ($opts{read_output}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"read_output"}) 2 3 5
38 2 seek $ofh, 0, 0;
39 2 $phase = 1;
40 }
41 }
42 } else {
43 23 $ofh = *STDOUT;
44 }
45  
46 28 my ($line, $memkey);
47 28 my %mem;
48 29 ▶ my $sub_reset_mem = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
49 29 ▶ if ($opts{num_entries} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'num_entries'} > 0) { } 2 27 29
50 2 require Tie::Cache;
51 2 tie %mem, 'Tie::Cache', $opts{num_entries};
52 } else {
53 27 %mem = ();
54 }
55 28 };
56 28 $sub_reset_mem->();
57 28 ▶ require Digest::MD5 if $opts{md5};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"md5"} 1 27 28
58 30 ▶ no warnings; # we want to shut up 'substr outside of string'
Subroutine BEGIN: called CC=1 SCAR=0.0
59 28 while (1) {
60 179 ▶ if ($phase == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase == 1) { } 8 171 179
61 # phase 1 is just reading the output file
62 8 $line = <$ofh>;
63 8 ▶ if (!$line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line) 2 6 8
64 2 $phase = 2;
65 2 next;
66 }
67 } else {
68 171 $line = <$ifh>;
69 171 ▶ if (!$line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line) 28 143 171
70 28 last;
71 }
72 }
73 149 ▶ if ($opts{forget_pattern} && $line =~ $opts{forget_pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"forget_pattern"} and $line =~ /$opts{"forget_pattern"}/) 1 148 149
Condition100%3/3
$opts{"forget_pattern"} and $line =~ /$opts{"forget_pattern"}/
!ll&&!rl&&r
14261
MC/DC100%2/2
$opts{"forget_pattern"} and $line =~ /$opts{"forget_pattern"}/
$opts{"forget_pattern"} $line =~ /$opts{"forget_pattern"}/
Truth table100%3/3
A and B
A= $opts{"forget_pattern"}B= $line =~ /$opts{"forget_pattern"}/
ABresult
0X0
100
111
74 1 $sub_reset_mem->();
75 }
76  
77 $memkey = $opts{check_chars} > 0 ?
78 substr($line, $opts{skip_chars}, $opts{check_chars}) :
79 149 ▶ substr($line, $opts{skip_chars});
Branch: 1 branch
BranchTrueFalseTotal
$opts{'check_chars'} > 0 ? : 16 133 149
80 149 ▶ $memkey = lc($memkey) if $opts{ignore_case};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"ignore_case"} 10 139 149
81 149 ▶ $memkey = Digest::MD5::md5($memkey) if $opts{md5};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"md5"} 5 144 149
82  
83 149 ▶ if ($phase == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase == 2) 143 6 149
84 143 ▶ if ($mem{$memkey}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mem{$memkey}) { } 58 85 143
85 58 ▶ print $ofh $line if $opts{show_repeated};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"show_repeated"} 8 50 58
86 } else {
87 85 ▶ print $ofh $line if $opts{show_unique};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"show_unique"} 73 12 85
88 }
89 }
90  
91 149 $mem{$memkey} = 1;
92 }
93 }
94  
95  
96 30 1;
97 # ABSTRACT: Non-adjacent uniq
98  
99 __END__
↑ Summary script/nauniq »