From: Matt S Trout Date: Sun, 7 Nov 2010 04:16:06 +0000 (+0000) Subject: clean up method naming X-Git-Tag: 0.009001~71 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=316917c90ba1fb9d3bd9efdd48d80282bc24b8e4;p=gitmo%2FMoo.git clean up method naming --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 6c6d30b..292900d 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -6,20 +6,20 @@ use base qw(Class::Tiny::Object); use Sub::Quote; use B 'perlstring'; -sub generate_methods { +sub generate_method { my ($self, $into, $name, $spec) = @_; die "Must have an is" unless my $is = $spec->{is}; my $name_str = perlstring $name; my $body = do { if ($is eq 'ro') { - ' '.$self->_generate_get($name_str) + $self->_generate_get($name_str) } elsif ($is eq 'rw') { - ' '.$self->_generate_getset($name_str) + $self->_generate_getset($name_str) } else { die "Unknown is ${is}"; } }; - quote_sub "${into}::${name}" => $body; + quote_sub "${into}::${name}" => ' '.$body."\n"; } sub _generate_get { diff --git a/t/method-generate-accessor.t b/t/method-generate-accessor.t index 3845956..3b2af68 100644 --- a/t/method-generate-accessor.t +++ b/t/method-generate-accessor.t @@ -11,9 +11,9 @@ my $gen = Method::Generate::Accessor->new; use Class::Tiny; } -$gen->generate_methods('Foo' => 'one' => { is => 'ro' }); +$gen->generate_method('Foo' => 'one' => { is => 'ro' }); -$gen->generate_methods('Foo' => 'two' => { is => 'rw' }); +$gen->generate_method('Foo' => 'two' => { is => 'rw' }); like( exception { $gen->generate_methods('Foo' => 'three' => {}) },