From: Yuval Kogman Date: Fri, 8 Aug 2008 22:08:38 +0000 (+0000) Subject: Remove p6 style attribute naming X-Git-Tag: 0_64_01~78 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8683db0e09d4b53db67d19f36810e4070e264d2d;p=gitmo%2FClass-MOP.git Remove p6 style attribute naming --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 99e510e..bd51287 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -216,7 +216,7 @@ sub is_class_loaded { ## Class::MOP::Package Class::MOP::Package->meta->add_attribute( - Class::MOP::Attribute->new('$!package' => ( + Class::MOP::Attribute->new('package' => ( reader => { # NOTE: we need to do this in order # for the instance meta-object to @@ -231,7 +231,7 @@ Class::MOP::Package->meta->add_attribute( ); Class::MOP::Package->meta->add_attribute( - Class::MOP::Attribute->new('%!namespace' => ( + Class::MOP::Attribute->new('namespace' => ( reader => { # NOTE: # we just alias the original method @@ -266,7 +266,7 @@ Class::MOP::Package->meta->add_method('initialize' => sub { # the metaclass, isn't abstraction great :) Class::MOP::Module->meta->add_attribute( - Class::MOP::Attribute->new('$!version' => ( + Class::MOP::Attribute->new('version' => ( reader => { # NOTE: # we just alias the original method @@ -285,7 +285,7 @@ Class::MOP::Module->meta->add_attribute( # well. Class::MOP::Module->meta->add_attribute( - Class::MOP::Attribute->new('$!authority' => ( + Class::MOP::Attribute->new('authority' => ( reader => { # NOTE: # we just alias the original method @@ -301,7 +301,7 @@ Class::MOP::Module->meta->add_attribute( ## Class::MOP::Class Class::MOP::Class->meta->add_attribute( - Class::MOP::Attribute->new('%!attributes' => ( + Class::MOP::Attribute->new('attributes' => ( reader => { # NOTE: we need to do this in order # for the instance meta-object to @@ -317,7 +317,7 @@ Class::MOP::Class->meta->add_attribute( ); Class::MOP::Class->meta->add_attribute( - Class::MOP::Attribute->new('%!methods' => ( + Class::MOP::Attribute->new('methods' => ( init_arg => 'methods', reader => { # NOTE: @@ -330,7 +330,7 @@ Class::MOP::Class->meta->add_attribute( ); Class::MOP::Class->meta->add_attribute( - Class::MOP::Attribute->new('@!superclasses' => ( + Class::MOP::Attribute->new('superclasses' => ( accessor => { # NOTE: # we just alias the original method @@ -343,7 +343,7 @@ Class::MOP::Class->meta->add_attribute( ); Class::MOP::Class->meta->add_attribute( - Class::MOP::Attribute->new('$!attribute_metaclass' => ( + Class::MOP::Attribute->new('attribute_metaclass' => ( reader => { # NOTE: # we just alias the original method @@ -356,7 +356,7 @@ Class::MOP::Class->meta->add_attribute( ); Class::MOP::Class->meta->add_attribute( - Class::MOP::Attribute->new('$!method_metaclass' => ( + Class::MOP::Attribute->new('method_metaclass' => ( reader => { # NOTE: # we just alias the original method @@ -369,7 +369,7 @@ Class::MOP::Class->meta->add_attribute( ); Class::MOP::Class->meta->add_attribute( - Class::MOP::Attribute->new('$!instance_metaclass' => ( + Class::MOP::Attribute->new('instance_metaclass' => ( reader => { # NOTE: we need to do this in order # for the instance meta-object to @@ -394,7 +394,7 @@ Class::MOP::Class->meta->add_attribute( ## Class::MOP::Attribute Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!name' => ( + Class::MOP::Attribute->new('name' => ( init_arg => 'name', reader => { # NOTE: we need to do this in order @@ -409,7 +409,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!associated_class' => ( + Class::MOP::Attribute->new('associated_class' => ( init_arg => 'associated_class', reader => { # NOTE: we need to do this in order @@ -424,7 +424,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!accessor' => ( + Class::MOP::Attribute->new('accessor' => ( init_arg => 'accessor', reader => { 'accessor' => \&Class::MOP::Attribute::accessor }, predicate => { 'has_accessor' => \&Class::MOP::Attribute::has_accessor }, @@ -432,7 +432,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!reader' => ( + Class::MOP::Attribute->new('reader' => ( init_arg => 'reader', reader => { 'reader' => \&Class::MOP::Attribute::reader }, predicate => { 'has_reader' => \&Class::MOP::Attribute::has_reader }, @@ -440,7 +440,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!initializer' => ( + Class::MOP::Attribute->new('initializer' => ( init_arg => 'initializer', reader => { 'initializer' => \&Class::MOP::Attribute::initializer }, predicate => { 'has_initializer' => \&Class::MOP::Attribute::has_initializer }, @@ -448,7 +448,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!writer' => ( + Class::MOP::Attribute->new('writer' => ( init_arg => 'writer', reader => { 'writer' => \&Class::MOP::Attribute::writer }, predicate => { 'has_writer' => \&Class::MOP::Attribute::has_writer }, @@ -456,7 +456,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!predicate' => ( + Class::MOP::Attribute->new('predicate' => ( init_arg => 'predicate', reader => { 'predicate' => \&Class::MOP::Attribute::predicate }, predicate => { 'has_predicate' => \&Class::MOP::Attribute::has_predicate }, @@ -464,7 +464,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!clearer' => ( + Class::MOP::Attribute->new('clearer' => ( init_arg => 'clearer', reader => { 'clearer' => \&Class::MOP::Attribute::clearer }, predicate => { 'has_clearer' => \&Class::MOP::Attribute::has_clearer }, @@ -472,7 +472,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!builder' => ( + Class::MOP::Attribute->new('builder' => ( init_arg => 'builder', reader => { 'builder' => \&Class::MOP::Attribute::builder }, predicate => { 'has_builder' => \&Class::MOP::Attribute::has_builder }, @@ -480,7 +480,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!init_arg' => ( + Class::MOP::Attribute->new('init_arg' => ( init_arg => 'init_arg', reader => { 'init_arg' => \&Class::MOP::Attribute::init_arg }, predicate => { 'has_init_arg' => \&Class::MOP::Attribute::has_init_arg }, @@ -488,7 +488,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('$!default' => ( + Class::MOP::Attribute->new('default' => ( init_arg => 'default', # default has a custom 'reader' method ... predicate => { 'has_default' => \&Class::MOP::Attribute::has_default }, @@ -496,7 +496,7 @@ Class::MOP::Attribute->meta->add_attribute( ); Class::MOP::Attribute->meta->add_attribute( - Class::MOP::Attribute->new('@!associated_methods' => ( + Class::MOP::Attribute->new('associated_methods' => ( init_arg => 'associated_methods', reader => { 'associated_methods' => \&Class::MOP::Attribute::associated_methods }, default => sub { [] } @@ -529,6 +529,7 @@ Class::MOP::Attribute->meta->add_method('new' => sub { "wrap the default of '$name' in a CODE reference (ex: sub { [] } and not [])") if exists $options{default} && ref $options{default}; } + # return the new object $class->meta->new_object(name => $name, %options); }); @@ -540,23 +541,22 @@ Class::MOP::Attribute->meta->add_method('clone' => sub { ## -------------------------------------------------------- ## Class::MOP::Method - Class::MOP::Method->meta->add_attribute( - Class::MOP::Attribute->new('&!body' => ( + Class::MOP::Attribute->new('body' => ( init_arg => 'body', reader => { 'body' => \&Class::MOP::Method::body }, )) ); Class::MOP::Method->meta->add_attribute( - Class::MOP::Attribute->new('$!package_name' => ( + Class::MOP::Attribute->new('package_name' => ( init_arg => 'package_name', reader => { 'package_name' => \&Class::MOP::Method::package_name }, )) ); Class::MOP::Method->meta->add_attribute( - Class::MOP::Attribute->new('$!name' => ( + Class::MOP::Attribute->new('name' => ( init_arg => 'name', reader => { 'name' => \&Class::MOP::Method::name }, )) @@ -591,14 +591,14 @@ Class::MOP::Method->meta->add_method('clone' => sub { # practices of attributes, but we put # it here for completeness Class::MOP::Method::Wrapped->meta->add_attribute( - Class::MOP::Attribute->new('%!modifier_table') + Class::MOP::Attribute->new('modifier_table') ); ## -------------------------------------------------------- ## Class::MOP::Method::Generated Class::MOP::Method::Generated->meta->add_attribute( - Class::MOP::Attribute->new('$!is_inline' => ( + Class::MOP::Attribute->new('is_inline' => ( init_arg => 'is_inline', reader => { 'is_inline' => \&Class::MOP::Method::Generated::is_inline }, default => 0, @@ -618,7 +618,7 @@ Class::MOP::Method::Generated->meta->add_method('new' => sub { ## Class::MOP::Method::Accessor Class::MOP::Method::Accessor->meta->add_attribute( - Class::MOP::Attribute->new('$!attribute' => ( + Class::MOP::Attribute->new('attribute' => ( init_arg => 'attribute', reader => { 'associated_attribute' => \&Class::MOP::Method::Accessor::associated_attribute @@ -627,7 +627,7 @@ Class::MOP::Method::Accessor->meta->add_attribute( ); Class::MOP::Method::Accessor->meta->add_attribute( - Class::MOP::Attribute->new('$!accessor_type' => ( + Class::MOP::Attribute->new('accessor_type' => ( init_arg => 'accessor_type', reader => { 'accessor_type' => \&Class::MOP::Method::Accessor::accessor_type }, )) @@ -655,7 +655,7 @@ Class::MOP::Method::Accessor->meta->add_method('new' => sub { # we don't want this creating # a cycle in the code, if not # needed - Scalar::Util::weaken($self->{'$!attribute'}); + Scalar::Util::weaken($self->{'attribute'}); $self->initialize_body; @@ -667,7 +667,7 @@ Class::MOP::Method::Accessor->meta->add_method('new' => sub { ## Class::MOP::Method::Constructor Class::MOP::Method::Constructor->meta->add_attribute( - Class::MOP::Attribute->new('%!options' => ( + Class::MOP::Attribute->new('options' => ( init_arg => 'options', reader => { 'options' => \&Class::MOP::Method::Constructor::options @@ -677,7 +677,7 @@ Class::MOP::Method::Constructor->meta->add_attribute( ); Class::MOP::Method::Constructor->meta->add_attribute( - Class::MOP::Attribute->new('$!associated_metaclass' => ( + Class::MOP::Attribute->new('associated_metaclass' => ( init_arg => 'metaclass', reader => { 'associated_metaclass' => \&Class::MOP::Method::Constructor::associated_metaclass @@ -702,7 +702,7 @@ Class::MOP::Method::Constructor->meta->add_method('new' => sub { # we don't want this creating # a cycle in the code, if not # needed - Scalar::Util::weaken($self->{'$!associated_metaclass'}); + Scalar::Util::weaken($self->{'associated_metaclass'}); $self->initialize_body; @@ -717,11 +717,11 @@ Class::MOP::Method::Constructor->meta->add_method('new' => sub { # included for completeness Class::MOP::Instance->meta->add_attribute( - Class::MOP::Attribute->new('$!meta') + Class::MOP::Attribute->new('meta') ); Class::MOP::Instance->meta->add_attribute( - Class::MOP::Attribute->new('@!slots') + Class::MOP::Attribute->new('slots') ); ## -------------------------------------------------------- diff --git a/lib/Class/MOP/Attribute.pm b/lib/Class/MOP/Attribute.pm index 4d9a602..697fb3a 100644 --- a/lib/Class/MOP/Attribute.pm +++ b/lib/Class/MOP/Attribute.pm @@ -47,26 +47,24 @@ sub new { if( $options{required} and not( defined($options{builder}) || defined($options{init_arg}) || exists $options{default} ) ) { confess("A required attribute must have either 'init_arg', 'builder', or 'default'"); } + bless { - '$!name' => $name, - '$!accessor' => $options{accessor}, - '$!reader' => $options{reader}, - '$!writer' => $options{writer}, - '$!predicate' => $options{predicate}, - '$!clearer' => $options{clearer}, - '$!builder' => $options{builder}, - '$!init_arg' => $options{init_arg}, - '$!default' => $options{default}, - '$!initializer' => $options{initializer}, + 'name' => $name, + 'accessor' => $options{accessor}, + 'reader' => $options{reader}, + 'writer' => $options{writer}, + 'predicate' => $options{predicate}, + 'clearer' => $options{clearer}, + 'builder' => $options{builder}, + 'init_arg' => $options{init_arg}, + 'default' => $options{default}, + 'initializer' => $options{initializer}, # keep a weakened link to the # class we are associated with - '$!associated_class' => undef, + 'associated_class' => undef, # and a list of the methods # associated with this attr - '@!associated_methods' => [], - # NOTE: - # protect this from silliness - init_arg => undef, + 'associated_methods' => [], } => $class; } @@ -85,7 +83,8 @@ sub clone { sub initialize_instance_slot { my ($self, $meta_instance, $instance, $params) = @_; - my $init_arg = $self->{'$!init_arg'}; + my $init_arg = $self->{'init_arg'}; + # try to fetch the init arg from the %params ... # if nothing was in the %params, we can use the @@ -97,14 +96,14 @@ sub initialize_instance_slot { $params->{$init_arg}, ); } - elsif (defined $self->{'$!default'}) { + elsif (defined $self->{'default'}) { $self->_set_initial_slot_value( $meta_instance, $instance, $self->default($instance), ); } - elsif (defined( my $builder = $self->{'$!builder'})) { + elsif (defined( my $builder = $self->{'builder'})) { if ($builder = $instance->can($builder)) { $self->_set_initial_slot_value( $meta_instance, @@ -113,7 +112,7 @@ sub initialize_instance_slot { ); } else { - confess(blessed($instance)." does not support builder method '". $self->{'$!builder'} ."' for attribute '" . $self->name . "'"); + confess(blessed($instance)." does not support builder method '". $self->{'builder'} ."' for attribute '" . $self->name . "'"); } } } @@ -140,29 +139,29 @@ sub _set_initial_slot_value { # the next bunch of methods will get bootstrapped # away in the Class::MOP bootstrapping section -sub name { $_[0]->{'$!name'} } - -sub associated_class { $_[0]->{'$!associated_class'} } -sub associated_methods { $_[0]->{'@!associated_methods'} } - -sub has_accessor { defined($_[0]->{'$!accessor'}) ? 1 : 0 } -sub has_reader { defined($_[0]->{'$!reader'}) ? 1 : 0 } -sub has_writer { defined($_[0]->{'$!writer'}) ? 1 : 0 } -sub has_predicate { defined($_[0]->{'$!predicate'}) ? 1 : 0 } -sub has_clearer { defined($_[0]->{'$!clearer'}) ? 1 : 0 } -sub has_builder { defined($_[0]->{'$!builder'}) ? 1 : 0 } -sub has_init_arg { defined($_[0]->{'$!init_arg'}) ? 1 : 0 } -sub has_default { defined($_[0]->{'$!default'}) ? 1 : 0 } -sub has_initializer { defined($_[0]->{'$!initializer'}) ? 1 : 0 } - -sub accessor { $_[0]->{'$!accessor'} } -sub reader { $_[0]->{'$!reader'} } -sub writer { $_[0]->{'$!writer'} } -sub predicate { $_[0]->{'$!predicate'} } -sub clearer { $_[0]->{'$!clearer'} } -sub builder { $_[0]->{'$!builder'} } -sub init_arg { $_[0]->{'$!init_arg'} } -sub initializer { $_[0]->{'$!initializer'} } +sub name { $_[0]->{'name'} } + +sub associated_class { $_[0]->{'associated_class'} } +sub associated_methods { $_[0]->{'associated_methods'} } + +sub has_accessor { defined($_[0]->{'accessor'}) ? 1 : 0 } +sub has_reader { defined($_[0]->{'reader'}) ? 1 : 0 } +sub has_writer { defined($_[0]->{'writer'}) ? 1 : 0 } +sub has_predicate { defined($_[0]->{'predicate'}) ? 1 : 0 } +sub has_clearer { defined($_[0]->{'clearer'}) ? 1 : 0 } +sub has_builder { defined($_[0]->{'builder'}) ? 1 : 0 } +sub has_init_arg { defined($_[0]->{'init_arg'}) ? 1 : 0 } +sub has_default { defined($_[0]->{'default'}) ? 1 : 0 } +sub has_initializer { defined($_[0]->{'initializer'}) ? 1 : 0 } + +sub accessor { $_[0]->{'accessor'} } +sub reader { $_[0]->{'reader'} } +sub writer { $_[0]->{'writer'} } +sub predicate { $_[0]->{'predicate'} } +sub clearer { $_[0]->{'clearer'} } +sub builder { $_[0]->{'builder'} } +sub init_arg { $_[0]->{'init_arg'} } +sub initializer { $_[0]->{'initializer'} } # end bootstrapped away method section. # (all methods below here are kept intact) @@ -231,7 +230,7 @@ sub get_write_method_ref { } sub is_default_a_coderef { - ('CODE' eq ref($_[0]->{'$!default'} || $_[0]->{default})) + ('CODE' eq ref($_[0]->{'default'} || $_[0]->{default})) } sub default { @@ -241,9 +240,9 @@ sub default { # we pass in the instance and default # can return a value based on that # instance. Somewhat crude, but works. - return $self->{'$!default'}->($instance); + return $self->{'default'}->($instance); } - $self->{'$!default'}; + $self->{'default'}; } # slots @@ -256,19 +255,19 @@ sub attach_to_class { my ($self, $class) = @_; (blessed($class) && $class->isa('Class::MOP::Class')) || confess "You must pass a Class::MOP::Class instance (or a subclass)"; - weaken($self->{'$!associated_class'} = $class); + weaken($self->{'associated_class'} = $class); } sub detach_from_class { my $self = shift; - $self->{'$!associated_class'} = undef; + $self->{'associated_class'} = undef; } # method association sub associate_method { my ($self, $method) = @_; - push @{$self->{'@!associated_methods'}} => $method; + push @{$self->{'associated_methods'}} => $method; } ## Slot management diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 2c09a0f..ad0c98c 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -74,7 +74,7 @@ sub construct_class_instance { no strict 'refs'; $meta = bless { # inherited from Class::MOP::Package - '$!package' => $package_name, + 'package' => $package_name, # NOTE: # since the following attributes will @@ -84,18 +84,18 @@ sub construct_class_instance { # listed here for reference, because they # should not actually have a value associated # with the slot. - '%!namespace' => \undef, + 'namespace' => \undef, # inherited from Class::MOP::Module - '$!version' => \undef, - '$!authority' => \undef, + 'version' => \undef, + 'authority' => \undef, # defined in Class::MOP::Class - '@!superclasses' => \undef, + 'superclasses' => \undef, - '%!methods' => {}, - '%!attributes' => {}, - '$!attribute_metaclass' => $options{'attribute_metaclass'} || 'Class::MOP::Attribute', - '$!method_metaclass' => $options{'method_metaclass'} || 'Class::MOP::Method', - '$!instance_metaclass' => $options{'instance_metaclass'} || 'Class::MOP::Instance', + 'methods' => {}, + 'attributes' => {}, + 'attribute_metaclass' => $options{'attribute_metaclass'} || 'Class::MOP::Attribute', + 'method_metaclass' => $options{'method_metaclass'} || 'Class::MOP::Method', + 'instance_metaclass' => $options{'instance_metaclass'} || 'Class::MOP::Instance', ## uber-private variables # NOTE: @@ -103,8 +103,8 @@ sub construct_class_instance { # we can tell the first time the # methods are fetched # - SL - '$!_package_cache_flag' => undef, - '$!_meta_instance' => undef, + '_package_cache_flag' => undef, + '_meta_instance' => undef, } => $class; } else { @@ -128,7 +128,7 @@ sub construct_class_instance { $meta; } -sub reset_package_cache_flag { (shift)->{'$!_package_cache_flag'} = undef } +sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef } sub update_package_cache_flag { my $self = shift; # NOTE: @@ -137,7 +137,7 @@ sub update_package_cache_flag { # to our cache as well. This avoids us # having to regenerate the method_map. # - SL - $self->{'$!_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); + $self->{'_package_cache_flag'} = Class::MOP::check_package_cache_flag($self->name); } sub check_metaclass_compatability { @@ -291,22 +291,22 @@ sub create { # all these attribute readers will be bootstrapped # away in the Class::MOP bootstrap section -sub get_attribute_map { $_[0]->{'%!attributes'} } -sub attribute_metaclass { $_[0]->{'$!attribute_metaclass'} } -sub method_metaclass { $_[0]->{'$!method_metaclass'} } -sub instance_metaclass { $_[0]->{'$!instance_metaclass'} } +sub get_attribute_map { $_[0]->{'attributes'} } +sub attribute_metaclass { $_[0]->{'attribute_metaclass'} } +sub method_metaclass { $_[0]->{'method_metaclass'} } +sub instance_metaclass { $_[0]->{'instance_metaclass'} } # FIXME: # this is a prime canidate for conversion to XS sub get_method_map { my $self = shift; - if (defined $self->{'$!_package_cache_flag'} && - $self->{'$!_package_cache_flag'} == Class::MOP::check_package_cache_flag($self->name)) { - return $self->{'%!methods'}; + if (defined $self->{'_package_cache_flag'} && + $self->{'_package_cache_flag'} == Class::MOP::check_package_cache_flag($self->name)) { + return $self->{'methods'}; } - my $map = $self->{'%!methods'}; + my $map = $self->{'methods'}; my $class_name = $self->name; my $method_metaclass = $self->method_metaclass; @@ -348,6 +348,7 @@ sub get_method_map { sub new_object { my $class = shift; + # NOTE: # we need to protect the integrity of the # Class::MOP::Class singletons here, so we @@ -394,10 +395,10 @@ sub get_meta_instance { # is probably needed, but better safe # then sorry. # - SL - $self->{'$!_meta_instance'} = undef - if defined $self->{'$!_package_cache_flag'} && - $self->{'$!_package_cache_flag'} == Class::MOP::check_package_cache_flag($self->name); - $self->{'$!_meta_instance'} ||= $self->instance_metaclass->new( + $self->{'_meta_instance'} = undef + if defined $self->{'_package_cache_flag'} && + $self->{'_package_cache_flag'} == Class::MOP::check_package_cache_flag($self->name); + $self->{'_meta_instance'} ||= $self->instance_metaclass->new( $self, $self->compute_all_applicable_attributes() ); diff --git a/lib/Class/MOP/Immutable.pm b/lib/Class/MOP/Immutable.pm index bddbfbb..bed881d 100644 --- a/lib/Class/MOP/Immutable.pm +++ b/lib/Class/MOP/Immutable.pm @@ -18,9 +18,9 @@ sub new { my ($class, $metaclass, $options) = @_; my $self = bless { - '$!metaclass' => $metaclass, - '%!options' => $options, - '$!immutable_metaclass' => undef, + 'metaclass' => $metaclass, + 'options' => $options, + 'immutable_metaclass' => undef, } => $class; # NOTE: @@ -31,9 +31,9 @@ sub new { return $self; } -sub immutable_metaclass { (shift)->{'$!immutable_metaclass'} } -sub metaclass { (shift)->{'$!metaclass'} } -sub options { (shift)->{'%!options'} } +sub immutable_metaclass { (shift)->{'immutable_metaclass'} } +sub metaclass { (shift)->{'metaclass'} } +sub options { (shift)->{'options'} } sub create_immutable_metaclass { my $self = shift; @@ -43,7 +43,7 @@ sub create_immutable_metaclass { # metaclass is just a anon-class # which shadows the methods # appropriately - $self->{'$!immutable_metaclass'} = Class::MOP::Class->create_anon_class( + $self->{'immutable_metaclass'} = Class::MOP::Class->create_anon_class( superclasses => [ blessed($self->metaclass) ], methods => $self->create_methods_for_immutable_metaclass, ); diff --git a/lib/Class/MOP/Instance.pm b/lib/Class/MOP/Instance.pm index ecc25f9..50cd23e 100644 --- a/lib/Class/MOP/Instance.pm +++ b/lib/Class/MOP/Instance.pm @@ -25,16 +25,16 @@ sub new { # which is *probably* a safe # assumption,.. but you can # never tell <:) - '$!meta' => $meta, - '@!slots' => { map { $_ => undef } @slots }, + 'meta' => $meta, + 'slots' => { map { $_ => undef } @slots }, } => $class; - weaken($instance->{'$!meta'}); + weaken($instance->{'meta'}); return $instance; } -sub associated_metaclass { (shift)->{'$!meta'} } +sub associated_metaclass { (shift)->{'meta'} } sub create_instance { my $self = shift; @@ -55,12 +55,12 @@ sub clone_instance { sub get_all_slots { my $self = shift; - return keys %{$self->{'@!slots'}}; + return keys %{$self->{'slots'}}; } sub is_valid_slot { my ($self, $slot_name) = @_; - exists $self->{'@!slots'}->{$slot_name}; + exists $self->{'slots'}->{$slot_name}; } # operations on created instances diff --git a/lib/Class/MOP/Method.pm b/lib/Class/MOP/Method.pm index 9d8e10a..a9b93e1 100644 --- a/lib/Class/MOP/Method.pm +++ b/lib/Class/MOP/Method.pm @@ -38,15 +38,15 @@ sub wrap { || confess "You must supply the package_name and name parameters $UPGRADE_ERROR_TEXT"; bless { - '&!body' => $code, - '$!package_name' => $params{package_name}, - '$!name' => $params{name}, + 'body' => $code, + 'package_name' => $params{package_name}, + 'name' => $params{name}, } => blessed($class) || $class; } ## accessors -sub body { (shift)->{'&!body'} } +sub body { (shift)->{'body'} } # TODO - add associated_class @@ -54,12 +54,12 @@ sub body { (shift)->{'&!body'} } sub package_name { my $self = shift; - $self->{'$!package_name'} ||= (Class::MOP::get_code_info($self->body))[0]; + $self->{'package_name'} ||= (Class::MOP::get_code_info($self->body))[0]; } sub name { my $self = shift; - $self->{'$!name'} ||= (Class::MOP::get_code_info($self->body))[1]; + $self->{'name'} ||= (Class::MOP::get_code_info($self->body))[1]; } sub fully_qualified_name { diff --git a/lib/Class/MOP/Method/Accessor.pm b/lib/Class/MOP/Method/Accessor.pm index bf06963..afa4340 100644 --- a/lib/Class/MOP/Method/Accessor.pm +++ b/lib/Class/MOP/Method/Accessor.pm @@ -30,19 +30,19 @@ sub new { my $self = bless { # from our superclass - '&!body' => undef, - '$!package_name' => $options{package_name}, - '$!name' => $options{name}, + 'body' => undef, + 'package_name' => $options{package_name}, + 'name' => $options{name}, # specific to this subclass - '$!attribute' => $options{attribute}, - '$!is_inline' => ($options{is_inline} || 0), - '$!accessor_type' => $options{accessor_type}, + 'attribute' => $options{attribute}, + 'is_inline' => ($options{is_inline} || 0), + 'accessor_type' => $options{accessor_type}, } => $class; # we don't want this creating # a cycle in the code, if not # needed - weaken($self->{'$!attribute'}); + weaken($self->{'attribute'}); $self->initialize_body; @@ -51,8 +51,8 @@ sub new { ## accessors -sub associated_attribute { (shift)->{'$!attribute'} } -sub accessor_type { (shift)->{'$!accessor_type'} } +sub associated_attribute { (shift)->{'attribute'} } +sub accessor_type { (shift)->{'accessor_type'} } ## factory @@ -66,7 +66,7 @@ sub initialize_body { ($self->is_inline ? 'inline' : ()) ); - eval { $self->{'&!body'} = $self->$method_name() }; + eval { $self->{'body'} = $self->$method_name() }; die $@ if $@; } diff --git a/lib/Class/MOP/Method/Constructor.pm b/lib/Class/MOP/Method/Constructor.pm index b2d2703..6f9d221 100644 --- a/lib/Class/MOP/Method/Constructor.pm +++ b/lib/Class/MOP/Method/Constructor.pm @@ -25,19 +25,19 @@ sub new { my $self = bless { # from our superclass - '&!body' => undef, - '$!package_name' => $options{package_name}, - '$!name' => $options{name}, + 'body' => undef, + 'package_name' => $options{package_name}, + 'name' => $options{name}, # specific to this subclass - '%!options' => $options{options} || {}, - '$!associated_metaclass' => $options{metaclass}, - '$!is_inline' => ($options{is_inline} || 0), + 'options' => $options{options} || {}, + 'associated_metaclass' => $options{metaclass}, + 'is_inline' => ($options{is_inline} || 0), } => $class; # we don't want this creating # a cycle in the code, if not # needed - weaken($self->{'$!associated_metaclass'}); + weaken($self->{'associated_metaclass'}); $self->initialize_body; @@ -46,19 +46,19 @@ sub new { ## accessors -sub options { (shift)->{'%!options'} } -sub associated_metaclass { (shift)->{'$!associated_metaclass'} } +sub options { (shift)->{'options'} } +sub associated_metaclass { (shift)->{'associated_metaclass'} } ## cached values ... sub meta_instance { my $self = shift; - $self->{'$!meta_instance'} ||= $self->associated_metaclass->get_meta_instance; + $self->{'meta_instance'} ||= $self->associated_metaclass->get_meta_instance; } sub attributes { my $self = shift; - $self->{'@!attributes'} ||= [ $self->associated_metaclass->compute_all_applicable_attributes ] + $self->{'attributes'} ||= [ $self->associated_metaclass->compute_all_applicable_attributes ] } ## method @@ -69,7 +69,7 @@ sub initialize_body { $method_name .= '_inline' if $self->is_inline; - $self->{'&!body'} = $self->$method_name; + $self->{'body'} = $self->$method_name; } sub generate_constructor_method { diff --git a/lib/Class/MOP/Method/Generated.pm b/lib/Class/MOP/Method/Generated.pm index 701c247..1ba8cb0 100644 --- a/lib/Class/MOP/Method/Generated.pm +++ b/lib/Class/MOP/Method/Generated.pm @@ -20,11 +20,11 @@ sub new { my $self = bless { # from our superclass - '&!body' => undef, - '$!package_name' => $options{package_name}, - '$!name' => $options{name}, + 'body' => undef, + 'package_name' => $options{package_name}, + 'name' => $options{name}, # specific to this subclass - '$!is_inline' => ($options{is_inline} || 0), + 'is_inline' => ($options{is_inline} || 0), } => $class; $self->initialize_body; @@ -34,7 +34,7 @@ sub new { ## accessors -sub is_inline { (shift)->{'$!is_inline'} } +sub is_inline { (shift)->{'is_inline'} } sub initialize_body { confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class"; diff --git a/lib/Class/MOP/Method/Wrapped.pm b/lib/Class/MOP/Method/Wrapped.pm index d46ad6e..167d71f 100644 --- a/lib/Class/MOP/Method/Wrapped.pm +++ b/lib/Class/MOP/Method/Wrapped.pm @@ -91,27 +91,27 @@ sub wrap { package_name => $params{package_name} || $code->package_name, name => $params{name} || $code->name, ); - $method->{'%!modifier_table'} = $modifier_table; + $method->{'modifier_table'} = $modifier_table; $method; } sub get_original_method { my $code = shift; - $code->{'%!modifier_table'}->{orig}; + $code->{'modifier_table'}->{orig}; } sub add_before_modifier { my $code = shift; my $modifier = shift; - unshift @{$code->{'%!modifier_table'}->{before}} => $modifier; - $_build_wrapped_method->($code->{'%!modifier_table'}); + unshift @{$code->{'modifier_table'}->{before}} => $modifier; + $_build_wrapped_method->($code->{'modifier_table'}); } sub add_after_modifier { my $code = shift; my $modifier = shift; - push @{$code->{'%!modifier_table'}->{after}} => $modifier; - $_build_wrapped_method->($code->{'%!modifier_table'}); + push @{$code->{'modifier_table'}->{after}} => $modifier; + $_build_wrapped_method->($code->{'modifier_table'}); } { @@ -132,12 +132,12 @@ sub add_after_modifier { sub add_around_modifier { my $code = shift; my $modifier = shift; - unshift @{$code->{'%!modifier_table'}->{around}->{methods}} => $modifier; - $code->{'%!modifier_table'}->{around}->{cache} = $compile_around_method->( - @{$code->{'%!modifier_table'}->{around}->{methods}}, - $code->{'%!modifier_table'}->{orig}->body + unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier; + $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->( + @{$code->{'modifier_table'}->{around}->{methods}}, + $code->{'modifier_table'}->{orig}->body ); - $_build_wrapped_method->($code->{'%!modifier_table'}); + $_build_wrapped_method->($code->{'modifier_table'}); } } diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 8732836..2e8f6c2 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -21,7 +21,7 @@ sub initialize { # until we can bootstrap it no strict 'refs'; return bless { - '$!package' => $package_name, + 'package' => $package_name, # NOTE: # because of issues with the Perl API # to the typeglob in some versions, we @@ -29,7 +29,7 @@ sub initialize { # reference to the hash in the accessor. # Ideally we could just store a ref and # it would Just Work, but oh well :\ - '%!namespace' => \undef, + 'namespace' => \undef, } => $class; } @@ -39,7 +39,7 @@ sub initialize { # all these attribute readers will be bootstrapped # away in the Class::MOP bootstrap section -sub name { $_[0]->{'$!package'} } +sub name { $_[0]->{'package'} } sub namespace { # NOTE: # because of issues with the Perl API @@ -49,7 +49,7 @@ sub namespace { # we could just store a ref and it would # Just Work, but oh well :\ no strict 'refs'; - \%{$_[0]->{'$!package'} . '::'} + \%{$_[0]->{'package'} . '::'} } # utility methods @@ -91,7 +91,7 @@ sub add_package_symbol { ? @{$variable}{qw[name sigil type]} : $self->_deconstruct_variable_name($variable); - my $pkg = $self->{'$!package'}; + my $pkg = $self->{'package'}; no strict 'refs'; no warnings 'redefine', 'misc'; diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 6326f93..343ba27 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -136,22 +136,22 @@ foreach my $non_method_name (qw( # check for the right attributes my @class_mop_package_attributes = ( - '$!package', - '%!namespace', + 'package', + 'namespace', ); my @class_mop_module_attributes = ( - '$!version', - '$!authority' + 'version', + 'authority' ); my @class_mop_class_attributes = ( - '@!superclasses', - '%!methods', - '%!attributes', - '$!attribute_metaclass', - '$!method_metaclass', - '$!instance_metaclass' + 'superclasses', + 'methods', + 'attributes', + 'attribute_metaclass', + 'method_metaclass', + 'instance_metaclass' ); # check class @@ -209,58 +209,58 @@ foreach my $attribute_name (@class_mop_module_attributes) { # ... package -ok($class_mop_package_meta->get_attribute('$!package')->has_reader, '... Class::MOP::Class $!package has a reader'); -is(ref($class_mop_package_meta->get_attribute('$!package')->reader), 'HASH', '... Class::MOP::Class $!package\'s a reader is { name => sub { ... } }'); +ok($class_mop_package_meta->get_attribute('package')->has_reader, '... Class::MOP::Class package has a reader'); +is(ref($class_mop_package_meta->get_attribute('package')->reader), 'HASH', '... Class::MOP::Class package\'s a reader is { name => sub { ... } }'); -ok($class_mop_package_meta->get_attribute('$!package')->has_init_arg, '... Class::MOP::Class $!package has a init_arg'); -is($class_mop_package_meta->get_attribute('$!package')->init_arg, 'package', '... Class::MOP::Class $!package\'s a init_arg is package'); +ok($class_mop_package_meta->get_attribute('package')->has_init_arg, '... Class::MOP::Class package has a init_arg'); +is($class_mop_package_meta->get_attribute('package')->init_arg, 'package', '... Class::MOP::Class package\'s a init_arg is package'); # ... class -ok($class_mop_class_meta->get_attribute('%!attributes')->has_reader, '... Class::MOP::Class %!attributes has a reader'); -is_deeply($class_mop_class_meta->get_attribute('%!attributes')->reader, +ok($class_mop_class_meta->get_attribute('attributes')->has_reader, '... Class::MOP::Class attributes has a reader'); +is_deeply($class_mop_class_meta->get_attribute('attributes')->reader, { 'get_attribute_map' => \&Class::MOP::Class::get_attribute_map }, - '... Class::MOP::Class %!attributes\'s a reader is &get_attribute_map'); + '... Class::MOP::Class attributes\'s a reader is &get_attribute_map'); -ok($class_mop_class_meta->get_attribute('%!attributes')->has_init_arg, '... Class::MOP::Class %!attributes has a init_arg'); -is($class_mop_class_meta->get_attribute('%!attributes')->init_arg, +ok($class_mop_class_meta->get_attribute('attributes')->has_init_arg, '... Class::MOP::Class attributes has a init_arg'); +is($class_mop_class_meta->get_attribute('attributes')->init_arg, 'attributes', - '... Class::MOP::Class %!attributes\'s a init_arg is attributes'); + '... Class::MOP::Class attributes\'s a init_arg is attributes'); -ok($class_mop_class_meta->get_attribute('%!attributes')->has_default, '... Class::MOP::Class %!attributes has a default'); -is_deeply($class_mop_class_meta->get_attribute('%!attributes')->default('Foo'), +ok($class_mop_class_meta->get_attribute('attributes')->has_default, '... Class::MOP::Class attributes has a default'); +is_deeply($class_mop_class_meta->get_attribute('attributes')->default('Foo'), {}, - '... Class::MOP::Class %!attributes\'s a default of {}'); + '... Class::MOP::Class attributes\'s a default of {}'); -ok($class_mop_class_meta->get_attribute('$!attribute_metaclass')->has_reader, '... Class::MOP::Class $!attribute_metaclass has a reader'); -is_deeply($class_mop_class_meta->get_attribute('$!attribute_metaclass')->reader, +ok($class_mop_class_meta->get_attribute('attribute_metaclass')->has_reader, '... Class::MOP::Class attribute_metaclass has a reader'); +is_deeply($class_mop_class_meta->get_attribute('attribute_metaclass')->reader, { 'attribute_metaclass' => \&Class::MOP::Class::attribute_metaclass }, - '... Class::MOP::Class $!attribute_metaclass\'s a reader is &attribute_metaclass'); + '... Class::MOP::Class attribute_metaclass\'s a reader is &attribute_metaclass'); -ok($class_mop_class_meta->get_attribute('$!attribute_metaclass')->has_init_arg, '... Class::MOP::Class $!attribute_metaclass has a init_arg'); -is($class_mop_class_meta->get_attribute('$!attribute_metaclass')->init_arg, +ok($class_mop_class_meta->get_attribute('attribute_metaclass')->has_init_arg, '... Class::MOP::Class attribute_metaclass has a init_arg'); +is($class_mop_class_meta->get_attribute('attribute_metaclass')->init_arg, 'attribute_metaclass', - '... Class::MOP::Class $!attribute_metaclass\'s a init_arg is attribute_metaclass'); + '... Class::MOP::Class attribute_metaclass\'s a init_arg is attribute_metaclass'); -ok($class_mop_class_meta->get_attribute('$!attribute_metaclass')->has_default, '... Class::MOP::Class $!attribute_metaclass has a default'); -is($class_mop_class_meta->get_attribute('$!attribute_metaclass')->default, +ok($class_mop_class_meta->get_attribute('attribute_metaclass')->has_default, '... Class::MOP::Class attribute_metaclass has a default'); +is($class_mop_class_meta->get_attribute('attribute_metaclass')->default, 'Class::MOP::Attribute', - '... Class::MOP::Class $!attribute_metaclass\'s a default is Class::MOP:::Attribute'); + '... Class::MOP::Class attribute_metaclass\'s a default is Class::MOP:::Attribute'); -ok($class_mop_class_meta->get_attribute('$!method_metaclass')->has_reader, '... Class::MOP::Class $!method_metaclass has a reader'); -is_deeply($class_mop_class_meta->get_attribute('$!method_metaclass')->reader, +ok($class_mop_class_meta->get_attribute('method_metaclass')->has_reader, '... Class::MOP::Class method_metaclass has a reader'); +is_deeply($class_mop_class_meta->get_attribute('method_metaclass')->reader, { 'method_metaclass' => \&Class::MOP::Class::method_metaclass }, - '... Class::MOP::Class $!method_metaclass\'s a reader is &method_metaclass'); + '... Class::MOP::Class method_metaclass\'s a reader is &method_metaclass'); -ok($class_mop_class_meta->get_attribute('$!method_metaclass')->has_init_arg, '... Class::MOP::Class $!method_metaclass has a init_arg'); -is($class_mop_class_meta->get_attribute('$!method_metaclass')->init_arg, +ok($class_mop_class_meta->get_attribute('method_metaclass')->has_init_arg, '... Class::MOP::Class method_metaclass has a init_arg'); +is($class_mop_class_meta->get_attribute('method_metaclass')->init_arg, 'method_metaclass', '... Class::MOP::Class $:method_metaclass\'s init_arg is method_metaclass'); -ok($class_mop_class_meta->get_attribute('$!method_metaclass')->has_default, '... Class::MOP::Class $!method_metaclass has a default'); -is($class_mop_class_meta->get_attribute('$!method_metaclass')->default, +ok($class_mop_class_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default'); +is($class_mop_class_meta->get_attribute('method_metaclass')->default, 'Class::MOP::Method', - '... Class::MOP::Class $!method_metaclass\'s a default is Class::MOP:::Method'); + '... Class::MOP::Class method_metaclass\'s a default is Class::MOP:::Method'); # check the values of some of the methods diff --git a/t/014_attribute_introspection.t b/t/014_attribute_introspection.t index 16cf78f..dc1e18c 100644 --- a/t/014_attribute_introspection.t +++ b/t/014_attribute_introspection.t @@ -70,18 +70,18 @@ BEGIN { } my @attributes = ( - '$!name', - '$!accessor', - '$!reader', - '$!writer', - '$!predicate', - '$!clearer', - '$!builder', - '$!init_arg', - '$!initializer', - '$!default', - '$!associated_class', - '@!associated_methods', + 'name', + 'accessor', + 'reader', + 'writer', + 'predicate', + 'clearer', + 'builder', + 'init_arg', + 'initializer', + 'default', + 'associated_class', + 'associated_methods', ); is_deeply(