X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose.pm;h=eb00d7f17f9c0e440cc3216689b05310e2ea937d;hb=30350cb4d7b4345131ed638b2b30e7d1b7b1ef4c;hp=45070f01d8dbcfb6f80f8d4342f50b0fc3c66220;hpb=af4840a96f66d966e9f3084b41d10ed77132ae2b;p=gitmo%2FMoose.git diff --git a/lib/Moose.pm b/lib/Moose.pm index 45070f0..eb00d7f 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -6,7 +6,7 @@ use warnings; use 5.008; -our $VERSION = '0.58'; +our $VERSION = '0.65'; $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; @@ -15,7 +15,7 @@ use Carp 'confess', 'croak', 'cluck'; use Moose::Exporter; -use Class::MOP 0.67; +use Class::MOP 0.76; use Moose::Meta::Class; use Moose::Meta::TypeConstraint; @@ -36,6 +36,13 @@ use Moose::Meta::Role::Application::ToInstance; use Moose::Util::TypeConstraints; use Moose::Util (); +sub _caller_info { + my $level = @_ ? ($_[0] + 1) : 2; + my %info; + @info{qw(package file line)} = caller($level); + return \%info; +} + sub throw_error { # FIXME This shift; @@ -74,7 +81,7 @@ sub has { my $class = shift; my $name = shift; croak 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1; - my %options = @_; + my %options = ( definition_context => _caller_info(), @_ ); my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; Class::MOP::Class->initialize($class)->add_attribute( $_, %options ) for @$attrs; } @@ -94,8 +101,15 @@ sub around { Moose::Util::add_method_modifier($class, 'around', \@_); } +our $SUPER_PACKAGE; +our $SUPER_BODY; +our @SUPER_ARGS; + sub super { - return unless our $SUPER_BODY; $SUPER_BODY->(our @SUPER_ARGS); + # This check avoids a recursion loop - see + # t/100_bugs/020_super_recursion.t + return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller(); + return unless $SUPER_BODY; $SUPER_BODY->(@SUPER_ARGS); } sub override { @@ -124,16 +138,9 @@ sub augment { 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::MOP::Class->initialize($class)->make_immutable(@_); -} - Moose::Exporter->setup_import_methods( with_caller => [ - qw( extends with has before after around override augment make_immutable ) + qw( extends with has before after around override augment) ], as_is => [ qw( super inner ), @@ -244,24 +251,18 @@ sub _get_caller { ## make 'em all immutable -$_->meta->make_immutable( +$_->make_immutable( inline_constructor => 1, constructor_name => "_new", - inline_accessors => 1, # these are Class::MOP accessors, so they need inlining - ) - for (qw( + # these are Class::MOP accessors, so they need inlining + inline_accessors => 1 + ) for grep { $_->is_mutable } + map { $_->meta } + 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 @@ -283,7 +284,7 @@ $_->meta->make_immutable( Moose::Meta::Role::Application::ToClass Moose::Meta::Role::Application::ToRole Moose::Meta::Role::Application::ToInstance -)); +); 1; @@ -613,14 +614,14 @@ resolved to a class name. Also see L for a metaclass trait example. -=item I +=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 for more information. -=item I +=item I => SCALAR | CODE The value of this key is the default value which will initialize the attribute. @@ -631,7 +632,7 @@ See the L for more information. -=item I +=item I => Str This may be a method name (referring to a method on the class with this attribute) or a CODE ref. The initializer is used to set the @@ -641,24 +642,30 @@ to). See the L for more information. -=item I +=item I => Str Allows you to clear the value, see the L for more information. -=item I +=item I => Str Basic test to see if a value has been set in the attribute, see the L for more information. +=item I => (0|1) + +Automatically define lazy => 1 as well as builder => "_build_$attr", clearer => +"clear_$attr', predicate => 'has_$attr' unless they are already defined. + + =back =item B %options> -This is variation on the normal attibute creator C which allows you to +This is variation on the normal attribute creator C which allows you to clone and extend an attribute from a superclass or from a role. Here is an example of the superclass usage: @@ -737,7 +744,7 @@ You I allowed to change the type without restriction. It is recommended that you use this freedom with caution. We used to only allow for extension only if the type was a subtype of the parent's type, but we felt that was too restrictive and is better left as a -policy descision. +policy decision. =item I @@ -1012,6 +1019,8 @@ Part 2 - L =item L documentation +=item L for information about type constraints. + =item The #moose channel on irc.perl.org =item The Moose mailing list - moose@perl.org @@ -1072,7 +1081,7 @@ project you have a commit bit on this file and can add your name to the list. However there are only a few people with the rights to release a new version of Moose. The Moose Cabal are the people to go to with questions regarding -the wider purvue of Moose, and help out maintaining not just the code +the wider purview of Moose, and help out maintaining not just the code but the community as well. Stevan (stevan) Little Estevan@iinteractive.comE @@ -1123,6 +1132,8 @@ Piotr (dexter) Roszatycki Sam (mugwump) Vilain +Cory (gphat) Watson + ... and many other #moose folks =head1 COPYRIGHT AND LICENSE