use Carp 'confess';
use Scalar::Util 'blessed', 'reftype', 'weaken';
-our $VERSION = '0.10';
+our $VERSION = '0.12';
+our $AUTHORITY = 'cpan:STEVAN';
+
+use base 'Class::MOP::Object';
sub meta {
require Class::MOP::Class;
(defined $name && $name)
|| confess "You must provide a name for the attribute";
+
$options{init_arg} = $name
if not exists $options{init_arg};
+ (is_default_a_coderef(\%options))
+ || confess("References are not allowed as default values, you must ".
+ "wrap then in a CODE reference (ex: sub { [] } and not [])")
+ if exists $options{default} && ref $options{default};
+
bless {
name => $name,
accessor => $options{accessor},
# (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]);
};
}
use Class::MOP::Method;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
+our $AUTHORITY = 'cpan:STEVAN';
-our @ISA = ('Class::MOP::Method');
+use base 'Class::MOP::Method';
1;