From: wu-lee Date: Mon, 6 Apr 2009 17:08:11 +0000 (+0100) Subject: Added metaclass cache accessor methods (straight from Class::MOP). X-Git-Tag: 0.20~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cecfb9738ad8b93c2ca0171b61c06cac0ebd7484;p=gitmo%2FMouse.git Added metaclass cache accessor methods (straight from Class::MOP). Mainly convenient to me for finding classes to ->make_immutable. --- diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 9e6ef57..6d9cc4f 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -4,7 +4,7 @@ use warnings; use Mouse::Meta::Method::Constructor; use Mouse::Meta::Method::Destructor; -use Scalar::Util qw/blessed/; +use Scalar::Util qw/blessed weaken/; use Mouse::Util qw/get_linear_isa version authority identifier/; use Carp 'confess'; @@ -27,6 +27,17 @@ do { if !exists($METACLASS_CACHE{$name}); return $METACLASS_CACHE{$name}; } + + # Means of accessing all the metaclasses that have + # been initialized thus far + sub get_all_metaclasses { %METACLASS_CACHE } + sub get_all_metaclass_instances { values %METACLASS_CACHE } + sub get_all_metaclass_names { keys %METACLASS_CACHE } + sub get_metaclass_by_name { $METACLASS_CACHE{$_[0]} } + sub store_metaclass_by_name { $METACLASS_CACHE{$_[0]} = $_[1] } + sub weaken_metaclass { weaken($METACLASS_CACHE{$_[0]}) } + sub does_metaclass_exist { exists $METACLASS_CACHE{$_[0]} && defined $METACLASS_CACHE{$_[0]} } + sub remove_metaclass_by_name { $METACLASS_CACHE{$_[0]} = undef } }; sub new {