---------------------------------------------------------------------
TODO
----------------------------------------------------------------------
-
-- check out what chromatic said:
-
-I think you can check the class key <_ISA to see if it has expired.
-
-- switch to Context::Handle for method modifiers
-
-Should probably write some more tests to verify this works correctly
-when we add it in, to make sure we don't break weird stuff.
-
-- add ::Attribute::Collection types
-
-mugwump was working on this ...
+---------------------------------------------------------------------
- do not bless methods unless asked
use Carp 'confess';
use Scalar::Util 'blessed', 'reftype', 'weaken';
-our $VERSION = '0.12';
+our $VERSION = '0.13';
our $AUTHORITY = 'cpan:STEVAN';
sub meta {
# (all methods below here are kept intact)
sub is_default_a_coderef {
- (reftype($_[0]->{default}) && reftype($_[0]->{default}) eq 'CODE')
+ ('CODE' eq (reftype($_[0]->{default}) || ''))
}
sub default {
## Slot management
sub set_value {
- my ( $self, $instance, $value ) = @_;
+ my ($self, $instance, $value) = @_;
Class::MOP::Class->initialize(Scalar::Util::blessed($instance))
->get_meta_instance
}
sub get_value {
- my ( $self, $instance ) = @_;
+ my ($self, $instance) = @_;
Class::MOP::Class->initialize(Scalar::Util::blessed($instance))
->get_meta_instance
- ->get_slot_value( $instance, $self->name );
+ ->get_slot_value($instance, $self->name);
}
## Method generation helpers
sub generate_accessor_method {
my $attr = shift;
return sub {
- $attr->set_value( $_[0], $_[1] ) if scalar(@_) == 2;
- $attr->get_value( $_[0] );
+ $attr->set_value($_[0], $_[1]) if scalar(@_) == 2;
+ $attr->get_value($_[0]);
};
}
my $attr = shift;
return sub {
confess "Cannot assign a value to a read-only accessor" if @_ > 1;
- $attr->get_value( $_[0] );
+ $attr->get_value($_[0]);
};
}
sub generate_writer_method {
my $attr = shift;
return sub {
- $attr->set_value( $_[0], $_[1] );
+ $attr->set_value($_[0], $_[1]);
};
}
# methods which can *not* be called
-sub add_method { confess 'Cannot call method "add_method" on an immutable instance' }
-sub alias_method { confess 'Cannot call method "alias_method" on an immutable instance' }
-sub remove_method { confess 'Cannot call method "remove_method" on an immutable instance' }
-
-sub add_attribute { confess 'Cannot call method "add_attribute" on an immutable instance' }
-sub remove_attribute { confess 'Cannot call method "remove_attribute" on an immutable instance' }
+sub add_method { confess 'Cannot call method "add_method" on an immutable instance' }
+sub alias_method { confess 'Cannot call method "alias_method" on an immutable instance' }
+sub remove_method { confess 'Cannot call method "remove_method" on an immutable instance' }
+
+sub add_attribute { confess 'Cannot call method "add_attribute" on an immutable instance' }
+sub remove_attribute { confess 'Cannot call method "remove_attribute" on an immutable instance' }
sub add_package_symbol { confess 'Cannot call method "add_package_symbol" on an immutable instance' }
sub remove_package_symbol { confess 'Cannot call method "remove_package_symbol" on an immutable instance' }