some pod cleanups
[gitmo/Moo.git] / lib / Moo / Role.pm
index 401cfdc..71db848 100644 (file)
@@ -5,6 +5,9 @@ use Moo::_Utils;
 use Role::Tiny ();
 use base qw(Role::Tiny);
 
+our $VERSION = '1.003001';
+$VERSION = eval $VERSION;
+
 require Moo::sification;
 
 BEGIN { *INFO = \%Role::Tiny::INFO }
@@ -27,12 +30,18 @@ sub import {
   }
   $INFO{$target} ||= {};
   # get symbol table reference
-  my $stash = do { no strict 'refs'; \%{"${target}::"} };
+  my $stash = _getstash($target);
   _install_tracked $target => has => sub {
-    my ($name_proto, %spec) = @_;
-    my $name_isref = ref $name_proto eq 'ARRAY';
-    foreach my $name ($name_isref ? @$name_proto : $name_proto) {
-      my $spec_ref = $name_isref ? +{%spec} : \%spec;
+    my $name_proto = shift;
+    my @name_proto = ref $name_proto eq 'ARRAY' ? @$name_proto : $name_proto;
+    if (@_ % 2 != 0) {
+      require Carp;
+      Carp::croak("Invalid options for " . join(', ', map "'$_'", @name_proto)
+        . " attribute(s): even number of arguments expected, got " . scalar @_)
+    }
+    my %spec = @_;
+    foreach my $name (@name_proto) {
+      my $spec_ref = @name_proto > 1 ? +{%spec} : \%spec;
       ($INFO{$target}{accessor_maker} ||= do {
         require Method::Generate::Accessor;
         Method::Generate::Accessor->new
@@ -168,6 +177,7 @@ sub _inhale_if_moose {
     }
     require Class::Method::Modifiers if @$mods;
     $INFO{$role}{inhaled_from_moose} = 1;
+    $INFO{$role}{is_role} = 1;
   }
 }
 
@@ -230,9 +240,7 @@ sub apply_single_role_to_package {
 sub create_class_with_roles {
   my ($me, $superclass, @roles) = @_;
 
-  my $new_name = join(
-    '__WITH__', $superclass, my $compose_name = join '__AND__', @roles
-  );
+  my ($new_name, $compose_name) = $me->_composite_name($superclass, @roles);
 
   return $new_name if $Role::Tiny::COMPOSED{class}{$new_name};
 
@@ -258,7 +266,7 @@ sub create_class_with_roles {
     die "${role} is not a Role::Tiny" unless $INFO{$role};
   }
 
-  $Moo::MAKERS{$new_name} = {};
+  $Moo::MAKERS{$new_name} = {is_class => 1};
 
   $me->_handle_constructor($new_name, $_) for @roles;
 
@@ -335,6 +343,7 @@ sub _handle_constructor {
 }
 
 1;
+__END__
 
 =head1 NAME
 
@@ -400,3 +409,5 @@ See L<Moo> for authors.
 =head1 COPYRIGHT AND LICENSE
 
 See L<Moo> for the copyright and license.
+
+=cut