Login
RT #61311: Subroutines::ProhibitUnusedPrivateSubroutines dies on
[gknop/Perl-Critic.git] / t / Subroutines / ProhibitUnusedPrivateSubroutines.run
CommitLineData
6ddbc15f
TW
1## name basic failure
2## failures 1
3## cut
4
5sub _foo {};
6
7#-----------------------------------------------------------------------------
8
9## name basic pass
10## failures 0
11## cut
12
13sub _foo {};
14_foo;
15
16#-----------------------------------------------------------------------------
17
18## name Method call is OK
19## failures 0
20## cut
21
22sub _foo {};
23$self->_foo();
24
25#-----------------------------------------------------------------------------
26
27## name Method call where invocant is "shift"
28## failures 0
29## cut
30
31sub _foo {};
32shift->_foo;
33
34#-----------------------------------------------------------------------------
35
36## name other builtin-function followed by private method call
37## failures 0
38## cut
39
40sub _foo {};
41pop->_foo();
42
43#-----------------------------------------------------------------------------
44
45## name Maybe non-obvious failure
46## failures 1
47## cut
48
49sub _foo {};
50
51$self->SUPER::_foo();
52
53#-----------------------------------------------------------------------------
54
55## name Forward references do not count
56## failures 0
57## cut
58
59sub _foo;
60
61#-----------------------------------------------------------------------------
62
63## name User-configured exceptions.
64## parms { allow => '_foo _bar _baz' }
65## failures 0
66## cut
67
68sub _foo {};
69sub _bar ($) {};
70sub _baz : method {};
71
72#-----------------------------------------------------------------------------
73
74## name private_name_regex passing
75## failures 0
76## parms { private_name_regex => '_(?!_|parse_)\w+' }
77## cut
78
79sub __foo {};
80sub __bar ($) {};
81sub __baz : method {};
82sub _parse_my_argument {};
83
84#-----------------------------------------------------------------------------
85
86## name private_name_regex failure
87## failures 3
88## parms { private_name_regex => '_(?!_)\w+' }
89## cut
90
91sub _foo {};
92sub _bar ($) {};
93sub _baz : method {};
94
95#-----------------------------------------------------------------------------
96
97## name reference to private subroutine
98## failures 0
99## cut
100
101sub _foo {};
102my $bar = \&_foo;
103
104#-----------------------------------------------------------------------------
105
106## name goto to private subroutine
107## failures 0
108## cut
109
110sub _foo {};
111sub bar {
112 goto &_foo;
113}
114
115#-----------------------------------------------------------------------------
116
117## name private subroutine used in overload
118## failures 0
119## cut
120
121use overload ( cmp => '_compare' );
122sub _compare {};
123
124#-----------------------------------------------------------------------------
125
126## name private subroutine used in overload, the bad way
127## failures 0
128## cut
129
130use overload ( cmp => _compare => foo => 'bar' );
131sub _compare {};
132
133#-----------------------------------------------------------------------------
134
135## name private subroutine used in overload, by reference
136## failures 0
137## cut
138
139use overload ( cmp => \&_compare );
140sub _compare {};
141
142#-----------------------------------------------------------------------------
143
144## name recursive but otherwise unused subroutine
145## failures 2
146## cut
147
148sub _foo {
149 my ( $arg ) = @_;
150 return $arg <= 1 ? $arg : $arg * _foo( $arg - 1 );
151}
152
153sub _bar {
154 --$_[0] > 0 and goto &_bar;
155 return $_[0];
156}
157
158#-----------------------------------------------------------------------------
159
160## name recursive subroutine called outside itself
161## failures 0
162## cut
163
164_foo( 3 );
165sub _foo {
166 my ( $arg ) = @_;
167 return $arg <= 1 ? $arg : $arg * _foo( $arg - 1 );
168}
169
170_bar( 1.3 );
171sub _bar {
172 --$_[0] > 0 and goto &_bar;
173 return $_[0];
174}
175
176#-----------------------------------------------------------------------------
177
178## name subroutine declared in someone else's name space
179## failures 0
180## cut
181
182sub _Foo::_foo {}
183
184#-----------------------------------------------------------------------------
185
f3f01a25
TW
186## name Subroutine called in replacement portion of s/.../.../e
187## failures 0
188## cut
189
190s/ ( foo ) / _bar( $1 ) /smxe;
191
192sub _bar {
193 my ( $foo ) = @_;
194 return $foo x 3;
195}
196
197#-----------------------------------------------------------------------------
198
199## name Subroutine called in regexp interpolation
200## failures 0
201## cut
202
203s/ ( foo ) /@{[ _bar( $1 ) ]}/smx;
204
205sub _bar {
206 my ( $foo ) = @_;
207 return $foo x 3;
208}
209
210#-----------------------------------------------------------------------------
211
212## name Subroutine called in regexp embedded code
213## failures 0
214## cut
215
216m/ (?{ _foo() }) /smx;
217
218sub _foo {
219 return 'bar';
220}
221
222#-----------------------------------------------------------------------------
223
2e31b804
TW
224## name RT 61311: dies on "&_name" call
225## failures 0
226## cut
227
228sub first {
229 &_second();
230}
231
232sub _second {
233 print "A private sub\n";
234}
235
236#-----------------------------------------------------------------------------
237
6ddbc15f
TW
238
239##############################################################################
2dccb78c
TW
240# $URL$
241# $Date$
242# $Author$
243# $Revision$
6ddbc15f
TW
244##############################################################################
245
246# Local Variables:
247# mode: cperl
248# cperl-indent-level: 4
249# fill-column: 78
250# indent-tabs-mode: nil
251# c-indentation-style: bsd
252# End:
253# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :