Some of the more dynamic languages—I have used this with Perl in particular—allow you to declaratively change the scope of a block of code, much like reflection-base coercion. Although this features carries great potential for evil if you use it to pry open other people’s encapsulation, we use it only for good. It leverages the general principle of using the rules of packages to give tests access to the code they are testing, doing so in a more targeted and purposeful way.
Let’s look at an example using the Class::Std module for Perl object-oriented development (Listing 9-13). Class::Std lets you ascribe methods with traits that represent their visibility, much like the protected
and private
keywords in Java and C++. ...
No credit card required