use Mouse::Util qw/:meta get_code_package not_supported load_class/;
-{
- my %METACLASS_CACHE;
-
- # because Mouse doesn't introspect existing classes, we're forced to
- # only pay attention to other Mouse classes
- sub _metaclass_cache {
- my($class, $name) = @_;
- return $METACLASS_CACHE{$name};
- }
- sub initialize {
- my($class, $package_name, @args) = @_;
+my %METACLASS_CACHE;
- ($package_name && !ref($package_name))
- || $class->throw_error("You must pass a package name and it cannot be blessed");
+# because Mouse doesn't introspect existing classes, we're forced to
+# only pay attention to other Mouse classes
+sub _metaclass_cache {
+ my($class, $name) = @_;
+ return $METACLASS_CACHE{$name};
+}
- return $METACLASS_CACHE{$package_name}
- ||= $class->_construct_meta(package => $package_name, @args);
- }
+sub initialize {
+ my($class, $package_name, @args) = @_;
- sub class_of{
- my($class_or_instance) = @_;
- return undef unless defined $class_or_instance;
- return $METACLASS_CACHE{ blessed($class_or_instance) || $class_or_instance };
- }
+ ($package_name && !ref($package_name))
+ || $class->throw_error("You must pass a package name and it cannot be blessed");
- # 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 { defined $METACLASS_CACHE{$_[0]} }
- sub remove_metaclass_by_name { delete $METACLASS_CACHE{$_[0]} }
+ return $METACLASS_CACHE{$package_name}
+ ||= $class->_construct_meta(package => $package_name, @args);
+}
+sub class_of{
+ my($class_or_instance) = @_;
+ return undef unless defined $class_or_instance;
+ return $METACLASS_CACHE{ blessed($class_or_instance) || $class_or_instance };
}
+# 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 { defined $METACLASS_CACHE{$_[0]} }
+#sub remove_metaclass_by_name { delete $METACLASS_CACHE{$_[0]} }
+
+
+
sub name { $_[0]->{package} }
-sub version { no strict 'refs'; ${shift->name.'::VERSION'} }
-sub authority { no strict 'refs'; ${shift->name.'::AUTHORITY'} }
-sub identifier {
- my $self = shift;
- return join '-' => (
- $self->name,
- ($self->version || ()),
- ($self->authority || ()),
- );
-}
+# The followings are Class::MOP specific methods
+
+#sub version { no strict 'refs'; ${shift->name.'::VERSION'} }
+#sub authority { no strict 'refs'; ${shift->name.'::AUTHORITY'} }
+#sub identifier {
+# my $self = shift;
+# return join '-' => (
+# $self->name,
+# ($self->version || ()),
+# ($self->authority || ()),
+# );
+#}
# add_attribute is an abstract method
)};
my $meta = $class->initialize( $package_name, %initialize_options, @extra_options);
- Mouse::Meta::Module::weaken_metaclass($package_name)
+ weaken $METACLASS_CACHE{$package_name}
if $mortal;
# FIXME totally lame
@{$self->{superclasses}} = () if exists $self->{superclasses};
%{$stash} = ();
- Mouse::Meta::Module::remove_metaclass_by_name($self->name);
+ delete $METACLASS_CACHE{$self->name};
no strict 'refs';
delete ${$ANON_PREFIX}{ $serial_id . '::' };
meta => [qw(does meta dump _MOUSE_VERBOSE)],
);
+# aliases as public APIs
+
+BEGIN{
+ *class_of = \&Mouse::Meta::Module::class_of;
+ *get_metaclass_by_name = \&Mouse::Meta::Module::get_metaclass_by_name;
+ *get_all_metaclass_instances = \&Mouse::Meta::Module::get_all_metaclass_instances;
+ *get_all_metaclass_names = \&Mouse::Meta::Module::get_all_metaclass_names;
+}
+
# Moose::Util compatible utilities
sub find_meta{
- return Mouse::Meta::Module::class_of( $_[0] );
+ return class_of( $_[0] );
}
sub does_role{
my ($class_or_obj, $role_name) = @_;
- my $meta = Mouse::Meta::Module::class_of($class_or_obj);
+ my $meta = class_of($class_or_obj);
(defined $role_name)
|| ($meta || 'Mouse::Meta::Class')->throw_error("You must supply a role name to does()");
return defined($meta) && $meta->does_role($role_name);
}
-
-
BEGIN {
my $impl;
if ($] >= 5.009_005) {
}
}
+# Utilities from Class::MOP
+
+
# taken from Class/MOP.pm
sub is_valid_class_name {
my $class = shift;
=head3 C<< load_class(ClassName) >>
-This will load a given C<ClassName> (or die if it's not loadable).
+This will load a given C<ClassName> (or die if it is not loadable).
This function can be used in place of tricks like
C<eval "use $module"> or using C<require>.
+=head2 C<< Mouse::Util::class_of(ClassName) >>
+
+The counterpart of C<Class::MOP::class_of()>. This is not exportable.
+
+=head2 C<< Mouse::Util::get_metaclass_by_name(ClassName) >>
+
+The counterpart of C<Class::MOP::get_metaclass_by_name()>. This is not exportable.
+
=head2 MRO::Compat
=head3 C<get_linear_isa>