Anchor this exclusion regex so "has_list" etc will work
[gitmo/Mouse.git] / lib / Mouse / Meta / Class.pm
index cd8766a..20d0549 100644 (file)
@@ -1,11 +1,11 @@
-#!/usr/bin/env perl
 package Mouse::Meta::Class;
 use strict;
 use warnings;
 
 use Mouse::Meta::Method::Constructor;
 use Mouse::Meta::Method::Destructor;
-use Mouse::Util qw/get_linear_isa blessed/;
+use Scalar::Util qw/blessed/;
+use Mouse::Util qw/get_linear_isa/;
 use Carp 'confess';
 
 do {
@@ -63,6 +63,7 @@ sub add_method {
     my $pkg = $self->name;
 
     no strict 'refs';
+    $self->{'methods'}->{$name}++; # Moose stores meta object here.
     *{ $pkg . '::' . $name } = $code;
 }
 
@@ -73,10 +74,11 @@ sub get_method_list {
 
     no strict 'refs';
     # Get all the CODE symbol table entries
-    my @functions = grep !/^meta$/,
-      grep { /\A[^\W\d]\w*\z/o }
+    my @functions =
+      grep !/^(?:has|with|around|before|after|blessed|extends|confess)$/,
       grep { defined &{"${name}::$_"} }
       keys %{"${name}::"};
+    push @functions, keys %{$self->{'methods'}->{$name}};
     wantarray ? @functions : \@functions;
 }
 
@@ -142,14 +144,12 @@ sub clone_instance {
 
 sub make_immutable {
     my $self = shift;
+    my %args = @_;
     my $name = $self->name;
     $self->{is_immutable}++;
-    no strict 'refs';
-    *{"$name\::new"}     = Mouse::Meta::Method::Constructor->generate_constructor_method_inline( $self );
-
-    my $destructor = Mouse::Meta::Method::Destructor->generate_destructor_method_inline( $self );
-    if ($destructor) {
-        *{"$name\::DESTROY"} = $destructor;
+    $self->add_method('new' => Mouse::Meta::Method::Constructor->generate_constructor_method_inline( $self ));
+    if ($args{inline_destructor}) {
+        $self->add_method('DESTROY' => Mouse::Meta::Method::Destructor->generate_destructor_method_inline( $self ));
     }
 }
 sub make_mutable {