X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=6f6feabdfb9802c7f6f5b34da1f2e9a94941db83;hb=cbc437f2b4ce45360cef004995bd27ffc8649fb8;hp=3a0a52970b4b5b88581a5331741e48c1f7b13697;hpb=8632b6fe69bd4417ad67fbcbbca617ad4fd54ccb;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 3a0a529..6f6feab 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -1,4 +1,3 @@ -#!/usr/bin/env perl package Mouse::Meta::Class; use strict; use warnings; @@ -76,7 +75,7 @@ sub get_method_list { no strict 'refs'; # Get all the CODE symbol table entries my @functions = - grep !/(?:has|with|around|before|after|blessed|extends|confess)/, + grep !/^(?:has|with|around|before|after|blessed|extends|confess)$/, grep { defined &{"${name}::$_"} } keys %{"${name}::"}; push @functions, keys %{$self->{'methods'}->{$name}}; @@ -153,9 +152,9 @@ sub make_immutable { $self->add_method('DESTROY' => Mouse::Meta::Method::Destructor->generate_destructor_method_inline( $self )); } } -sub make_mutable { - Carp::croak "Mouse::Meta::Class->make_mutable does not supported by Mouse"; -} + +sub make_mutable { confess "Mouse does not currently support 'make_mutable'" } + sub is_immutable { $_[0]->{is_immutable} } sub attribute_metaclass { "Mouse::Meta::Class" } @@ -197,38 +196,33 @@ sub roles { $_[0]->{roles} } sub does_role { my ($self, $role_name) = @_; + (defined $role_name) || confess "You must supply a role name to look for"; + for my $role (@{ $self->{roles} }) { return 1 if $role->name eq $role_name; } + return 0; } sub create { - my ( $class, @args ) = @_; - - unshift @args, 'package' if @args % 2 == 1; - - my (%options) = @args; - my $package_name = $options{package}; + my ($self, $package_name, %options) = @_; (ref $options{superclasses} eq 'ARRAY') || confess "You must pass an ARRAY ref of superclasses" if exists $options{superclasses}; - + (ref $options{attributes} eq 'ARRAY') || confess "You must pass an ARRAY ref of attributes" - if exists $options{attributes}; - + if exists $options{attributes}; + (ref $options{methods} eq 'HASH') || confess "You must pass a HASH ref of methods" - if exists $options{methods}; + if exists $options{methods}; do { - # XXX should I implement Mouse::Meta::Module? - my $package_name = $options{package}; - ( defined $package_name && $package_name ) || confess "You must pass a package name"; @@ -242,7 +236,7 @@ sub create { confess "creation of $package_name failed : $@" if $@; }; - my (%initialize_options) = @args; + my %initialize_options = %options; delete @initialize_options{qw( package superclasses @@ -251,11 +245,11 @@ sub create { version authority )}; - my $meta = $class->initialize( $package_name => %initialize_options ); + my $meta = $self->initialize( $package_name => %initialize_options ); # FIXME totally lame $meta->add_method('meta' => sub { - $class->initialize(ref($_[0]) || $_[0]); + $self->initialize(ref($_[0]) || $_[0]); }); $meta->superclasses(@{$options{superclasses}}) @@ -330,7 +324,7 @@ this class and its superclasses. Returns a mapping of attribute names to their corresponding L objects. -=head2 has_attribute Name -> Boool +=head2 has_attribute Name -> Bool Returns whether we have a L with the given name.