Permalink
Browse files

Fix the application of roles with Elastic::Model and Elastic::Doc

Using classes which extend other classes as doc classes was not working
correctly. The Elastic::Model::Role::Doc role was being applied to the
base class, and then removed after the class was extended.

Closes #13
  • Loading branch information...
1 parent 0915097 commit 0521a844699ac952e89a68611e915df0c873a509 @clintongormley committed Oct 10, 2012
Showing with 47 additions and 27 deletions.
  1. +10 −3 lib/Elastic/Doc.pm
  2. +9 −2 lib/Elastic/Model.pm
  3. +1 −22 t/lib/Foo/Post.pm
  4. +27 −0 t/lib/Foo/Post/Base.pm
View
@@ -5,16 +5,23 @@ use Moose::Exporter;
use namespace::autoclean;
Moose::Exporter->setup_import_methods(
- base_class_roles => ['Elastic::Model::Role::Doc'],
- with_meta => ['has_mapping'],
- class_metaroles => {
+ with_meta => ['has_mapping'],
+ class_metaroles => {
class => ['Elastic::Model::Meta::Class::Doc'],
attribute => ['Elastic::Model::Trait::Field'],
},
also => 'Moose',
);
#===================================
+sub init_meta {
+#===================================
+ shift;
+ my $meta = Moose->init_meta(@_);
+ Moose::Util::apply_all_roles( $meta, 'Elastic::Model::Role::Doc' );
+}
+
+#===================================
sub has_mapping { shift->mapping(@_) }
#===================================
View
@@ -12,11 +12,18 @@ Moose::Exporter->setup_import_methods(
has_analyzer has_tokenizer has_filter has_char_filter
has_unique_index)
],
- base_class_roles => ['Elastic::Model::Role::Model'],
- also => 'Moose',
+ also => 'Moose',
);
#===================================
+sub init_meta {
+#===================================
+ shift;
+ my $meta = Moose->init_meta(@_);
+ Moose::Util::apply_all_roles( $meta, 'Elastic::Model::Role::Model' );
+}
+
+#===================================
sub has_namespace {
#===================================
my $meta = shift;
View
@@ -1,28 +1,7 @@
package Foo::Post;
use Elastic::Doc;
-use Moose;
-use MooseX::Types::Moose qw(Str);
+extends 'Foo::Post::Base';
-#===================================
-has 'title' => (
-#===================================
- is => 'ro',
- isa => Str,
-);
-
-#===================================
-has 'content' => (
-#===================================
- is => 'ro',
- isa => Str,
-);
-
-#===================================
-has 'user' => (
-#===================================
- is => 'ro',
- isa => 'Foo::User',
-);
1;
View
@@ -0,0 +1,27 @@
+package Foo::Post::Base;
+
+use Moose;
+use MooseX::Types::Moose qw(Str);
+
+#===================================
+has 'title' => (
+#===================================
+ is => 'ro',
+ isa => Str,
+);
+
+#===================================
+has 'content' => (
+#===================================
+ is => 'ro',
+ isa => Str,
+);
+
+#===================================
+has 'user' => (
+#===================================
+ is => 'ro',
+ isa => 'Foo::User',
+);
+
+1;

0 comments on commit 0521a84

Please sign in to comment.