X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FSingleton%2FMeta%2FMethod%2FConstructor.pm;h=eb8aaabfb19d6314d176886e1dc3ce4d2605e426;hb=32bf84e9c634fea4b2e1b437e4249b1c2ccbc2fa;hp=c27085f517d2c8652e4a3c76d1d842efc6de03d9;hpb=d871257e46e9a2871c530139b5c20a9e54c8875a;p=gitmo%2FMooseX-Singleton.git diff --git a/lib/MooseX/Singleton/Meta/Method/Constructor.pm b/lib/MooseX/Singleton/Meta/Method/Constructor.pm index c27085f..eb8aaab 100644 --- a/lib/MooseX/Singleton/Meta/Method/Constructor.pm +++ b/lib/MooseX/Singleton/Meta/Method/Constructor.pm @@ -15,8 +15,8 @@ sub initialize_body { # the author, after all, nothing is free) my $source = 'sub {'; $source .= "\n" . 'my $class = shift;'; - - $source .= "\n" . 'my $existing = do { no strict "refs"; \${"$class\::singleton"}; };'; + + $source .= "\n" . 'my $existing = do { no strict "refs"; no warnings "once"; \${"$class\::singleton"}; };'; $source .= "\n" . 'return ${$existing} if ${$existing};'; $source .= "\n" . 'return $class->Moose::Object::new(@_)'; @@ -39,6 +39,8 @@ sub initialize_body { my $code; { + my $meta = $self; + # NOTE: # create the nessecary lexicals # to be picked up in the eval @@ -62,9 +64,16 @@ sub initialize_body { } @type_constraints; $code = eval $source; - confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@; + $self->throw_error( + "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", + error => $@, data => $source ) + if $@; } - $self->{'&!body'} = $code; + $self->{'body'} = $code; +} + +sub _expected_constructor_class { + return 'MooseX::Singleton::Object'; } no Moose;