Declarative Scope Changing
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++. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access