So as merly and everyone else have pointed out, at the end of the day, you have to have test cases cover all braches. Brach could mean different things for different testing phases. For the unit testing that you should do, branch means each logic branch of all your scripts.
On the other hand, I agree that it would be nice, if Perl can help you to avoid some of those pitfalls.
Now, how many times have you run into nasty problems by misspelling your hash keys? (In this case -w and strict does not help) But in this in this case Perl provides a great tool: Hash::Util:
foo.pm: package foo; use Hash::Util; use strict; use warnings; sub new { my $self = {}; $self->{XBCDE} = 1; $self->{AXCDE} = 2; $self->{ABXDE} = 3; $self->{ABCXE} = 4; $self->{ABCDX} = 5; bless($self); Hash::Util::lock_keys(%{$self}); return $self; } sub bar_1 { my $self = shift; $self->{AXCDE} = 10; } sub bar_2 { my $self = shift; print $self->{AXCDE}; } sub bar_3 { my $self = shift; $self->{XXXXX} = 10; } sub bar_4 { my $self = shift; print $self->{XXXXX}; } 1; foo.pl: use foo; use strict; use warnings; my $foo = new foo; $foo->bar_1; #okay as the key exists $foo->bar_2; #okay as the key exists $foo->bar_3; #no good, comment out this, and try for the second time $foo->bar_4; #no good, comment out this, and try for the third time
In reply to Re: When -w and use strict aren't enough...
by pg
in thread When -w and use strict aren't enough...
by RMGir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |