10 use Scalar::Util 'blessed';
12 use Mouse::Meta::Attribute;
13 use Mouse::Meta::Class;
15 use Mouse::TypeRegistry;
22 my $meta = Mouse::Meta::Class->initialize($CALLER);
29 $caller->meta->superclasses(@_);
37 $names = [$names] if !ref($names);
39 for my $name (@$names) {
40 Mouse::Meta::Attribute->create($package, $name, @_);
54 my $exporter = Sub::Exporter::build_exporter({
56 groups => { default => [':all'] },
65 my $meta = Mouse::Meta::Class->initialize($CALLER);
66 $meta->superclasses('Mouse::Object')
67 unless $meta->superclasses;
76 for my $keyword (keys %exports) {
77 next if $keyword eq 'meta'; # we don't delete this one
78 delete ${ $caller . '::' }{$keyword};
86 return 0 if ref($class) || !defined($class) || !length($class);
88 return 1 if is_class_loaded($class);
90 (my $file = "$class.pm") =~ s{::}{/}g;
92 eval { CORE::require($file) };
93 confess "Could not load class ($class) because : $@" if $@;
101 return 0 if ref($class) || !defined($class) || !length($class);
103 # walk the symbol table tree to avoid autovififying
104 # \*{${main::}{"Foo::"}} == \*main::Foo::
107 foreach my $part (split('::', $class)) {
108 return 0 unless exists ${$$pack}{"${part}::"};
109 $pack = \*{${$$pack}{"${part}::"}};
112 # check for $VERSION or @ISA
113 return 1 if exists ${$$pack}{VERSION}
114 && defined *{${$$pack}{VERSION}}{SCALAR};
115 return 1 if exists ${$$pack}{ISA}
116 && defined *{${$$pack}{ISA}}{ARRAY};
118 # check for any method
119 foreach ( keys %{$$pack} ) {
120 next if substr($_, -2, 2) eq '::';
121 return 1 if defined *{${$$pack}{$_}}{CODE};
134 Mouse - Moose minus antlers
138 Version 0.01 released ???
143 use Mouse; # automatically turns on strict and warnings
145 has 'x' => (is => 'rw', isa => 'Int');
146 has 'y' => (is => 'rw', isa => 'Int');
159 has 'z' => (is => 'rw', isa => 'Int');
161 #after 'clear' => sub {
172 =head2 meta -> Mouse::Meta::Class
174 Returns this class' metaclass instance.
176 =head2 extends superclasses
178 Sets this class' superclasses.
180 =head2 has (name|names) => parameters
182 Adds an attribute (or if passed an arrayref of names, multiple attributes) to
185 =head2 confess error -> BOOM
187 L<Carp/confess> for your convenience.
189 =head2 blessed value -> ClassName | undef
191 L<Scalar::Util/blessed> for your convenience.
197 Importing Mouse will default your class' superclass list to L<Mouse::Object>.
198 You may use L</extends> to replace the superclass list.
202 Please unimport Mouse so that if someone calls one of the keywords (such as
203 L</extends>) it will break loudly instead breaking subtly.
207 =head2 load_class Class::Name
209 This will load a given C<Class::Name> (or die if it's not loadable).
210 This function can be used in place of tricks like
211 C<eval "use $module"> or using C<require>.
213 =head2 is_class_loaded Class::Name -> Bool
215 Returns whether this class is actually loaded or not. It uses a heuristic which
216 involves checking for the existence of C<$VERSION>, C<@ISA>, and any
217 locally-defined method.
221 Shawn M Moore, C<< <sartak at gmail.com> >>
227 Please report any bugs through RT: email
228 C<bug-mouse at rt.cpan.org>, or browse
229 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mouse>.
231 =head1 COPYRIGHT AND LICENSE
233 Copyright 2008 Shawn M Moore.
235 This program is free software; you can redistribute it and/or modify it
236 under the same terms as Perl itself.