Login
Make sub _parse_private_name_regex() the parser for parameter
[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
186
187##############################################################################
188# $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic/t/Subroutines/ProtectPrivateSubs.run $
189# $Date: 2009-03-01 13:21:29 -0500 (Sun, 01 Mar 2009) $
190# $Author: clonezone $
191# $Revision: 3194 $
192##############################################################################
193
194# Local Variables:
195# mode: cperl
196# cperl-indent-level: 4
197# fill-column: 78
198# indent-tabs-mode: nil
199# c-indentation-style: bsd
200# End:
201# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :