| 1 | package uninit; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | $uninit::VERSION="1.00"; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | CHECK { | ||||||||||||||||||||||||||
|
Subroutine
CHECK: called CC=8 SCAR=29.2
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use B qw(main_start); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | my %globs; | |||||||||||||||||||||||||||
| 8 | 1 | my ($prog, $line); | |||||||||||||||||||||||||||
| 9 | 1 | ▶ | for (my $op = main_start; $$op; $op = $op->next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | if ($op->name =~ /gvsv/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 11 | 0 | my $var = '$'.$op->sv->SAFENAME; | |||||||||||||||||||||||||||
| 12 | 0 | my $top = $op; | |||||||||||||||||||||||||||
| 13 | 0 | ▶ | $top = $top->sibling while $top->can("sibling") and ${$top->sibling}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$top->can("sibling") and ${$top->sibling;}
MC/DC0%0/2
$top->can("sibling") and ${$top->sibling;}
$top->can("sibling")
${$top->sibling;}
Truth table0%0/3
A and B
A= $top->can("sibling")B= ${$top->sibling;}
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | if ($top->next->name =~ /assign/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 15 | 0 | $assigned{$var}++; | |||||||||||||||||||||||||||
| 16 | } elsif (not exists $assigned{$var}) { | ||||||||||||||||||||||||||||
| 17 | 0 | warn "$var may be used uninitialized at $prog line $line.\n"; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | } elsif ($op->name eq "nextstate") { | ||||||||||||||||||||||||||||
| 20 | 1 | $prog = $op->file; $line = $op->line; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =pod | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 NAME | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | uninit - Warn about uninitialized variables | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | perl -Muninit myprogram | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | It's all very well being warned about the use of C<undef> if you | ||||||||||||||||||||||||||||
| 38 | don't know what variable it is that contains C<undef>, especially | ||||||||||||||||||||||||||||
| 39 | if you've got more than one variable in a line. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | C<uninit> attempts to do compile-time static checking of your | ||||||||||||||||||||||||||||
| 42 | program to see if any variables are used before they have any | ||||||||||||||||||||||||||||
| 43 | values assigned to them; it also reports B<which> variable actually | ||||||||||||||||||||||||||||
| 44 | caused the problem. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | It isn't guaranteed to catch all cases, and you can probably trick | ||||||||||||||||||||||||||||
| 47 | it with judicious use of C<eval>, but I can't do anything about that. | ||||||||||||||||||||||||||||
| 48 | It's only a guideline. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Simon Cozens, C<simon@cpan.org> | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | L<optimize>, L<B> | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | 1; | |||||||||||||||||||||||||||