Revision history for Perl extension Class-MOP.
-0.23
+0.23 Thurs. March 30, 2006
* Class::MOP::Class
- fixed the way attribute defaults are handled
during instance construction (bug found by chansen)
+
+ * Class::MOP::Attribute
+ - read-only accessors ('reader') will now die if
+ passed more than one argument (attempting to write
+ to them basically)
+ - added tests for this
+ - adjusted all /example files to comply
+
0.22 Mon. March 20, 2006
* Class::MOP::Class
my ($self, $attr_name) = @_;
my $class_name = $self->associated_class->name;
eval qq{sub {
+ Carp::confess "Cannot assign a value to a read-only accessor" if \@_ > 1;
\$_[0]->{'$class_name'}->{'$attr_name'};
}};
}
our $VERSION = '0.04';
+use Carp 'confess';
use Scalar::Util 'refaddr';
use base 'Class::MOP::Attribute';
sub generate_reader_method {
my ($self, $attr_name) = @_;
eval 'sub {
+ confess "Cannot assign a value to a read-only accessor" if @_ > 1;
$' . ($self->associated_class->name . '::' . $attr_name) . '{ refaddr($_[0]) };
}';
}
use strict;
use warnings;
+use Carp 'confess';
+
our $VERSION = '0.02';
use base 'Class::MOP::Attribute';
sub generate_reader_method {
my ($self, $attr_name) = @_;
sub {
+ confess "Cannot assign a value to a read-only accessor" if @_ > 1;
if (!exists $_[0]->{$attr_name}) {
my $attr = $self->associated_class->get_attribute($attr_name);
$_[0]->{$attr_name} = $attr->has_default ? $attr->default($_[0]) : undef;
use Carp 'confess';
use Scalar::Util 'blessed', 'reftype', 'weaken';
-our $VERSION = '0.04';
+our $VERSION = '0.05';
sub meta {
require Class::MOP::Class;
sub generate_reader_method {
my ($self, $attr_name) = @_;
- sub { $_[0]->{$attr_name} };
+ sub {
+ confess "Cannot assign a value to a read-only accessor" if @_ > 1;
+ $_[0]->{$attr_name};
+ };
}
sub generate_writer_method {
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 28;
use Test::Exception;
BEGIN {
is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject');
-$point->x(42);
+dies_ok {
+ $point->x(42);
+} '... cannot write to a read-only accessor';
is($point->x, 2, '... the $.x attribute was not altered');
$point->clear();
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 28;
use Test::Exception;
BEGIN {
is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject');
-$point->x(42);
+dies_ok {
+ $point->x(42);
+} '... cannot write to a read-only accessor';
is($point->x, 2, '... the $.x attribute was not altered');
$point->clear();