#!/usr/bin/env perl use warnings; use strict; use feature 'current_sub'; # Perl 5.16, for __SUB__() # tests for Perl::Critic::Policy::ControlStructures::ProhibitGotoLabel # run me with e.g.: perl -c gototest.pl && perlcritic -3 gototest.pl goto FOO; # bad FOO: sub foo { } sub bar { goto &foo } # good my $i = 1; goto ("FOO", "BAR", "GLARCH")[$i]; # bad BAR: sub quz { goto __SUB__ } # good sub quz2 { goto __SUB__() } # good my $subref = \&foo; sub ab { goto &$subref; } # good sub cd { goto $subref; } # good, but false positive my $label = "XYZ"; goto $label; # bad (but ambigious) XYZ: __END__ gototest.pl syntax OK goto LABEL used at line 9, column 1. Considered bad practice. (Severity: 3) goto LABEL used at line 16, column 1. Considered bad practice. (Severity: 3) goto LABEL used at line 24, column 10. Considered bad practice. (Severity: 3) goto LABEL used at line 27, column 1. Considered bad practice. (Severity: 3)