1use strict;
2use warnings;
3use Perl::Lint::Policy::ValuesAndExpressions::ProhibitMagicNumbers;
4use t::Policy::Util qw/fetch_violations/;
5use Test::Base::Less;
6
7my $class_name = 'ValuesAndExpressions::ProhibitMagicNumbers';
8
9filters {
10    params => [qw/eval/],
11};
12
13for my $block (blocks) {
14    my $violations = fetch_violations($class_name, $block->input, $block->params);
15    is scalar @$violations, $block->failures, $block->dscr;
16}
17
18done_testing;
19
20__DATA__
21
22===
23--- dscr: Version numbers allowed in use statements.
24--- failures: 0
25--- params:
26--- input
27use 5.8.1;
28
29===
30--- dscr: Version numbers allowed in require statements.
31--- failures: 0
32--- params:
33--- input
34require 5.8.1;
35
36===
37--- dscr: Version numbers not allowed in regular statements.
38--- failures: 1
39--- params:
40--- input
41$Aleax = 5.8.1;
42
43===
44--- dscr: All numbers are allowed on any use statement.
45--- failures: 0
46--- params:
47--- input
48use Test::More plan => 57;
49
50===
51--- dscr: Numbers allowed on plan statements.
52--- failures: 0
53--- params:
54--- input
55plan tests => 2349;
56
57===
58--- dscr: Decimal zero is allowed anywhere.
59--- failures: 0
60--- params:
61--- input
62$tangle_tree = 0;
63
64===
65--- dscr: Floating-point zero is allowed anywhere.
66--- failures: 0
67--- params:
68--- input
69$xiron_golem = 0.0
70
71===
72--- dscr: Decimal one is allowed anywhere.
73--- failures: 0
74--- params:
75--- input
76$killer_tomato = 1;
77
78===
79--- dscr: Floating-point one is allowed anywhere.
80--- failures: 0
81--- params:
82--- input
83$witch_doctor = 1.0;
84
85===
86--- dscr: Decimal two is allowed anywhere.
87--- failures: 0
88--- params:
89--- input
90$gold_golem = 2;
91
92===
93--- dscr: Floating-point two is allowed anywhere.
94--- failures: 0
95--- params:
96--- input
97$lich = 2.0;
98
99===
100--- dscr: Fractional numbers not allowed in regular statements.
101--- failures: 1
102--- params:
103--- input
104$soldier = 2.5;
105
106===
107--- dscr: Negative one is not allowed by default.
108--- failures: 1
109--- params:
110--- input
111$giant_pigmy = -1;
112
113===
114--- dscr: The answer to life, the universe, and everything is not allowed in regular statements.
115--- failures: 1
116--- params:
117--- input
118$frobnication_factor = 42;
119
120===
121--- dscr: The answer to life, the universe, and everything is allowed as a constant.
122--- failures: 0
123--- params:
124--- input
125use constant FROBNICATION_FACTOR => 42;
126
127===
128--- dscr: Fractional numbers are allowed as a constant.
129--- failures: 0
130--- params:
131--- input
132use constant FROBNICATION_FACTOR => 1_234.567_89;
133
134===
135--- dscr: The Readonly subroutine works.
136--- failures: 0
137--- params:
138--- input
139use Readonly;
140
141Readonly $frobnication_factor => 57;
142
143===
144--- dscr: The Readonly::Scalar subroutine works.
145--- failures: 0
146--- params:
147--- input
148use Readonly;
149
150Readonly::Scalar $frobnication_factor => 57;
151
152===
153--- dscr: The Readonly::Scalar1 subroutine does work if allow_to_the_right_of_a_fat_comma is set.
154--- failures: 0
155--- params:
156--- input
157use Readonly;
158
159Readonly::Scalar1 $frobnication_factor => 57;
160
161===
162--- dscr: The Readonly::Scalar1 subroutine does not work if allow_to_the_right_of_a_fat_comma is not set.
163--- failures: 1
164--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
165--- input
166use Readonly;
167
168Readonly::Scalar1 $frobnication_factor => 57;
169
170===
171--- dscr: The Readonly::Array subroutine works.
172--- failures: 0
173--- params:
174--- input
175use Readonly;
176
177Readonly::Array @frobnication_factors => ( 57, 193, 49675 );
178
179===
180--- dscr: The Readonly::Array1 subroutine does not work.
181--- failures: 3
182--- params:
183--- input
184use Readonly;
185
186Readonly::Array1 @frobnication_factors => ( 57, 193, 49675 );
187
188===
189--- dscr: The Readonly::Hash subroutine works.
190--- failures: 0
191--- params:
192--- input
193use Readonly;
194
195Readonly::Hash %frobnication_factors => ( 57 => 290 );
196
197===
198--- dscr: The Readonly::Hash1 subroutine does work if allow_to_the_right_of_a_fat_comma is set.
199--- failures: 0
200--- params:
201--- input
202use Readonly;
203
204Readonly::Hash1 %frobnication_factors => ( quhh => 290 );
205
206===
207--- dscr: The Readonly::Hash1 subroutine does not work if allow_to_the_right_of_a_fat_comma is not set.
208--- failures: 1
209--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
210--- input
211use Readonly;
212
213Readonly::Hash1 %frobnication_factors => ( quhh => 290 );
214
215===
216--- dscr: Const::Fast works even if allow_to_the_right_of_a_fat_comma is not set.
217--- failures: 0
218--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
219--- input
220use Const::Fast;
221
222const my $frobnication_factor => 57;
223
224===
225--- dscr: Constant subroutines containing just a number are allowed.
226--- failures: 0
227--- params:
228--- input
229sub constant_subroutine { 104598 }
230
231===
232--- dscr: Constant subroutines containing "return" and a number are allowed.
233--- failures: 0
234--- params:
235--- input
236sub constant_subroutine { return 9068; }
237
238===
239--- dscr: Subroutines that contain something other than a constant return value are not allowed.
240--- failures: 1
241--- params:
242--- input
243sub constant_subroutine {
244    print 'blah';
245    return 9068;
246}
247
248===
249--- dscr: Subroutines that contain something other than a constant return value are not allowed with implicit.
250--- failures: 1
251--- params:
252--- input
253sub constant_subroutine {
254    print 'blah';
255    9068;
256}
257
258===
259--- dscr: Magic numbers not allowed in ranges.
260--- failures: 1
261--- params:
262--- input
263foreach my $solid (1..5) {
264    frobnicate($solid);
265}
266
267===
268--- dscr: Readonly numbers allowed in ranges.
269--- failures: 0
270--- params:
271--- input
272use Readonly;
273
274Readonly my $REGULAR_GEOMETRIC_SOLIDS => 5;
275
276foreach my $solid (1..$REGULAR_GEOMETRIC_SOLIDS) {
277    frobnicate($solid);
278}
279
280===
281--- dscr: Binary zero isn't allowed in regular statements.
282--- failures: 1
283--- params:
284--- input
285$battlemech = 0b0;
286
287===
288--- dscr: Readonly binary zero is allowed.
289--- failures: 0
290--- params:
291--- input
292Readonly $giant_eel => 0b0;
293
294===
295--- dscr: Binary one isn't allowed in regular statements.
296--- failures: 1
297--- params:
298--- input
299$xeroc = 0b1;
300
301===
302--- dscr: Readonly binary one is allowed.
303--- failures: 0
304--- params:
305--- input
306Readonly $creeping_coins => 0b1;
307
308===
309--- dscr: Octal zero isn't allowed in regular statements.
310--- failures: 1
311--- params:
312--- input
313$basilisk = 000;
314
315===
316--- dscr: Readonly octal zero is allowed.
317--- failures: 0
318--- params:
319--- input
320Readonly $dwarf_lord => 000;
321
322===
323--- dscr: Octal one isn't allowed in regular statements.
324--- failures: 1
325--- params:
326--- input
327$brown_mold = 001;
328
329===
330--- dscr: Readonly octal one is allowed.
331--- failures: 0
332--- params:
333--- input
334Readonly $kobold_zombie => 001;
335
336===
337--- dscr: Hexadecimal zero isn't allowed in regular statements.
338--- failures: 1
339--- params:
340--- input
341$yeti = 0x00;
342
343===
344--- dscr: Readonly hexadecimal zero is allowed.
345--- failures: 0
346--- params:
347--- input
348Readonly $newt => 0x00;
349
350===
351--- dscr: Hexadecimal one isn't allowed in regular statements.
352--- failures: 1
353--- params:
354--- input
355$piranha = 0x01;
356
357===
358--- dscr: Readonly hexadecimal one is allowed.
359--- failures: 0
360--- params:
361--- input
362Readonly $Lord_Surtur => 0x01;
363
364===
365--- dscr: Exponential zero isn't allowed in regular statements.
366--- failures: 1
367--- params:
368--- input
369$Green_elf = 0e0;
370
371===
372--- dscr: Readonly exponential zero is allowed.
373--- failures: 0
374--- params:
375--- input
376Readonly $sasquatch => 0e0;
377
378===
379--- dscr: Exponential one isn't allowed in regular statements.
380--- failures: 1
381--- params:
382--- input
383$Uruk_hai = 1e0;
384
385===
386--- dscr: Readonly exponential one is allowed.
387--- failures: 0
388--- params:
389--- input
390Readonly $leather_golem => 1e0;
391
392===
393--- dscr: Any numbers allowed in array references in use statement.
394--- failures: 0
395--- params:
396--- input
397use Some::Module [ 1, 2, 3, 4 ];
398
399===
400--- dscr: Any numbers allowed in array references in require statement.
401--- failures: 0
402--- params:
403--- input
404require Some::Other::Module [ 1, 2, 3, 4 ];
405
406===
407--- dscr: Any numbers allowed in array references in readonly statement.
408--- failures: 0
409--- params:
410--- input
411Readonly $Totoro => [ 1, 2, 3, 4 ];
412
413===
414--- dscr: Magic numbers not allowed in array references in regular statement.
415--- failures: 2
416--- params:
417--- input
418$Evil_Iggy = [ 1, 2, 3, 4 ];
419
420===
421--- dscr: Array references containing only good numbers are allowed (by this policy).
422--- failures: 0
423--- params:
424--- input
425$titanothere = [ 1, 0, 1, 0 ];
426
427===
428--- dscr: Any numbers allowed in hash references in use statement.
429--- failures: 0
430--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
431--- input
432use Some::Module { a => 6, b => 4 };
433
434===
435--- dscr: Any numbers allowed in hash references in require statement.
436--- failures: 0
437--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
438--- input
439require Some::Other::Module { a => 6, b => 4 };
440
441===
442--- dscr: Any numbers allowed in hash references in readonly statement.
443--- failures: 0
444--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
445--- input
446Readonly $Vlad_the_Impaler => { a => 6, b => 4 };
447
448===
449--- dscr: Magic numbers allowed in hash references in regular statement if allow_to_the_right_of_a_fat_comma is set.
450--- failures: 0
451--- params:
452--- input
453$gnome_lord = { a => 6, b => 4 };
454
455===
456--- dscr: Magic numbers not allowed in hash references in regular statement if allow_to_the_right_of_a_fat_comma is not set.
457--- failures: 2
458--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
459--- input
460$gnome_lord = { a => 6, b => 4 };
461
462===
463--- dscr: Hash references containing only good numbers are allowed (by this policy).
464--- failures: 0
465--- params:
466--- input
467$aardvark = { 1 => 0, 0 => 1 };
468
469===
470--- dscr: Any numbers allowed in lists in use statement.
471--- failures: 0
472--- params:
473--- input
474use Some::Module ( 1, 2, 3, 4 );
475
476===
477--- dscr: Any numbers allowed in lists in require statement.
478--- failures: 0
479--- params:
480--- input
481require Some::Other::Module ( 1, 2, 3, 4 );
482
483===
484--- dscr: Any numbers allowed in lists in readonly statement.
485--- failures: 0
486--- params:
487--- input
488Readonly @elf_mummy => ( 1, 2, 3, 4 );
489
490===
491--- dscr: Magic numbers not allowed in lists in regular statement.
492--- failures: 2
493--- params:
494--- input
495@kitten = ( 1, 2, 3, 4 );
496
497===
498--- dscr: Lists containing only good numbers are allowed (by this policy).
499--- failures: 0
500--- params:
501--- input
502@purple_worm = ( 1, 0, 1, 0 );
503
504===
505--- dscr: Magic numbers not allowed in nested lists in regular statement.
506--- failures: 2
507--- params:
508--- input
509@quivering_blob = ( 1, ( 2, 3, 4 ) );
510
511===
512--- dscr: Magic numbers not allowed in nested array references in regular statement.
513--- failures: 2
514--- params:
515--- input
516@green_slime = ( 1, [ 2, 3, 4 ] );
517
518===
519--- dscr: Magic numbers allowed in nested hash references in regular statement if allow_to_the_right_of_a_fat_comma is set.
520--- failures: 0
521--- params:
522--- input
523@fire_elemental = ( 1, { 2 => 4 } );
524
525===
526--- dscr: Magic numbers not allowed in nested hash references in regular statement if allow_to_the_right_of_a_fat_comma is not set.
527--- failures: 1
528--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
529--- input
530@fire_elemental = ( 1, { 2 => 4 } );
531
532===
533--- dscr: Good numbers allowed in nested hash references anywhere.
534--- failures: 0
535--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
536--- input
537@Y2K_bug = ( 1, { 0 => 1 } );
538
539===
540--- dscr: Magic numbers not allowed in deep data structures in regular statement.
541--- failures: 1
542--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0}}
543--- input
544@fog_cloud = [ 1, { 0 => { 1 => [ 1, 1, [ \382 ] ] } } ];
545
546===
547--- dscr: Good numbers allowed in deep datastructures anywhere.
548--- failures: 0
549--- params:
550--- input
551@fog_cloud = [ 1, { 0 => { 1 => [ 1, 1, [ 1 ] ] } } ];
552
553===
554--- dscr: $VERSION variables get a special exemption.
555--- failures: 0
556--- params:
557--- input
558our $VERSION = 0.21;
559
560===
561--- dscr: Last element of an array gets a special exemption.
562--- failures: 0
563--- params:
564--- input
565$Invid = $nalfeshnee[-1];
566
567===
568--- dscr: Last element exemption does not work if there is anything else within the subscript.
569--- failures: 1
570--- params:
571--- input
572$warhorse = $Cerberus[-1 * 1];
573
574===
575--- dscr: Penultimate element of an array does not get a special exemption.
576--- failures: 1
577--- params:
578--- input
579$scorpion = $shadow[-2];
580
581===
582--- dscr: Decimal zero is allowed even if the configuration specifies that there aren't any allowed literals.
583--- failures: 0
584--- params: {prohibit_magic_numbers => {allowed_values => ''}}
585--- input
586$tangle_tree = 0;
587
588===
589--- dscr: Floating-point zero is allowed even if the configuration specifies that there aren't any allowed literals.
590--- failures: 0
591--- params: {prohibit_magic_numbers => {allowed_values => ''}}
592--- input
593$xiron_golem = 0.0
594
595===
596--- dscr: Decimal one is allowed even if the configuration specifies that there aren't any allowed literals.
597--- failures: 0
598--- params: {prohibit_magic_numbers => {allowed_values => ''}}
599--- input
600$killer_tomato = 1;
601
602===
603--- dscr: Floating-point one is allowed even if the configuration specifies that there aren't any allowed literals.
604--- failures: 0
605--- params: {prohibit_magic_numbers => {allowed_values => ''}}
606--- input
607$witch_doctor = 1.0;
608
609===
610--- dscr: Decimal two is not allowed if the configuration specifies that there aren't any allowed literals.
611--- failures: 1
612--- params: {prohibit_magic_numbers => {allowed_values => ''}}
613--- input
614$gold_golem = 2;
615
616===
617--- dscr: Floating-point two is not allowed if the configuration specifies that there aren't any allowed literals.
618--- failures: 1
619--- params: {prohibit_magic_numbers => {allowed_values => ''}}
620--- input
621$lich = 2.0;
622
623===
624--- dscr: Decimal zero is allowed even if the configuration doesn't include it in the allowed literals.
625--- failures: 0
626--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
627--- input
628$tangle_tree = 0;
629
630===
631--- dscr: Floating-point zero is allowed even if the configuration doesn't include it in the allowed literals.
632--- failures: 0
633--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
634--- input
635$xiron_golem = 0.0
636
637===
638--- dscr: Decimal one is allowed even if the configuration doesn't include it in the allowed literals.
639--- failures: 0
640--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
641--- input
642$killer_tomato = 1;
643
644===
645--- dscr: Floating-point one is allowed even if the configuration doesn't include it in the allowed literals.
646--- failures: 0
647--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
648--- input
649$witch_doctor = 1.0;
650
651===
652--- dscr: Decimal two is not allowed if the configuration doesn't include it in the allowed literals.
653--- failures: 1
654--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
655--- input
656$gold_golem = 2;
657
658===
659--- dscr: Floating-point two is not allowed if the configuration doesn't include it in the allowed literals.
660--- failures: 1
661--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
662--- input
663$lich = 2.0;
664
665===
666--- dscr: Decimal three is allowed if the configuration includes it in the allowed literals.
667--- failures: 0
668--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
669--- input
670$ghoul = 3;
671
672===
673--- dscr: Floating-point three is allowed if the configuration includes it in the allowed literals.
674--- failures: 0
675--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
676--- input
677$water_elemental = 3.0;
678
679===
680--- dscr: Decimal negative five is allowed if the configuration includes it in the allowed literals.
681--- failures: 0
682--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
683--- input
684$glass_piercer = -5;
685
686===
687--- dscr: Floating-point negative five is allowed if the configuration includes it in the allowed literals.
688--- failures: 0
689--- params: {prohibit_magic_numbers => {allowed_values => '3 -5'}}
690--- input
691$clay_golem = -5.0;
692
693===
694--- dscr: Decimal zero is allowed even if the configuration specifies that there aren't any allowed types.
695--- failures: 0
696--- params: {prohibit_magic_numbers => {allowed_types => ''}}
697--- input
698$tangle_tree = 0;
699
700===
701--- dscr: Floating-point zero is not allowed if the configuration specifies that there aren't any allowed types.
702--- failures: 1
703--- params: {prohibit_magic_numbers => {allowed_types => ''}}
704--- input
705$xiron_golem = 0.0
706
707===
708--- dscr: Decimal one is allowed even if the configuration specifies that there aren't any allowed types.
709--- failures: 0
710--- params: {prohibit_magic_numbers => {allowed_types => ''}}
711--- input
712$killer_tomato = 1;
713
714===
715--- dscr: Floating-point one is not allowed if the configuration specifies that there aren't any allowed types.
716--- failures: 1
717--- params: {prohibit_magic_numbers => {allowed_types => ''}}
718--- input
719$witch_doctor = 1.0;
720
721===
722--- dscr: Decimal zero is allowed if the configuration specifies that there are any allowed types.
723--- failures: 0
724--- params: {prohibit_magic_numbers => {allowed_types => 'Float'}}
725--- input
726$tangle_tree = 0;
727
728===
729--- dscr: Floating-point zero is allowed if the configuration specifies that the Float type is allowed.
730--- failures: 0
731--- params: {prohibit_magic_numbers => {allowed_types => 'Float'}}
732--- input
733$xiron_golem = 0.0
734
735===
736--- dscr: Decimal one is allowed if the configuration specifies that there are any allowed types.
737--- failures: 0
738--- params: {prohibit_magic_numbers => {allowed_types => 'Float'}}
739--- input
740$killer_tomato = 1;
741
742===
743--- dscr: Floating-point one is allowed if the configuration specifies that the Float type is allowed.
744--- failures: 0
745--- params: {prohibit_magic_numbers => {allowed_types => 'Float'}}
746--- input
747$witch_doctor = 1.0;
748
749===
750--- dscr: Binary zero is allowed if the configuration specifies that the Binary type is allowed.
751--- failures: 0
752--- params: {prohibit_magic_numbers => {allowed_types => 'Binary'}}
753--- input
754$battlemech = 0b0;
755
756===
757--- dscr: Binary one is allowed if the configuration specifies that the Binary type is allowed.
758--- failures: 0
759--- params: {prohibit_magic_numbers => {allowed_types => 'Binary'}}
760--- input
761$xeroc = 0b1;
762
763===
764--- dscr: Exponential zero is allowed if the configuration specifies that the Exp type is allowed.
765--- failures: 0
766--- params: {prohibit_magic_numbers => {allowed_types => 'Exp'}}
767--- input
768$Green_elf = 0e0;
769
770===
771--- dscr: Exponential one is allowed if the configuration specifies that the Exp type is allowed.
772--- failures: 0
773--- params: {prohibit_magic_numbers => {allowed_types => 'Exp'}}
774--- input
775$Uruk_hai = 1e0;
776
777===
778--- dscr: Hexadecimal zero is allowed if the configuration specifies that the Hex type is allowed.
779--- failures: 0
780--- params: {prohibit_magic_numbers => {allowed_types => 'Hex'}}
781--- input
782$yeti = 0x00;
783
784===
785--- dscr: Hexadecimal one is allowed if the configuration specifies that the Hex type is allowed.
786--- failures: 0
787--- params: {prohibit_magic_numbers => {allowed_types => 'Hex'}}
788--- input
789$piranha = 0x01;
790
791===
792--- dscr: Octal zero is allowed if the configuration specifies that the Octal type is allowed.
793--- failures: 0
794--- params: {prohibit_magic_numbers => {allowed_types => 'Octal'}}
795--- input
796$basilisk = 000;
797
798===
799--- dscr: Octal one is allowed if the configuration specifies that the Octal type is allowed.
800--- failures: 0
801--- params: {prohibit_magic_numbers => {allowed_types => 'Octal'}}
802--- input
803$brown_mold = 001;
804
805===
806--- dscr: Any integer value should pass if the allowed values contains 'all_integers'.
807--- failures: 0
808--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers'}}
809--- input
810$brogmoid = 356_634_627;
811$rat_ant  =     -29_422;
812
813===
814--- dscr: Any floating-point value without a fractional portion should pass if the allowed values contains 'all_integers'.
815--- failures: 0
816--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers'}}
817--- input
818$human = 102_938.0;
819
820===
821--- dscr: A non-integral value should pass if the allowed values contains it and 'all_integers'.
822--- failures: 0
823--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers 429.73902'}}
824--- input
825$Norn = 429.73902;
826
827===
828--- dscr: Any binary value should pass if the allowed values contains 'all_integers' and allowed types includes 'Binary'.
829--- failures: 0
830--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers', allowed_types => 'Binary'}}
831--- input
832$baby_blue_dragon = 0b01100101_01101010_01110011;
833
834===
835--- dscr: Any hexadecimal value should pass if the allowed values contains 'all_integers' and allowed types includes 'Hex'.
836--- failures: 0
837--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers', allowed_types => 'Hex'}}
838--- input
839$killer_bee = 0x656a73;
840
841===
842--- dscr: Any octal value should pass if the allowed values contains 'all_integers' and allowed types includes 'Octal'.
843--- failures: 0
844--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers', allowed_types => 'Octal'}}
845--- input
846$ettin_mummy = 0145_152_163;
847
848===
849--- dscr: Zero, one, three, four, and five decimal values should pass if the allowed values contains the '3..5' range.
850--- failures: 0
851--- params: {prohibit_magic_numbers => {allowed_values => '3..5'}}
852--- input
853$guide = 0;
854$cuatl = 1;
855$Master_Assassin = 3;
856$orc = 4;
857$trapper = 5;
858
859===
860--- dscr: Negative one, two, and six decimal values and fractional values should not pass if the allowed values contains the '3..5' range.
861--- failures: 4
862--- params: {prohibit_magic_numbers => {allowed_values => '3..5'}}
863--- input
864$Elvenking = -1;
865$brown_pudding = 2;
866$archeologist = 6;
867$nurse = 4.5;
868
869===
870--- dscr: -3/2, -2/2, -1/2 ... 7/5 should pass if the allowed values contains the '-1.5..3.5:by(0.5)' range.
871--- failures: 0
872--- params: {prohibit_magic_numbers => {allowed_values => '-1.5..3.5:by(0.5)'}}
873--- input
874$owlbear = [ -1.5, -1, -.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5 ];
875
876===
877--- dscr: Negative two and four should not pass if the allowed values contains the '-1.5..3.5:by(0.5)' range.
878--- failures: 2
879--- params: {prohibit_magic_numbers => {allowed_values => '-1.5..3.5:by(0.5)'}}
880--- input
881$lurker_above = [ -2, 4 ];
882
883===
884--- dscr: -3/2, -1/2, 1/2 ... 7/5, plus 0 and 1 should pass if the allowed values contains the '-1.5..3.5' range.
885--- failures: 0
886--- params: {prohibit_magic_numbers => {allowed_values => '-1.5..3.5'}}
887--- input
888$long_worm = [ -1.5, -.5, 0, 0.5, 1, 1.5, 2.5, 3.5 ];
889
890===
891--- dscr: -3/2, -2/2, -1/2 ... 7/5 should pass if the allowed values contains the '-1.5..3.5' range and 'all_integers'.
892--- failures: 0
893--- params: {prohibit_magic_numbers => {allowed_values => 'all_integers -1.5..3.5:by(0.5)'}}
894--- input
895$ice_devil = [ -1.5, -1, -.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5 ];
896
897===
898--- dscr: -5, -4, -3, -2, 0, 1, 21, 22, 23, and 24 should pass if the allowed values contains the '-5..-2' and '21..24 ranges.
899--- failures: 0
900--- params: {prohibit_magic_numbers => {allowed_values => '-5..-2 21..24'}}
901--- input
902$newt = [ -5, -4, -3, -2, 0, 1, 21, 22, 23, 24 ];
903
904===
905--- dscr: Should pass mini-CPAN accumulated \$VERSION declarations.
906--- failures: 0
907--- params:
908--- input
909(our $VERSION = q$Revision$) =~ s/Revision //;
910(our $VERSION) = '$Revision$' =~ /([\d.]+)/;
911(our $VERSION) = sprintf "%d", q$Revision$ =~ /Revision:\s+(\S+)/;
912our $VERSION : unique = "1.23";
913our $VERSION : unique = '1.23';
914our $VERSION = "$local_variable v1.23";
915our $VERSION = "1." . sprintf "%d", q$Revision$ =~ /: (\d+)/;
916our $VERSION = "1.2.3";
917our $VERSION = "1.2.3.0";
918our $VERSION = "1.2.3.blah";
919our $VERSION = "1.23 (liblgrp version $local_variable)";
920our $VERSION = "1.23 2005-05-20";
921our $VERSION = "1.23";
922our $VERSION = "1.23, 2004-12-07";
923our $VERSION = "1.23_blah";
924our $VERSION = "1.23blah";
925our $VERSION = "1.2_3";
926our $VERSION = "123";
927our $VERSION = "INSERT";
928our $VERSION = $SomeOtherModule::VERSION;
929our $VERSION = $VERSION = (qw($Revision$))[1];
930our $VERSION = $local_variable;
931our $VERSION = '$Date$'; $VERSION =~ s|^\$Date:\s*([0-9]{4})/([0-9]{2})/([0-9]{2})\s.*|\1.\2.\3| ;
932our $VERSION = '$Revision$' =~ /\$Revision:\s+([^\s]+)/;
933our $VERSION = '$Revision$';
934our $VERSION = '-123 blah';
935our $VERSION = '1.' . qw $Revision$[1];
936our $VERSION = '1.' . sprintf "%d", (qw($Revision$))[1];
937our $VERSION = '1.' . sprintf("%d", (qw($Revision$))[1]);
938our $VERSION = '1.2.3';
939our $VERSION = '1.2.3.0';
940our $VERSION = '1.2.3blah';
941our $VERSION = '1.23';
942our $VERSION = '1.23_blah';
943our $VERSION = '1.23blah';
944our $VERSION = '1.2_3';
945our $VERSION = '1.23' || do { q $Revision$ =~ /(\d+)/; sprintf "%4.2f", $1 / 100 };
946our $VERSION = '123';
947our $VERSION = ('$Revision$' =~ /(\d+.\d+)/)[ 0];
948our $VERSION = ('$Revision$' =~ /(\d+\.\d+)/);
949our $VERSION = ('$Revision$' =~ m/(\d+)/)[0];
950our $VERSION = ((require SomeOtherModule), $SomeOtherModule::VERSION)[1];
951our $VERSION = (q$Revision$ =~ /([\d\.]+)/);
952our $VERSION = (q$Revision$ =~ /(\d+)/g)[0];
953our $VERSION = (qq$Revision$ =~ /(\d+)/)[0];
954our $VERSION = (qw$Revision$)[-1];
955our $VERSION = (qw$Revision$)[1];
956our $VERSION = (qw($Revision$))[1];
957our $VERSION = (split(/ /, '$Revision$'))[1];
958our $VERSION = (split(/ /, '$Revision$'))[2];
959our $VERSION = 1.2.3;
960our $VERSION = 1.23;
961our $VERSION = 1.2_3;
962our $VERSION = 123;
963our $VERSION = SomeOtherModule::RCSVersion('$Revision$');
964our $VERSION = SomeOtherModule::VERSION;
965our $VERSION = [ qw{ $Revision$ } ]->[1];
966our $VERSION = do { (my $v = q%version: 1.23 %) =~ s/.*://; sprintf("%d.%d", split(/\./, $v), 0) };
967our $VERSION = do { (my $v = q%version: 123 %) =~ s/.*://; sprintf("%d.%d", split(/\./, $v), 0) };
968our $VERSION = do { q $Revision$ =~ /(\d+)/; sprintf "%4.2f", $1 / 100 };
969our $VERSION = do { q$Revision$ =~ /Revision: (\d+)/; sprintf "1.%d", $1; };
970our $VERSION = do { require mod_perl2; $mod_perl2::VERSION };
971our $VERSION = do {(q$URL$=~ m$.*/(?:tags|branches)/([^/ \t]+)$)[0] || "0.0"};
972our $VERSION = eval { require version; version::qv((qw$Revision$)[1] / 1000) };
973our $VERSION = q$0.04$;
974our $VERSION = q$Revision$;
975our $VERSION = q(0.14);
976our $VERSION = qv('1.2.3');
977our $VERSION = qw(1.2.3);
978our $VERSION = sprintf "%.02f", $local_variable/100 + 0.3;
979our $VERSION = sprintf "%.3f", 123 + substr(q$Revision$, 4)/1000;
980our $VERSION = sprintf "%d.%d", '$Revision$' =~ /(\d+)\.(\d+)/;
981our $VERSION = sprintf "%d.%d", '$Revision$' =~ /(\d+)/g;
982our $VERSION = sprintf "%d.%d", '$Revision$' =~ /(\d+)\.(\d+)/;
983our $VERSION = sprintf "%d.%d", q$Revision$ =~ /: (\d+)\.(\d+)/;
984our $VERSION = sprintf "%d.%d", q$Revision$ =~ /(\d+)/g;
985our $VERSION = sprintf "%d.%d", q$Revision$ =~ /(\d+)\.(\d+)/;
986our $VERSION = sprintf "%d.%d", q$Revision$ =~ /(\d+)\.(\d+)/g;
987our $VERSION = sprintf "%d.%d", q$Revision$ =~ /: (\d+)\.(\d+)/;
988our $VERSION = sprintf "%d.%d", q$Revision$ =~ m/ (\d+) \. (\d+) /xg;
989our $VERSION = sprintf "%d.%d", q$Revision$ ~~ m:P5:g/(\d+)/;
990our $VERSION = sprintf "%d.%d%d", (split /\D+/, '$Name: beta0_1_1 $')[1..3];
991our $VERSION = sprintf "%s.%s%s", q$Name: Rel-0_90 $ =~ /^Name: Rel-(\d+)_(\d+)(_\d+|)\s*$/, 999, "00", join "", (gmtime)[5] +1900, map {sprintf "%d", $_} (gmtime)[4]+1;
992our $VERSION = sprintf "1.%d", '$Revision$' =~ /(\d+)/;
993our $VERSION = sprintf "1.%d", q$Revision$ =~ /(\d+)/g;
994our $VERSION = sprintf '%d.%d', (q$Revision$ =~ /(\d+)\.(\d+)/);
995our $VERSION = sprintf '%d.%d', q$Revision$ =~ /(\d+)\.(\d+)/;
996our $VERSION = sprintf '%d.%d', q$Revision$ =~ /(\d+)\.(\d+)/;
997our $VERSION = sprintf '%s', 'q$Revision$' =~ /\S+\s+(\S+)\s+/ ;
998our $VERSION = sprintf '%s', 'q$Revision$' =~ /\S+\s+(\S+)\s+/ ;
999our $VERSION = sprintf '%s', q$Revision$ =~ /Revision:\s+(\S+)\s+/ ;
1000our $VERSION = sprintf '%s', q{$Revision$} =~ /\S+\s+(\S+)/ ;
1001our $VERSION = sprintf '1.%d', (q$Revision$ =~ /\D(\d+)\s*$/)[0] + 15;
1002our $VERSION = sprintf("%d", q$Id: SomeModule.pm,v 1.23 2006/04/10 22:39:38 matthew Exp $ =~ /\s(\d+)\s/);
1003our $VERSION = sprintf("%d", q$Id: SomeModule.pm,v 1.23 2006/04/10 22:39:39 matthew Exp $ =~ /\s(\d+)\s/);
1004our $VERSION = sprintf("%d.%d", "Revision: 2006.0626" =~ /(\d+)\.(\d+)/);
1005our $VERSION = sprintf("%d.%d", '$Name: v0_018-2006-06-15b $' =~ /(\d+)_(\d+)/, 0, 0);
1006our $VERSION = sprintf("%d.%d", 0, q$Revision$ =~ /(\d+)\.(\d+)/);
1007our $VERSION = sprintf("%d.%d", q$Name: REL-0-13 $ =~ /(\d+)-(\d+)/, 999, 99);
1008our $VERSION = sprintf("%d.%d", q$Name: ical-parser-html-1-6 $ =~ /(\d+)-(\d+)/);
1009our $VERSION = sprintf("%d.%d", q$Revision$ =~ /(\d+)\.(\d+)/);
1010our $VERSION = sprintf("%d.%d", q$Revision$ =~ /(\d+)\.(\d+)/o);
1011our $VERSION = sprintf("%d.%d", q$Revision$ =~ m/(\d+)\.(\d+)/);
1012our $VERSION = sprintf("%d.%d", q$Revision$=~/(\d+)\.(\d+)/);
1013our $VERSION = sprintf("%d.%d", q'$Revision$' =~ /(\d+)\.(\d+)/);
1014our $VERSION = sprintf("%d.%d.%d", 0, q$Revision$ =~ /(\d+)\.(\d+)/);
1015our $VERSION = sprintf("1.%d", q$Revision$ =~ / (\d+) /);
1016our $VERSION = sprintf("1.%d", q$Revision$ =~ /(\d+)/);
1017our $VERSION = sprintf("1.2%d%d", q$Revision$ =~ /(\d+)\.(\d+)/);
1018our $VERSION = sprintf('%d.%d', '$Revision$' =~ /(\d+)\.(\d+)/);
1019our $VERSION = sprintf('%d.%d', q$Revision$ =~ /(\d+)\.(\d+)/);
1020our $VERSION = sprintf('%d.%d', q$Revision$ =~ /(\d+)\.(\d+)/);
1021our $VERSION = substr q$Revision$, 10;
1022our $VERSION = substr(q$Revision$, 10);
1023our $VERSION = v1.2.3.0;
1024our $VERSION = v1.2.3;
1025our $VERSION = v1.23;
1026our $VERSION = version->new('1.2.3');
1027our $VERSION = version->new(qw$Revision$);
1028our ($PACKAGE, $VERSION) = ('') x 2;
1029our ($VERSION) = "1.23";
1030our ($VERSION) = $SomeOtherModule::VERSION;
1031our ($VERSION) = '$Revision$' =~ /\$Revision:\s+([^\s]+)/;
1032our ($VERSION) = '$Revision$' =~ /\$Revision:\s+([^\s]+)/;
1033our ($VERSION) = '$Revision$' =~ m{ \$Revision: \s+ (\S+) }x;
1034our ($VERSION) = '$Revision$' =~ m{ \$Revision: \s+ (\S+) }xm;
1035our ($VERSION) = '$Revision$'=~/(\d+(\.\d+))/;
1036our ($VERSION) = '$Revision$' =~ m{ \$Revision: \s+ (\S+) }x;
1037our ($VERSION) = '1.23' =~ /([.,\d]+)/;
1038our ($VERSION) = '1.23';
1039our ($VERSION) = ($local_variable =~ /(\d+\.\d+)/);
1040our ($VERSION) = ('$Revision$' =~ /(\d+\.\d+)/) ;
1041our ($VERSION) = ('$Revision$' =~ /(\d+\.\d+)/);
1042our ($VERSION) = ('$Revision$' =~ m/([\.\d]+)/) ;
1043our ($VERSION) = (q$Revision$ =~ /([\d\.]+)/);
1044our ($VERSION) = (qq$Revision$ =~ /(\d+)/)[0];
1045our ($VERSION) = 1.23;
1046our ($VERSION) = q$Revision$ =~ /Revision:\s+(\S+)/ or $VERSION = "1.23";
1047our ($VERSION) = q$Revision$ =~ /Revision:\s+(\S+)/ or $VERSION = '1.23';
1048our ($VERSION) = q$Revision$ =~ /[\d.]+/g;
1049our ($VERSION) = q$Revision$ =~ /^Revision:\s+(\S+)/ or $VERSION = "1.23";
1050require SomeOtherModule; our $VERSION = $SomeOtherModule::VERSION;
1051use SomeOtherModule; our $VERSION = $SomeOtherModule::VERSION;
1052use SomeOtherModule; our $VERSION = SomeOtherModule::VERSION;
1053use base 'SomeOtherModule'; our $VERSION = $SomeOtherModule::VERSION;
1054use version; our $VERSION = 1.23;
1055use version; our $VERSION = qv("1.2.3");
1056use version; our $VERSION = qv('1.2.3');
1057use version; our $VERSION = qv('1.23');
1058use version; our $VERSION = qv((qw$Revision$)[1] / 1000);
1059use version; our $VERSION = version->new('1.23');
1060
1061===
1062--- dscr: user-defined constant creators. RT #62562
1063--- failures: 0
1064--- params: {prohibit_magic_numbers => {allow_to_the_right_of_a_fat_comma => 0, constant_creator_subroutines => 'blahlahlah'}}
1065--- input
1066blahlahlah my $answer => 42;
1067
1068===
1069--- dscr: allow version as second argument of package. RT #67159
1070--- failures: 0
1071--- params:
1072--- input
1073package Maggot 0.01;
1074
1075# NOTE: I feel not needed following function
1076# ===
1077# --- dscr: do not allow numbers elsewhere in package statement. RT #67159
1078# --- failures: 2
1079# --- params:
1080# --- input
1081# package 42; # Illegal, but check anyway.
1082# package Maggot 0.01 42;
1083
1084===
1085--- dscr: no lint
1086--- failures: 0
1087--- params:
1088--- input
1089$Aleax = 5.8.1; ## no lint
1090