From: Matt Phillips Date: Sat, 16 Mar 2013 18:57:06 +0000 (-0400) Subject: refactor asserter code into _generate_asserter() X-Git-Tag: v1.002000~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6d92e9d862d632eccdb89205bddf3ca29ce83a83;p=gitmo%2FMoo.git refactor asserter code into _generate_asserter() --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 10b4ea6..594c81c 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -194,16 +194,9 @@ sub generate_method { if (my $asserter = $spec->{asserter}) { $self->{captures} = {}; - my $code = "do {\n" - ." my \$val = ".$self->_generate_get($name, $spec).";\n" - ." unless (".$self->_generate_simple_has('$_[0]', $name).") {\n" - .qq! die "Attempted to access '${name}' but it is not set";\n! - ." }\n" - ." \$val;\n" - ."}\n"; $methods{$asserter} = - quote_sub "${into}::${asserter}" => $code, + quote_sub "${into}::${asserter}" => $self->_generate_asserter($name, $spec), delete $self->{captures} ; } @@ -540,6 +533,17 @@ sub _generate_getset { ."\n : ".$self->_generate_get($name, $spec)."\n )"; } +sub _generate_asserter { + my ($self, $name, $spec) = @_; + + "do {\n" + ." my \$val = ".$self->_generate_get($name, $spec).";\n" + ." unless (".$self->_generate_simple_has('$_[0]', $name).") {\n" + .qq! die "Attempted to access '${name}' but it is not set";\n! + ." }\n" + ." \$val;\n" + ."}\n"; +} sub _generate_delegation { my ($self, $asserter, $target, $args) = @_; my $arg_string = do {