402057fcb875e38e58d767618133caf3731311c7
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / RegularExpressions / ProhibitCaptureWithoutTest.run
1 ## name use without regex
2 ## failures 3
3 ## cut
4 my $foo = $1;
5 my @matches = ($1, $2);
6
7 #-----------------------------------------------------------------------------
8
9 ## name void use without regex
10 ## failures 1
11 ## cut
12 $1
13
14 #-----------------------------------------------------------------------------
15
16 ## name regex but no check on success
17 ## failures 1
18 ## cut
19 'some string' =~ m/(s)/;
20 my $s = $1;
21
22 #-----------------------------------------------------------------------------
23
24 ## name inside a checkblock, but another regex overrides
25 ## failures 1
26 ## cut
27 if (m/(.)/) {
28    'some string' =~ m/(s)/;
29    my $s = $1;
30 }
31
32 #-----------------------------------------------------------------------------
33
34 ## name good passes
35 ## failures 0
36 ## cut
37 if ($str =~ m/(.)/) {
38    return $1;
39 }
40 elsif ($foo =~ s/(b)//) {
41    $bar = $1;
42 }
43
44 if ($str =~ m/(.)/) {
45    while (1) {
46       return $1;
47    }
48 }
49
50 while ($str =~ m/\G(.)/cg) {
51    print $1;
52 }
53
54 print $0; # not affected by policy
55 print $_; # not affected by policy
56 print $f1; # not affected by policy
57
58 my $result = $str =~ m/(.)/;
59 if ($result) {
60    return $1;
61 }
62
63 #-----------------------------------------------------------------------------
64
65 ## name ternary passes
66 ## failures 0
67 ## cut
68 print m/(.)/ ? $1 : 'undef';
69 print !m/(.)/ ? 'undef' : $1;
70 print s/(.)// ? $1 : 'undef';
71 print !s/(.)// ? 'undef' : $1;
72 $foo = m/(.)/ && $1;
73 $foo = !m/(.)/ || $1;
74 $foo = s/(.)// && $1;
75 $foo = !s/(.)// || $1;
76
77 #-----------------------------------------------------------------------------
78
79 ## name Regression for PPI::Statement::Expressions
80 ## failures 0
81 ## cut
82
83 if (m/(\d+)/xms) {
84    $foo = ($1);
85 }
86
87 #-----------------------------------------------------------------------------
88
89 ## name Regression for ternaries with structures
90 ## failures 0
91 ## cut
92
93 $str =~ m/(.)/xms ? foo($1) : die;
94 $str =~ m/(.)/xms ? [$1] : die;
95 $str =~ m/(.)/xms ? { match => $1 } : die;