use Moose::Meta::Attribute;
use Moose::Meta::Instance;
+use Moose::Object;
+
use Moose::Meta::Role;
+use Moose::Meta::Role::Composite;
+use Moose::Meta::Role::Application;
+use Moose::Meta::Role::Application::RoleSummation;
+use Moose::Meta::Role::Application::ToClass;
+use Moose::Meta::Role::Application::ToRole;
+use Moose::Meta::Role::Application::ToInstance;
+use Moose::Meta::Role::Application::ToMetaclassInstance;
-use Moose::Object;
use Moose::Util::TypeConstraints;
use Moose::Util ();
# this checks the metaclass to make sure
# it is correct, sometimes it can get out
# of sync when the classes are being built
- my $meta = $class->meta->_fix_metaclass_incompatability(@supers);
+ my $meta = Class::MOP::Class->initialize($class)->_fix_metaclass_incompatability(@supers);
$meta->superclasses(@supers);
}
sub with {
my $class = shift;
- Moose::Util::apply_all_roles($class->meta, @_);
+ Moose::Util::apply_all_roles(Class::MOP::Class->initialize($class), @_);
}
sub has {
croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1;
my %options = @_;
my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
- $class->meta->add_attribute( $_, %options ) for @$attrs;
+ Class::MOP::Class->initialize($class)->add_attribute( $_, %options ) for @$attrs;
}
sub before {
sub override {
my $class = shift;
my ( $name, $method ) = @_;
- $class->meta->add_override_method_modifier( $name => $method );
+ Class::MOP::Class->initialize($class)->add_override_method_modifier( $name => $method );
}
sub inner {
sub augment {
my $class = shift;
my ( $name, $method ) = @_;
- $class->meta->add_augment_method_modifier( $name => $method );
+ Class::MOP::Class->initialize($class)->add_augment_method_modifier( $name => $method );
}
sub make_immutable {
my $class = shift;
cluck "The make_immutable keyword has been deprecated, " .
"please go back to __PACKAGE__->meta->make_immutable\n";
- $class->meta->make_immutable(@_);
+ Class::MOP::Class->initialize($class)->make_immutable(@_);
}
-my $exporter = Moose::Exporter->build_import_methods(
+Moose::Exporter->setup_import_methods(
with_caller => [
qw( extends with has before after around override augment make_immutable )
],
# this is the case where the metaclass pragma
# was used before the 'use Moose' statement to
# override a specific class
- $meta = $class->meta();
+ $meta = Class::MOP::Class->initialize($class);
( blessed($meta) && $meta->isa('Moose::Meta::Class') )
- || confess "You already have a &meta function, but it does not return a Moose::Meta::Class";
+ || confess "$class already has a &meta function, but it does not return a Moose::Meta::Class ($meta)";
}
else {
# NOTE:
## make 'em all immutable
$_->meta->make_immutable(
- inline_constructor => 0,
+ inline_constructor => 1,
+ constructor_name => "_new",
inline_accessors => 1, # these are Class::MOP accessors, so they need inlining
)
- for (
- 'Moose::Meta::Attribute',
- 'Moose::Meta::Class',
- 'Moose::Meta::Instance',
-
- 'Moose::Meta::TypeConstraint',
- 'Moose::Meta::TypeConstraint::Union',
- 'Moose::Meta::TypeConstraint::Parameterized',
- 'Moose::Meta::TypeCoercion',
-
- 'Moose::Meta::Method',
- 'Moose::Meta::Method::Accessor',
- 'Moose::Meta::Method::Constructor',
- 'Moose::Meta::Method::Destructor',
- 'Moose::Meta::Method::Overriden',
-
- 'Moose::Meta::Role',
- 'Moose::Meta::Role::Method',
- 'Moose::Meta::Role::Method::Required',
- );
+ for (qw(
+ Moose::Meta::Attribute
+ Moose::Meta::Class
+ Moose::Meta::Instance
+
+ Moose::Meta::TypeConstraint
+ Moose::Meta::TypeConstraint::Union
+ Moose::Meta::TypeConstraint::Parameterized
+ Moose::Meta::TypeConstraint::Parameterizable
+ Moose::Meta::TypeConstraint::Enum
+ Moose::Meta::TypeConstraint::Class
+ Moose::Meta::TypeConstraint::Role
+ Moose::Meta::TypeConstraint::Registry
+ Moose::Meta::TypeCoercion
+ Moose::Meta::TypeCoercion::Union
+
+ Moose::Meta::Method
+ Moose::Meta::Method::Accessor
+ Moose::Meta::Method::Constructor
+ Moose::Meta::Method::Destructor
+ Moose::Meta::Method::Overriden
+ Moose::Meta::Method::Augmented
+
+ Moose::Meta::Role
+ Moose::Meta::Role::Method
+ Moose::Meta::Role::Method::Required
+
+ Moose::Meta::Role::Composite
+
+ Moose::Meta::Role::Application
+ Moose::Meta::Role::Application::RoleSummation
+ Moose::Meta::Role::Application::ToClass
+ Moose::Meta::Role::Application::ToRole
+ Moose::Meta::Role::Application::ToInstance
+ Moose::Meta::Role::Application::ToMetaclassInstance
+));
1;
building normal Perl 5 objects better, but it provides the power of
metaclass programming as well.
+=head2 New to Moose?
+
+If you're new to Moose, the best place to start is the
+L<Moose::Cookbook>. The recipes on Moose basics will get you up to
+speed with many of Moose's features quickly. Once you have an idea of
+what Moose can do, you can use the API documentation to get more
+detail on features which interest you.
+
=head2 Moose Extensions
The C<MooseX::> namespace is the official place to find Moose extensions.
This tells Moose to take the list of C<@role_names> and apply them to the
attribute meta-object. This is very similar to the I<metaclass> option, but
-allows you to use more than one extension at a time. This too is an advanced
-topic, we don't yet have a cookbook for it though.
+allows you to use more than one extension at a time.
-As with I<metaclass>, the default behavior is to just load C<$role_name>; however,
-we also have a way to alias to a shorter name. This will first look to see if
-B<Moose::Meta::Attribute::Custom::Trait::$role_name> exists. If it does, Moose
-will then check to see if that has the method C<register_implementation>, which
-should return the actual name of the custom attribute trait. If there is no
-C<register_implementation> method, it will fall back to using
-B<Moose::Meta::Attribute::Custom::Trait::$metaclass_name> as the trait name.
+See L<TRAIT NAME RESOLUTION> for details on how a trait name is
+resolved to a class name.
+
+Also see L<Moose::Cookbook::Meta::Recipe3> for a metaclass trait
+example.
=back
=back
+=head1 METACLASS TRAITS
+
+When you use Moose, you can also specify traits which will be applied
+to your metaclass:
+
+ use Moose -traits => 'My::Trait';
+
+This is very similar to the attribute traits feature. When you do
+this, your class's C<meta> object will have the specified traits
+applied to it. See L<TRAIT NAME RESOLUTION> for more details.
+
+=head1 TRAIT NAME RESOLUTION
+
+By default, when given a trait name, Moose simply tries to load a
+class of the same name. If such a class does not exist, it then looks
+for for a class matching
+B<Moose::Meta::$type::Custom::Trait::$trait_name>. The C<$type>
+variable here will be one of B<Attribute> or B<Class>, depending on
+what the trait is being applied to.
+
+If a class with this long name exists, Moose checks to see if it has
+the method C<register_implementation>. This method is expected to
+return the I<real> class name of the trait. If there is no
+C<register_implementation> method, it will fall back to using
+B<Moose::Meta::$type::Custom::Trait::$trait> as the trait name.
+
+If all this is confusing, take a look at
+L<Moose::Cookbook::Meta::Recipe3>, which demonstrates how to create an
+attribute trait.
+
=head1 UNIMPORTING FUNCTIONS
=head2 B<unimport>
use Moose (); # no need to get Moose's exports
use Moose::Exporter;
- Moose::Exporter->build_import_methods( also => 'Moose' );
+ Moose::Exporter->setup_import_methods( also => 'Moose' );
sub init_meta {
shift;
This method used to be documented as a function which accepted
positional parameters. This calling style will still work for
-backwards compatibility.
+backwards compatibility, but is deprecated.
=head2 B<import>