Revision history for Perl extension Class-MOP.
+0.33
+ * Class::MOP::Attribute
+ - reference values (other than CODE refs)
+ are no longer allowed for defaults
+ - added tests for this
+
0.32 Sat. Aug. 12, 2006
+ added Class::MOP::Object so that the
metamodel is more complete (and closer
-Class::MOP version 0.32
+Class::MOP version 0.33
===========================
See the individual module documentation for more information
use Class::MOP::Class::Immutable;
-our $VERSION = '0.32';
+our $VERSION = '0.33';
our $AUTHORITY = 'cpan:STEVAN';
## ----------------------------------------------------------------------------
|| confess "You must provide a name for the attribute";
$options{init_arg} = $name
if not exists $options{init_arg};
+
+ (Class::MOP::Attribute::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};
# return the new object
$class->meta->new_object(name => $name, %options);
use Carp 'confess';
use Scalar::Util 'blessed', 'reftype', 'weaken';
-our $VERSION = '0.11';
+our $VERSION = '0.12';
our $AUTHORITY = 'cpan:STEVAN';
sub meta {
$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},
use strict;
use warnings;
-use Test::More tests => 20;
+use Test::More tests => 23;
use Test::Exception;
BEGIN {
use_ok('Class::MOP::Attribute');
}
+# most values are static
{
- my $regexp = qr/hello (.*)/;
- my $attr = Class::MOP::Attribute->new('$test' => (
- default => $regexp
- ));
+ dies_ok {
+ Class::MOP::Attribute->new('$test' => (
+ default => qr/hello (.*)/
+ ));
+ } '... no refs for defaults';
+
+ dies_ok {
+ Class::MOP::Attribute->new('$test' => (
+ default => []
+ ));
+ } '... no refs for defaults';
+
+ dies_ok {
+ Class::MOP::Attribute->new('$test' => (
+ default => {}
+ ));
+ } '... no refs for defaults';
+
- ok($attr->has_default, '... we have a default value');
- is($attr->default, $regexp, '... and got the value we expected');
+ dies_ok {
+ Class::MOP::Attribute->new('$test' => (
+ default => \(my $var)
+ ));
+ } '... no refs for defaults';
+
+ dies_ok {
+ Class::MOP::Attribute->new('$test' => (
+ default => bless {} => 'Foo'
+ ));
+ } '... no refs for defaults';
+
}
{ # bad construtor args