2 package Mouse::Meta::Class;
6 use Scalar::Util 'blessed';
13 # because Mouse doesn't introspect existing classes, we're forced to
14 # only pay attention to other Mouse classes
15 sub _metaclass_cache {
18 return $METACLASS_CACHE{$name};
24 $METACLASS_CACHE{$name} = $class->new(name => $name)
25 if !exists($METACLASS_CACHE{$name});
26 return $METACLASS_CACHE{$name};
34 $args{attributes} = {};
35 $args{superclasses} = do {
37 \@{ $args{name} . '::ISA' };
43 sub name { $_[0]->{name} }
49 Mouse::load_class($_) for @_;
50 @{ $self->{superclasses} } = @_;
53 @{ $self->{superclasses} };
60 $self->{'attributes'}{$attr->name} = $attr;
63 sub compute_all_applicable_attributes {
67 for my $class ($self->linearized_isa) {
68 my $meta = $self->_metaclass_cache($class)
71 for my $name (keys %{ $meta->get_attribute_map }) {
72 next if $seen{$name}++;
73 push @attr, $meta->get_attribute($name);
80 sub get_attribute_map { $_[0]->{attributes} }
81 sub get_attribute { $_[0]->{attributes}->{$_[1]} }
83 sub linearized_isa { @{ mro::get_linear_isa($_[0]->name) } }
91 Mouse::Meta::Class - hook into the Mouse MOP
95 =head2 initialize ClassName -> Mouse::Meta::Class
97 Finds or creates a Mouse::Meta::Class instance for the given ClassName. Only
98 one instance should exist for a given class.
100 =head2 new %args -> Mouse::Meta::Class
102 Creates a new Mouse::Meta::Class. Don't call this directly.
104 =head2 name -> ClassName
106 Returns the name of the owner class.
108 =head2 superclasses -> [ClassName]
110 Gets (or sets) the list of superclasses of the owner class.
112 =head2 add_attribute Mouse::Meta::Attribute
114 Begins keeping track of the existing L<Mouse::Meta::Attribute> for the owner
117 =head2 compute_all_applicable_attributes -> (Mouse::Meta::Attribute)
119 Returns the list of all L<Mouse::Meta::Attribute> instances associated with
120 this class and its superclasses.
122 =head2 get_attribute_map -> { name => Mouse::Meta::Attribute }
124 Returns a mapping of attribute names to their corresponding
125 L<Mouse::Meta::Attribute> objects.
127 =head2 get_attribute Name -> Mouse::Meta::Attribute | undef
129 Returns the L<Mouse::Meta::Attribute> with the given name.
131 =head2 linearized_isa -> [ClassNames]
133 Returns the list of classes in method dispatch order, with duplicates removed.