X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose.pm;h=901821a971ba3e48f9614fd57acdaf1aceca7f8b;hb=0fc3ab3516f65e07f2af3fa41a8b344e1db2d0ca;hp=a084be0a6afd54c0d1399928defb42f3684bcffc;hpb=ad7a9317f0daa28041284b6b48c7c1ab5036d663;p=gitmo%2FMoose.git diff --git a/lib/Moose.pm b/lib/Moose.pm index a084be0..901821a 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -5,13 +5,19 @@ use warnings; use 5.008; use Scalar::Util 'blessed'; -use Carp 'confess'; +use Carp 'carp', 'confess'; +use Class::Load 'is_class_loaded'; use Moose::Deprecated; use Moose::Exporter; use Class::MOP; +BEGIN { + die "Class::MOP version $Moose::VERSION required--this is version $Class::MOP::VERSION" + if $Moose::VERSION && $Class::MOP::VERSION ne $Moose::VERSION; +} + use Moose::Meta::Class; use Moose::Meta::TypeConstraint; use Moose::Meta::TypeCoercion; @@ -61,7 +67,10 @@ sub has { Moose->throw_error('Usage: has \'name\' => ( key => value, ... )') if @_ % 2 == 1; - my %options = ( definition_context => Moose::Util::_caller_info(), @_ ); + my %context = Moose::Util::_caller_info; + $context{context} = 'has declaration'; + $context{type} = 'class'; + my %options = ( definition_context => \%context, @_ ); my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; $meta->add_attribute( $_, %options ) for @$attrs; } @@ -83,6 +92,10 @@ our $SUPER_BODY; our @SUPER_ARGS; sub super { + if (@_) { + carp 'Arguments passed to super() are ignored'; + } + # This check avoids a recursion loop - see # t/bugs/super_recursion.t return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller(); @@ -127,22 +140,6 @@ Moose::Exporter->setup_import_methods( ); sub init_meta { - # This used to be called as a function. This hack preserves - # backwards compatibility. - if ( $_[0] ne __PACKAGE__ ) { - Moose::Deprecated::deprecated( - feature => 'Moose::init_meta', - message => 'Calling Moose::init_meta as a function is deprecated.' - . ' Doing so will throw an error in Moose 2.0200.' - ); - - return __PACKAGE__->init_meta( - for_class => $_[0], - base_class => $_[1], - metaclass => $_[2], - ); - } - shift; my %args = @_; @@ -152,6 +149,9 @@ sub init_meta { my $metaclass = $args{metaclass} || 'Moose::Meta::Class'; my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta'; + Moose->throw_error("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)") + unless is_class_loaded($metaclass); + Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Class.") unless $metaclass->isa('Moose::Meta::Class'); @@ -241,7 +241,6 @@ $_->make_immutable( Moose::Meta::TypeCoercion::Union Moose::Meta::Method - Moose::Meta::Method::Accessor Moose::Meta::Method::Constructor Moose::Meta::Method::Destructor Moose::Meta::Method::Overridden @@ -262,9 +261,17 @@ $_->make_immutable( Moose::Meta::Role::Application::ToInstance ); -Moose::Meta::Mixin::AttributeCore->meta->make_immutable( +$_->make_immutable( inline_constructor => 0, constructor_name => undef, + # these are Class::MOP accessors, so they need inlining + inline_accessors => 1 + ) for grep { $_->is_mutable } + map { $_->meta } + qw( + Moose::Meta::Method::Accessor + Moose::Meta::Method::Delegation + Moose::Meta::Mixin::AttributeCore ); 1; @@ -458,7 +465,7 @@ for information on how to define a new type, and how to retrieve type meta-data) This will attempt to use coercion with the supplied type constraint to change the value passed into any accessors or constructors. You B supply a type constraint, and that type constraint B define a coercion. See -L for an example. +L for an example. =item I $role_name> @@ -636,15 +643,16 @@ cover here. See L for details on how a trait name is resolved to a role name. -Also see L for a metaclass trait -example. +Also see L for a metaclass +trait example. =item I => Str -The value of this key is the name of the method that will be called to -obtain the value used to initialize the attribute. See the L -and/or L for more information. +The value of this key is the name of the method that will be called to obtain +the value used to initialize the attribute. See the L and/or +L for more +information. =item I => SCALAR | CODE @@ -786,35 +794,33 @@ superclass method with the same arguments as the original method. An C method, is a way of explicitly saying "I am augmenting this method from my superclass". Once again, the details of how C and -C work is best described in the L. +C work is best described in the +L. =item B The keyword C, much like C, is a no-op outside of the context of an C method. You can think of C as being the inverse of C; the details of how C and C work is best described in -the L. +the L. -=item B +=item B -This is the C function, and exported here because I use it -all the time. +This is the C function. It is highly recommended that +this is used instead of C anywhere you need to test for an object's class +name. -=item B +=item B -This is the C function. It is exported here because I -use it all the time. It is highly recommended that this is used instead of -C anywhere you need to test for an object's class name. +This is the C function, and exported here for historical +reasons. =back =head1 METACLASS -When you use Moose, you can specify which metaclass to use: - - use Moose -metaclass => 'My::Meta::Class'; - -You can also specify traits which will be applied to your metaclass: +When you use Moose, you can specify traits which will be applied to your +metaclass: use Moose -traits => 'My::Trait'; @@ -842,8 +848,8 @@ The lookup method for metaclasses is the same, except that it looks for a class matching B. If all this is confusing, take a look at -L, which demonstrates how to create an -attribute trait. +L, which demonstrates how to +create an attribute trait. =head1 UNIMPORTING FUNCTIONS @@ -870,39 +876,10 @@ to work. Here is an example: To learn more about extending Moose, we recommend checking out the "Extending" recipes in the L, starting with -L, which provides an overview of -all the different ways you might extend Moose. - -=head2 B<< Moose->init_meta(for_class => $class, base_class => $baseclass, metaclass => $metaclass) >> - -The C method sets up the metaclass object for the class -specified by C. This method injects a a C accessor -into the class so you can get at this object. It also sets the class's -superclass to C, with L as the default. - -C returns the metaclass object for C<$class>. - -You can specify an alternate metaclass with the C option. - -For more detail on this topic, see L. - -This method used to be documented as a function which accepted -positional parameters. This calling style will still work for -backwards compatibility, but is deprecated. - -=head2 B - -Moose's C method supports the L form of C<{into =E $pkg}> -and C<{into_level =E 1}>. - -B: Doing this is more or less deprecated. Use L -instead, which lets you stack multiple C-alike modules -sanely. It handles getting the exported functions into the right place -for you. - -=head2 B - -An alias for C, used internally by Moose. +L, which provides an overview of +all the different ways you might extend Moose. L and +L are the modules which provide the majority of the +extension functionality, so reading their documentation should also be helpful. =head2 The MooseX:: namespace @@ -967,14 +944,39 @@ not (UPDATE: so far so good). We offer both a mailing list and a very active IRC channel. -The mailing list is L. You must be subscribed to send +The mailing list is L. You must be subscribed to send a message. To subscribe, send an empty message to -L +L You can also visit us at C<#moose> on L This channel is quite active, and questions at all levels (on Moose-related topics ;) are welcome. +=head1 WHAT DOES MOOSE STAND FOR? + +Moose doesn't stand for one thing in particular, however, if you want, here +are a few of our favorites. Feel free to contribute more! + +=over 4 + +=item * Make Other Object Systems Envious + +=item * Makes Object Orientation So Easy + +=item * Makes Object Orientation Spiffy- Er (sorry ingy) + +=item * Most Other Object Systems Emasculate + +=item * Moose Often Ovulate Sorta Early + +=item * Moose Offers Often Super Extensions + +=item * Meta Object Obligates Salivary Excitation + +=item * Meta Object Orientation Syntax Extensions + +=back + =head1 ACKNOWLEDGEMENTS =over 4 @@ -1002,9 +1004,19 @@ early ideas/feature-requests/encouragement/bug-finding. =item L -This is the official web home of Moose, it contains links to our public git repository -as well as links to a number of talks and articles on Moose and Moose related -technologies. +This is the official web home of Moose. It contains links to our public git +repository, as well as links to a number of talks and articles on Moose and +Moose related technologies. + +=item the L + +This is an introduction to Moose which covers most of the basics. + +=item Modern Perl, by chromatic + +This is an introduction to modern Perl programming, which includes a section on +Moose. It is available in print and as a free download from +L. =item The Moose is flying, a tutorial by Randal Schwartz @@ -1016,8 +1028,6 @@ Part 2 - L See L for extensions. -=item Moose stats on ohloh.net - L - =back =head2 Books @@ -1093,14 +1103,60 @@ Dave (autarch) Rolsky Eautarch@urth.orgE =head1 CONTRIBUTORS -Aankhen +Moose is a community project, and as such, involves the work of many, many +members of the community beyond just the members in the cabal. In particular: -Adam (Alias) Kennedy +Dave (autarch) Rolsky wrote most of the documentation in L. + +John (jgoulah) Goulah wrote L. + +Jess (castaway) Robinson wrote L. -Anders (Debolaz) Nor Berle +Aran (bluefeet) Clary Deltac wrote +L. + +Anders (Debolaz) Nor Berle contributed L and L. + +Also, the code in L is based on code from the +L distribution, which had contributions from: Chris (perigrin) Prather +Cory (gphat) Watson + +Evan Carroll + +Florian (rafl) Ragwitz + +Jason May + +Jay Hannah + +Jesse (doy) Luehrs + +Paul (frodwith) Driver + +Robert (rlb3) Boone + +Robert Buels + +Robert (phaylon) Sedlacek + +Shawn (Sartak) Moore + +Stevan Little + +Tom (dec) Lanyon + +Yuval Kogman + +Finally, these people also contributed various tests, bug fixes, +documentation, and features to the Moose codebase: + +Aankhen + +Adam (Alias) Kennedy + Christian (chansen) Hansen Cory (gphat) Watson @@ -1111,16 +1167,12 @@ Eric (ewilhelm) Wilhelm Evan Carroll -Florian (rafl) Ragwitz - Guillermo (groditi) Roditi Jason May Jay Hannah -Jess (castaway) Robinson - Jonathan (jrockway) Rockway Matt (mst) Trout @@ -1141,8 +1193,6 @@ Sam (mugwump) Vilain Scott (konobi) McWhirter -Shawn (Sartak) Moore - Shlomi (rindolf) Fish Tom (dec) Lanyon