lib/App/Greple/Util.pm

filter: Statementstmt 46.7% 29 / 62 Branchbran 16.6% 3 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 44.4% 8 / 18 Podpod 0.0% 0 / 1 totaltotal 36.7% 40 / 109 CC 13 SCAR 39.0
CC
13
Cov
37%
index
132.0
new
2.0
shellquote
2.0
CRAP 49.5
« lib/App/Greple/find.pm ↑ Summary script/greple »
1 package App::Greple::Util;
2  
3 171 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 171 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 171 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 171 our @EXPORT_OK = qw(shellquote);
8  
9 171 ▶use App::Greple::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ##
12 ## easy implementation. don't be serious.
13 ##
14 0 ▶sub shellquote {
Subroutine shellquote: not called CC=1 SCAR=6.9
Pod undocumented
15 0 state $option = qr/-++[-:\w]+=/;
16 0 state $special = qr/[\s\\(){}\|\*?]/;
17 0 map { s/^(${option}?)(.*${special}.*)\z/$1\'$2\'/sr } @_;
18 }
19  
20 package #
21 UniqIndex
22 171 {
23 171 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 171 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 166 ▶ sub new {
Subroutine new: called CC=2 SCAR=7.0
27 166 my $class = shift;
28 166 my $obj = bless {
29 HASH => {},
30 LIST => [],
31 COUNT => [],
32 }, $class;
33 166 ▶ $obj->configure(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 166 0 166
34 166 $obj;
35 }
36  
37 0 ▶ sub hash { shift->{HASH} }
Subroutine hash: not called CC=1 SCAR=6.9
38 0 ▶ sub list { shift->{LIST} }
Subroutine list: not called CC=1 SCAR=6.9
39 0 ▶ sub count { shift->{COUNT} }
Subroutine count: not called CC=1 SCAR=6.9
40  
41 166 ▶ sub configure {
Subroutine configure: called CC=2 SCAR=6.9
42 166 my $obj = shift;
43 166 ▶ while (@_ >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) 332 166 498
44 332 $obj->{$_[0]} = $_[1];
45 332 splice @_, 0, 2;
46 }
47 }
48  
49 0 ▶ sub index {
Subroutine index: not called CC=11 SCAR=48.8
50 0 ▶ my $opt = ref $_[0] eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
51 0 my $obj = shift;
52 0 local $_ = shift;
53  
54 0 ▶ my $index = $obj->{HASH}->{$_} //= do {
Condition0%0/3
$obj->{"HASH"}{$_} //= do { if (my $prepare = $obj->{"prepare"}) { foreach my $sub (@$prepare) { $_ = $sub->call; } ; } ; s/\n+//gu if $obj->{"ignore_newline"}; s/\s+//gu if $obj->{"ignore_space"}; s/\pS+//gu if $obj->{"ignore_symbol"}; s/\pP+//gu if $obj->{"ignore_punct"}; $_ = lc $_ if $obj->{"ignore_case"}; $obj->{"HASH"}{$_} //= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj->{"HASH"}{$_} //= do { if (my $prepare = $obj->{"prepare"}) { foreach my $sub (@$prepare) { $_ = $sub->call; } ; } ; s/\n+//gu if $obj->{"ignore_newline"}; s/\s+//gu if $obj->{"ignore_space"}; s/\pS+//gu if $obj->{"ignore_symbol"}; s/\pP+//gu if $obj->{"ignore_punct"}; $_ = lc $_ if $obj->{"ignore_case"}; $obj->{"HASH"}{$_} //= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} } }
$obj->{"HASH"}{$_} do { if (my $prepare = $obj->{"prepare"}) { foreach my $sub (@$prepare) { $_ = $sub->call; } ; } ; s/\n+//gu if $obj->{"ignore_newline"}; s/\s+//gu if $obj->{"ignore_space"}; s/\pS+//gu if $obj->{"ignore_symbol"}; s/\pP+//gu if $obj->{"ignore_punct"}; $_ = lc $_ if $obj->{"ignore_case"}; $obj->{"HASH"}{$_} //= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} } }
Truth table0%0/3
A //= B
A= $obj->{"HASH"}{$_}B= do { if (my $prepare = $obj->{"prepare"}) { foreach my $sub (@$prepare) { $_ = $sub->call; } ; } ; s/\n+//gu if $obj->{"ignore_newline"}; s/\s+//gu if $obj->{"ignore_space"}; s/\pS+//gu if $obj->{"ignore_symbol"}; s/\pP+//gu if $obj->{"ignore_punct"}; $_ = lc $_ if $obj->{"ignore_case"}; $obj->{"HASH"}{$_} //= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} } }
ABresult
1X1
011
000
55 0 ▶ if (my $prepare = $obj->{prepare}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prepare = $obj->{"prepare"}) 0 0 0
56 0 for my $sub (@$prepare) {
57 0 $_ = $sub->call();
58 }
59 }
60 0 ▶ s/\n+//g if $obj->{ignore_newline};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"ignore_newline"} 0 0 0
61 0 ▶ s/\s+//g if $obj->{ignore_space};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"ignore_space"} 0 0 0
62 0 ▶ s/\pS+//g if $obj->{ignore_symbol};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"ignore_symbol"} 0 0 0
63 0 ▶ s/\pP+//g if $obj->{ignore_punct};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"ignore_punct"} 0 0 0
64 0 ▶ $_ = lc($_) if $obj->{ignore_case};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"ignore_case"} 0 0 0
65 0 ▶ $obj->{HASH}->{$_} //= do {
Condition0%0/3
$obj->{"HASH"}{$_} //= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} }
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj->{"HASH"}{$_} //= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} }
$obj->{"HASH"}{$_} do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} }
Truth table0%0/3
A //= B
A= $obj->{"HASH"}{$_}B= do { my $list = $obj->{"LIST"}; push @$list, $_; $#{$list;} }
ABresult
1X1
011
000
66 0 my $list = $obj->{LIST};
67 0 push @$list, $_;
68 0 $#{ $list };
69 };
70 };
71  
72 0 $obj->{COUNT}->[$index] += 1;
73  
74 0 $index;
75 }
76 }
77  
78 package #
79 Indexer
80 171 {
81 0 ▶ sub new {
Subroutine new: not called CC=1 SCAR=6.9
82 0 my $class = shift;
83 0 my $obj = { @_ };
84 0 bless $obj, $class;
85 }
86 0 ▶ sub index { shift->{index}->() }
Subroutine index: not called CC=1 SCAR=6.9
87 0 ▶ sub reset { shift->{reset}->() }
Subroutine reset: not called CC=1 SCAR=6.9
88 0 ▶ sub block { shift->{block} }
Subroutine block: not called CC=1 SCAR=6.9
89 0 ▶ sub reverse { shift->{reverse} }
Subroutine reverse: not called CC=1 SCAR=6.9
90 }
91  
92 171 1;
« lib/App/Greple/find.pm ↑ Summary script/greple »