From: Dave Rolsky Date: Mon, 23 Aug 2010 13:08:21 +0000 (-0500) Subject: Constants _should_ be reported as methods. X-Git-Tag: 1.06~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74e5f6a094afcedbe9820c1340a10ca8be8df92b;p=gitmo%2FClass-MOP.git Constants _should_ be reported as methods. This makes no fucking sense, but we used to do this, so changing it now may break existing (boneheaded) code. --- diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 3aaa202..bd61c2b 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -164,8 +164,7 @@ sub get_method_list { # Constants will show up as some sort of reference in the namespace hash # ref. return grep { - ! ref $namespace->{$_} - && *{ $namespace->{$_} }{CODE} + ( ref $namespace->{$_} || *{ $namespace->{$_} }{CODE} ) && $self->has_method($_) } keys %{$namespace}; @@ -180,7 +179,7 @@ sub _get_local_methods { my $namespace = $self->namespace; return map { $self->get_method($_) } - grep { ! ref $namespace->{$_} && *{ $namespace->{$_} }{CODE} } + grep { ref $namespace->{$_} || *{ $namespace->{$_} }{CODE} } keys %{$namespace}; } diff --git a/t/003_methods.t b/t/003_methods.t index 7dc6ddb..53813db 100644 --- a/t/003_methods.t +++ b/t/003_methods.t @@ -367,13 +367,13 @@ my $HC = Class::MOP::Class->initialize('HasConstants'); is_deeply( [ sort $HC->get_method_list ], - [qw( quux thing )], + [qw( BAR BAZ FOO quux thing )], 'get_method_list handles constants properly' ); is_deeply( [ sort map { $_->name } $HC->_get_local_methods ], - [qw( quux thing )], + [qw( BAR BAZ FOO quux thing )], '_get_local_methods handles constants properly' );