
I have always embodied the perl virtue of laziness. Well, at least I've tried most times. Most times, this is good, since it helps me to write small, well tested code that is easy to maintain. Other times, it's bad, since I've never learned Moose or DBI::Class.
Recently, the decision was made to have WebGUI move over to Moose. I spent a lot of time reading POD and slides and online articles, and then began the task of setting up metaclasses and roles for WebGUI.
Several times, I found myself wanting to get all the attributes of a metaclass as objects. This can be done by iterating over the names, and then then calling $meta->find_attribute_by_name($name). But inside Class::MOP::Class they're all stored in a hash inside of a private method, _attribute_map(), there's simply no "public" way to get the values of that hash. Why isn't there a $meta->get_attributes?
Similarly, you can get a set of all attributes as objects across all metaclasses, but you can't get their names without again, iterating across all the objects one by one. So why isn't there a $meta->get_all_attributes_list?
Don't get me wrong. I love Moose. Even with the little that I've done, it's already made WebGUI easier to maintain and more reliable. I'm guessing the problem is that I'm not thinking in the Moose way yet, and doing things awkwardly.
There were methods for this at one point, they were removed in 0.93 with the following comment in Moose::Manual::Delta:
Both
get_method_map and get_attribute_map is
deprecated
These metaclass methods were never meant to be public, and they are both now deprecated. The work around if you still need the functionality they provided is to iterate over the list of names manually.
my %fields = map { $_ => $meta->get_attribute($_) } $meta->get_attribute_list;
This was actually a change in Class::MOP, but this version of Moose requires a version of Class::MOP that includes said change.

Copyright 2013 perlDreamer Consulting | All Rights Reserved | Site Map | Graphic Design by Plain Black