add cache attribute to M::Meta::Class->create_anon_class
[gitmo/Moose.git] / lib / Moose / Role.pm
index d6aacbf..67347a3 100644 (file)
@@ -8,12 +8,14 @@ use Scalar::Util 'blessed';
 use Carp         'confess';
 use Sub::Name    'subname';
 
+use Data::OptList;
 use Sub::Exporter;
 
-our $VERSION   = '0.07';
+our $VERSION   = '0.08';
 our $AUTHORITY = 'cpan:STEVAN';
 
-use Moose ();
+use Moose       ();
+use Moose::Util ();
 
 use Moose::Meta::Role;
 use Moose::Util::TypeConstraints;
@@ -29,8 +31,8 @@ use Moose::Util::TypeConstraints;
         # make a subtype for each Moose class
         subtype $role
             => as 'Role'
-            => where { $_->does($role) }
-            => optimize_as { blessed($_[0]) && $_[0]->can('does') && $_[0]->does($role) }
+            => where { Moose::Util::does_role($_, $role) }
+            => optimize_as { blessed($_[0]) && Moose::Util::does_role($_[0], $role) }
         unless find_type_constraint($role);
 
         my $meta;
@@ -58,20 +60,7 @@ use Moose::Util::TypeConstraints;
         with => sub {
             my $meta = _find_meta();
             return subname 'Moose::Role::with' => sub (@) {
-                my (@roles) = @_;
-                confess "Must specify at least one role" unless @roles;
-                Class::MOP::load_class($_) for @roles;
-                ($_->can('meta') && $_->meta->isa('Moose::Meta::Role'))
-                    || confess "You can only consume roles, $_ is not a Moose role"
-                        foreach @roles;
-                if (scalar @roles == 1) {
-                    $roles[0]->meta->apply($meta);
-                }
-                else {
-                    Moose::Meta::Role->combine(
-                        map { $_->meta } @roles
-                    )->apply($meta);
-                }
+                Moose::Util::apply_all_roles($meta, @_)
             };
         },
         requires => sub {
@@ -165,6 +154,10 @@ use Moose::Util::TypeConstraints;
           && defined $_[1]->{into_level} ? caller( $_[1]->{into_level} )
           :                                caller();
 
+        # this works because both pragmas set $^H (see perldoc perlvar)
+        # which affects the current compilation - i.e. the file who use'd
+        # us - which is why we don't need to do anything special to make
+        # it affect that file rather than this one (which is already compiled)
 
         strict->import;
         warnings->import;
@@ -296,7 +289,7 @@ Christian Hansen E<lt>chansen@cpan.orgE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006, 2007 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>