Dancing with Class::MOP

markjugg on 2006-07-02T19:44:04

My first impression of Class::MOP was WTF?. The "Meta Object Protocol" sounds awfully abstract. I thought it was Perl6 weirdness invading Perl 5.

Last night I began to understand what it's good for. To implement a plugin system, CGI::Application uses introspection to examine the ancestry of classes that have been inherited from. This allows callbacks in each ancestoral class to be executed.

We had been using "Class::ISA" to do this, which provides some related procedures.

Class::MOP formalizes, and in my opinion cleans up, access to this internal, or "meta" class information. It does so by adding a "meta" class method. Through it, this kind of meta-class information can be queried on demand. In my case, the syntax looked like this:

 my @ancestors = Project->meta->class_precedence_list;
 

Not so hard.

It seems in Perl6 "ISA" is gone, and the kind syntax provided through Class::MOP replaces it. This means that be using Class::MOP now, we can be learning about Perl6, and making our code even easier to port when the time comes.