Reflection
Explore the concept of reflection in Perl using Moose's Class::MOP and other Perl idioms to inspect and manipulate running programs. Understand how to verify module loading, package and class existence, check version numbers, functions, and methods, and work with symbol tables for effective object-oriented programming and code management.
Overview
Reflection (or introspection) is the process of asking a program about itself as it runs. By treating code as data, we can manage code in the same way that we manage data. That sounds like a truism, but it’s an important insight into modern programming. It’s also a principle behind code generation.
Moose’s Class::MOP
Checking that a module has loaded
If we know the name of a module, we can check that Perl believes it has loaded that module by looking in the %INC hash. When Perl loads code with use or require, it stores an entry in %INC where the key is the file path of the module to load, and the value is the full path on disk to that module. In ...