Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Lazy attributes without values weren't being built correctly before d…

…eflation
  • Loading branch information...
commit 8bb613e6d8d26e9032c4e4bb1080dfc6b5449889 1 parent 5bf07cb
@clintongormley authored
View
5 lib/Elastic/Model/TypeMap/Base.pm
@@ -133,9 +133,8 @@ sub class_deflator {
for ( keys %deflators ) {
my $attr = $attrs->{$_};
unless ( $attr->has_value($obj) ) {
- next unless $attr->has_builder;
- my $reader = $attr->get_read_method_ref;
- $obj->$reader;
+ next unless $attr->has_builder || $attr->has_default;
+ $attr->get_read_method_ref->($obj);
}
my $val = $attr->get_raw_value($obj);
eval { $hash{$_} = $deflators{$_}->($val); 1 } and next;
View
2  t/10_typemaps/04_map_objects.t
@@ -17,6 +17,7 @@ our @mapping = (
email => { type => "string" },
name => { type => "string" },
timestamp => { type => "date" },
+ lazy => { type => "string" },
uid => $uid,
},
},
@@ -43,6 +44,7 @@ our @mapping = (
properties => {
email => { type => "string" },
timestamp => { type => "date" },
+ lazy => { type => "string" },
uid => $uid,
},
View
2  t/10_typemaps/14_flate_objects.t
@@ -81,6 +81,7 @@ my ( $de, $in );
'doc',
{ email => "john\@foo.com",
name => "John",
+ lazy => 'lazy',
uid => { id => 1, index => "foo", type => "user" },
}
);
@@ -98,6 +99,7 @@ my ( $de, $in );
test_doc_attr(
'doc_exname',
{ email => "john\@foo.com",
+ lazy => 'lazy',
uid => { id => 1, index => "foo", type => "user" },
}
);
View
13 t/lib/Foo/User.pm
@@ -19,6 +19,19 @@ has 'email' => (
isa => Str,
);
+#===================================
+has 'lazy' => (
+#===================================
+ is => 'ro',
+ isa => 'Str',
+ lazy => 1,
+ builder => '_build_lazy'
+);
+
+#===================================
+sub _build_lazy { 'lazy' }
+#===================================
+
no Moose;
1;
Please sign in to comment.
Something went wrong with that request. Please try again.