blib/lib/Code/TidyAll/Util/Zglob.pm

filter: Statementstmt 80.7% 46 / 57 Branchbran 44.0% 22 / 50 Conditioncond 60.0% 18 / 30 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 58.7% 94 / 160 CC 37 SCAR 49.3
CC
37
Cov
63%
zglob_to_regex_string
165.2
zglobs_to_regex
2.0
BEGIN
1.0
CRAP 138.5
↑ Summary blib/lib/Code/TidyAll/Zglob.pm »
1 # This is a copy of Text::Glob, modified to support "**/"
2 #
3 package Code::TidyAll::Util::Zglob;
4  
5 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 our $VERSION = '0.83';
9  
10 35 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 35 our @EXPORT_OK = qw( zglobs_to_regex zglob_to_regex );
13  
14 35 our $strict_leading_dot = 1;
15 35 our $strict_wildcard_slash = 1;
16  
17 35 ▶use constant debug => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub zglobs_to_regex {
20 186 ▶ my @globs = @_;
Subroutine zglobs_to_regex: called CC=2 SCAR=6.9
Pod undocumented
21 return @globs
22 186 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
@globs ? : 101 85 186
23 101 my $re = join( '|', map { "(?:" . zglob_to_regex($_) . ")" } @globs );
24 101 qr/$re/;
25 }
26 : qr/(?!)/;
27 }
28  
29 sub zglob_to_regex {
30 104 ▶ my $glob = shift;
Subroutine zglob_to_regex: called CC=1 SCAR=0.0
Pod undocumented
31 104 my $regex = zglob_to_regex_string($glob);
32 104 return qr/^$regex$/;
33 }
34  
35 sub zglob_to_regex_string {
36 104 ▶ my $glob = shift;
Subroutine zglob_to_regex_string: called CC=36 SCAR=51.1
Pod undocumented
37 104 my ( $regex, $in_curlies, $escaping );
38 104 local $_;
39 104 my $first_byte = 1;
40 104 $glob =~ s/\*\*\//\cZ/g; # convert **/ to single character
41 104 for ( $glob =~ m/(.)/gs ) {
42 814 ▶ if ($first_byte) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_byte) 141 673 814
43 141 ▶ if ($strict_leading_dot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Code::TidyAll::Util::Zglob::strict_leading_dot) 141 0 141
44 141 ▶ $regex .= '(?=[^\.])' unless $_ eq '.';
Branch: 1 branch
BranchTrueFalseTotal
unless $_ eq "." 141 0 141
45 }
46 141 $first_byte = 0;
47 }
48 814 ▶ if ( $_ eq '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "/") 37 777 814
49 37 $first_byte = 1;
50 }
51 814 ▶ if ( $_ eq '.'
Branch: 8 branches
BranchTrueFalseTotal
if ($_ eq '.' or $_ eq '(' or $_ eq ')' or $_ eq '|' or $_ eq '+' or $_ eq '^' or $_ eq '$' or $_ eq '@' or $_ eq '%') { } 33 781 814
elsif ($_ eq "\cZ") { } 43 738 781
elsif ($_ eq '*') { } 104 634 738
elsif ($_ eq '?') { } 0 634 634
elsif ($_ eq '{') { } 0 634 634
elsif ($_ eq '}' and $in_curlies) { } 0 634 634
elsif ($_ eq ',' and $in_curlies) { } 0 634 634
elsif ($_ eq '\\') { } 0 634 634
Condition66%16/24
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|" or $_ eq "+" or $_ eq "^" or $_ eq "\$" or $_ eq "\@" or $_ eq "%"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|" or $_ eq "+" or $_ eq "^" or $_ eq "\$" or $_ eq "\@"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|" or $_ eq "+" or $_ eq "^" or $_ eq "\$"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|" or $_ eq "+" or $_ eq "^"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|" or $_ eq "+"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "(" or $_ eq ")"
l!l&&r!l&&!r
330781
$_ eq "." or $_ eq "("
l!l&&r!l&&!r
330781
MC/DC11%1/9
$_ eq "." or $_ eq "(" or $_ eq ")" or $_ eq "|" or $_ eq "+" or $_ eq "^" or $_ eq "\$" or $_ eq "\@" or $_ eq "%"
$_ eq "." $_ eq "(" $_ eq ")" $_ eq "|" $_ eq "+" $_ eq "^" $_ eq "\$" $_ eq "\@" $_ eq "%"
Truth table20%2/10
A or B or C or D or E or F or G or H or I
A= $_ eq "."B= $_ eq "("C= $_ eq ")"D= $_ eq "|"E= $_ eq "+"F= $_ eq "^"G= $_ eq "\$"H= $_ eq "\@"I= $_ eq "%"
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
52 || $_ eq '('
53 || $_ eq ')'
54 || $_ eq '|'
55 || $_ eq '+'
56 || $_ eq '^'
57 || $_ eq '$'
58 || $_ eq '@'
59 || $_ eq '%' ) {
60 33 $regex .= "\\$_";
61 }
62 elsif ( $_ eq "\cZ" ) { # handle **/ - if escaping, only escape first *
63 43 ▶ $regex
Branch: 2 branches
BranchTrueFalseTotal
$escaping ? : 0 43 43
$Code::TidyAll::Util::Zglob::strict_wildcard_slash ? : 0 0 0
64 .= $escaping
65 ? ( "\\*" . ( $strict_wildcard_slash ? "[^/]*" : ".*" ) . "/" )
66 : ".*";
67 }
68 elsif ( $_ eq '*' ) {
69 104 ▶ $regex
Branch: 2 branches
BranchTrueFalseTotal
$escaping ? : 0 104 104
$Code::TidyAll::Util::Zglob::strict_wildcard_slash ? : 104 0 104
70 .= $escaping ? "\\*"
71 : $strict_wildcard_slash ? "[^/]*"
72 : ".*";
73 }
74 elsif ( $_ eq '?' ) {
75 0 ▶ $regex
Branch: 2 branches
BranchTrueFalseTotal
$escaping ? : 0 0 0
$Code::TidyAll::Util::Zglob::strict_wildcard_slash ? : 0 0 0
76 .= $escaping ? "\\?"
77 : $strict_wildcard_slash ? "[^/]"
78 : ".";
79 }
80 elsif ( $_ eq '{' ) {
81 0 ▶ $regex .= $escaping ? "\\{" : "(";
Branch: 1 branch
BranchTrueFalseTotal
$escaping ? : 0 0 0
82 0 ▶ ++$in_curlies unless $escaping;
Branch: 1 branch
BranchTrueFalseTotal
unless $escaping 0 0 0
83 }
84 ▶ elsif ( $_ eq '}' && $in_curlies ) {
Condition33%1/3
$_ eq "}" and $in_curlies
!ll&&!rl&&r
63400
MC/DC0%0/2
$_ eq "}" and $in_curlies
$_ eq "}" $in_curlies
Truth table33%1/3
A and B
A= $_ eq "}"B= $in_curlies
ABresult
0X0
100
111
85 0 ▶ $regex .= $escaping ? "}" : ")";
Branch: 1 branch
BranchTrueFalseTotal
$escaping ? : 0 0 0
86 0 ▶ --$in_curlies unless $escaping;
Branch: 1 branch
BranchTrueFalseTotal
unless $escaping 0 0 0
87 }
88 ▶ elsif ( $_ eq ',' && $in_curlies ) {
Condition33%1/3
$_ eq "," and $in_curlies
!ll&&!rl&&r
63400
MC/DC0%0/2
$_ eq "," and $in_curlies
$_ eq "," $in_curlies
Truth table33%1/3
A and B
A= $_ eq ","B= $in_curlies
ABresult
0X0
100
111
89 0 ▶ $regex .= $escaping ? "," : "|";
Branch: 1 branch
BranchTrueFalseTotal
$escaping ? : 0 0 0
90 }
91 elsif ( $_ eq "\\" ) {
92 0 ▶ if ($escaping) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escaping) { } 0 0 0
93 0 $regex .= "\\\\";
94 0 $escaping = 0;
95 }
96 else {
97 0 $escaping = 1;
98 }
99 0 next;
100 }
101 else {
102 634 $regex .= $_;
103 634 $escaping = 0;
104 }
105 814 $escaping = 0;
106 }
107 104 print "# $glob $regex\n" if debug;
108  
109 104 return $regex;
110 }
111  
112 35 1;
113  
114 # ABSTRACT: Test::Glob hacked up to support "**/*"
115  
116 __END__
117  
118 =pod
119  
120 =encoding UTF-8
121  
122 =head1 NAME
123  
124 Code::TidyAll::Util::Zglob - Test::Glob hacked up to support "**/*"
125  
126 =head1 VERSION
127  
128 version 0.83
129  
130 =head1 SUPPORT
131  
132 Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>.
133  
134 =head1 SOURCE
135  
136 The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>.
137  
138 =head1 AUTHORS
139  
140 =over 4
141  
142 =item *
143  
144 Jonathan Swartz <swartz@pobox.com>
145  
146 =item *
147  
148 Dave Rolsky <autarch@urth.org>
149  
150 =back
151  
152 =head1 COPYRIGHT AND LICENSE
153  
154 This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
155  
156 This is free software; you can redistribute it and/or modify it under
157 the same terms as the Perl 5 programming language system itself.
158  
159 The full text of the license can be found in the
160 F<LICENSE> file included with this distribution.
161  
162 =cut
↑ Summary blib/lib/Code/TidyAll/Zglob.pm »