X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose.pm;h=16e9b9f9289c51f4df9fcad7d04a80540833f049;hb=84b56df2d53b1735aa20cac925233700f03fb129;hp=b81aa740f5acf0ed354c5e7b871e267909a29179;hpb=53dd42d80a04479722d4ba00de03fdbe26a12df6;p=gitmo%2FMoose.git diff --git a/lib/Moose.pm b/lib/Moose.pm index b81aa74..16e9b9f 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -4,7 +4,7 @@ package Moose; use strict; use warnings; -our $VERSION = '0.33'; +our $VERSION = '0.34'; our $AUTHORITY = 'cpan:STEVAN'; use Scalar::Util 'blessed', 'reftype'; @@ -13,7 +13,7 @@ use Sub::Name 'subname'; use Sub::Exporter; -use Class::MOP 0.46; +use Class::MOP 0.49; use Moose::Meta::Class; use Moose::Meta::TypeConstraint; @@ -92,10 +92,33 @@ use Moose::Util::TypeConstraints; with => sub { my $class = $CALLER; return subname 'Moose::with' => sub (@) { - my (@roles) = @_; - confess "Must specify at least one role" unless @roles; - Class::MOP::load_class($_) for @roles; - $class->meta->_apply_all_roles(@roles); + my (@args) = @_; + confess "Must specify at least one role" unless @args; + + my $roles = Data::OptList::mkopt(\@args); + + #use Data::Dumper; + #warn Dumper $roles; + + Class::MOP::load_class($_->[0]) for @$roles; + + ($_->[0]->can('meta') && $_->[0]->meta->isa('Moose::Meta::Role')) + || confess "You can only consume roles, " . $_->[0] . " is not a Moose role" + foreach @$roles; + + my $meta = $class->meta; + + if (scalar @$roles == 1) { + my ($role, $params) = @{$roles->[0]}; + $role->meta->apply($meta, (defined $params ? %$params : ())); + } + else { + Moose::Meta::Role->combine( + map { $_->[0]->meta } @$roles + )->apply($meta); + } + + #$class->meta->_apply_all_roles(@roles); }; }, has => sub { @@ -449,9 +472,9 @@ try and write a recipe on them soon. The default behavior here is to just load C<$metaclass_name>; however, we also have a way to alias to a shorter name. This will first look to see if B exists. If it does, Moose -will then check to see if that has the method C, which +will then check to see if that has the method C, which should return the actual name of the custom attribute metaclass. If there is no -C method, it will fall back to using +C method, it will fall back to using B as the metaclass name. =item I $code> @@ -878,7 +901,7 @@ Shawn (sartak) Moore =head1 COPYRIGHT AND LICENSE -Copyright 2006, 2007 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L