Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Inline the doc class initializers instead of calling the meta instanc…

…e init'er
  • Loading branch information...
commit 68890f2458d94bf2509b2b7c70e805d52e8738d3 1 parent dc9c5df
@clintongormley authored
Showing with 22 additions and 3 deletions.
  1. +22 −3 lib/Elastic/Model/Meta/Class/Doc.pm
View
25 lib/Elastic/Model/Meta/Class/Doc.pm
@@ -2,7 +2,7 @@ package Elastic::Model::Meta::Class::Doc;
use Moose::Role;
-use MooseX::Types::Moose qw(Maybe HashRef);
+use MooseX::Types::Moose qw(Maybe HashRef CodeRef);
use Carp;
use namespace::autoclean;
use Variable::Magic 0.51 qw(cast wizard dispell);
@@ -11,6 +11,15 @@ my $wiz = wizard( map { $_ => \&_inflate } qw(fetch store exists delete) );
my %exclude = map { $_ => 1 } qw(uid _can_inflate _source);
#===================================
+has 'stub_initializer' => (
+#===================================
+ isa => CodeRef,
+ is => 'ro',
+ lazy => 1,
+ builder => '_build_stub_initializer'
+);
+
+#===================================
has 'mapping' => (
#===================================
isa => HashRef,
@@ -32,8 +41,7 @@ sub new_stub {
#===================================
my ( $self, $uid, $source ) = @_;
- my $obj = $self->get_meta_instance->create_instance;
-
+ my $obj = $self->stub_initializer->();
croak "Invalid UID"
unless $uid && $uid->isa('Elastic::Model::UID') && $uid->from_store;
@@ -65,6 +73,17 @@ sub _build_unique_keys {
}
#===================================
+sub _build_stub_initializer {
+#===================================
+ my $self = shift;
+ my $src = 'sub {'
+ . $self->_inline_generate_instance( '$instance',
+ '"' . $self->name . '"' )
+ . 'return $instance' . '}';
+ return eval($src) or croak $@;
+}
+
+#===================================
sub _inflate {
#===================================
my ( $obj, undef, $key ) = @_;
Please sign in to comment.
Something went wrong with that request. Please try again.