0.33_02
* Make sure to work on 5.6.2
+ * Remove Class::Method::Modifiers dependency
+
* Remove testing modules from inc/
0.33_01 Thu Sep 24 16:16:57 2009
push @files, $_
if -f $_
&& !/Squirrel/
+ && !/TypeRegistory/
&& !/\bouse/
&& !/\.sw[po]$/
},
$_[0]->{_create_args}
}
-sub accessor_metaclass { 'Mouse::Meta::Method::Accessor' }
-
sub interpolate_class{
my($class, $name, $args) = @_;
sub coerce_constraint { ## my($self, $value) = @_;
my $type = $_[0]->{type_constraint}
or return $_[1];
- return Mouse::Util::TypeConstraints->typecast_constraints($_[0]->associated_class->name, $_[0]->type_constraint, $_[1]);
+ return Mouse::Util::TypeConstraints->typecast_constraints($_[0]->associated_class->name, $type, $_[1]);
}
sub _canonicalize_handles {
my $self = shift;
my $name = shift;
- return ref($self)->new($name, %{$self}, @_ == 1 ? %{$_[0]} : @_);
+ return ref($self)->new($name, %{$self}, (@_ == 1) ? %{$_[0]} : @_);
}
sub clone_parent {
. "Use \$meta->add_attribute and \$attr->install_accessors instead.");
- $self->create($class, $name, %args);
+ $self->clone_and_inherited_args($class, $name, %args);
}
sub get_parent_args {
my($attribute) = @_;
my $metaclass = $attribute->{associated_class};
- my $generator_class = $attribute->accessor_metaclass;
foreach my $type(qw(accessor reader writer predicate clearer handles)){
if(exists $attribute->{$type}){
my $installer = '_install_' . $type;
- $generator_class->$installer($attribute, $attribute->{$type}, $metaclass);
+
+ Mouse::Meta::Method::Accessor->$installer($attribute, $attribute->{$type}, $metaclass);
+
$attribute->{associated_methods}++;
}
}
if($attribute->can('create') != \&create){
+ # backword compatibility
$attribute->create($metaclass, $attribute->name, %{$attribute});
}
my ( $self, $into, $type, $name, $code ) = @_;
# load Class::Method::Modifiers first
- my $no_cmm_fast = $ENV{MOUSE_NO_CMM_FAST} || do{
+ my $no_cmm_fast = do{
local $@;
eval q{ require Class::Method::Modifiers::Fast };
$@;
my ($class, $metaclass) = @_;
my $associated_metaclass_name = $metaclass->name;
- my @attrs = $metaclass->get_all_attributes;
- my $buildall = $class->_generate_BUILDALL($metaclass);
- my $buildargs = $class->_generate_BUILDARGS($metaclass);
- my $processattrs = $class->_generate_processattrs($metaclass, \@attrs);
+ my @attrs = $metaclass->get_all_attributes;
+
+ my $buildall = $class->_generate_BUILDALL($metaclass);
+ my $buildargs = $class->_generate_BUILDARGS($metaclass);
+ my $processattrs = $class->_generate_processattrs($metaclass, \@attrs);
+
my @compiled_constraints = map { $_ ? $_->{_compiled_type_constraint} : undef } map { $_->{type_constraint} } @attrs;
my $code = <<"...";
sub {
my \$class = shift;
return \$class->Mouse::Object::new(\@_)
- if \$class ne '$associated_metaclass_name';
+ if \$class ne q{$associated_metaclass_name};
$buildargs;
my \$instance = bless {}, \$class;
$processattrs;
...
local $@;
- #warn $code;
my $res = eval $code;
die $@ if $@;
$res;
sub _generate_BUILDARGS {
my($self, $metaclass) = @_;
- if ($metaclass->name->can('BUILDARGS') && $metaclass->name->can('BUILDARGS') != Mouse::Object->can('BUILDARGS')) {
+ if ($metaclass->name->can('BUILDARGS') && $metaclass->name->can('BUILDARGS') != \&Mouse::Object::BUILDARGS) {
return 'my $args = $class->BUILDARGS(@_)';
}
sub _generate_BUILDALL {
my ($class, $metaclass) = @_;
+
return '' unless $metaclass->name->can('BUILD');
- my @code = ();
- push @code, q{no strict 'refs';};
- push @code, q{no warnings 'once';};
- no strict 'refs';
- no warnings 'once';
- for my $klass ($metaclass->linearized_isa) {
- if (*{ $klass . '::BUILD' }{CODE}) {
- unshift @code, qq{${klass}::BUILD(\$instance, \$args);};
+ my @code;
+ for my $class ($metaclass->linearized_isa) {
+ no strict 'refs';
+
+ if (*{ $class . '::BUILD' }{CODE}) {
+ unshift @code, qq{${class}::BUILD(\$instance, \$args);};
}
}
return join "\n", @code;
my $demolishall = do {
if ($meta->name->can('DEMOLISH')) {
my @code = ();
- no strict 'refs';
- for my $klass ($meta->linearized_isa) {
- if (*{$klass . '::DEMOLISH'}{CODE}) {
- push @code, "${klass}::DEMOLISH(\$self);";
+ for my $class ($meta->linearized_isa) {
+ no strict 'refs';
+ if (*{$class . '::DEMOLISH'}{CODE}) {
+ push @code, "${class}::DEMOLISH(\$self);";
}
}
join "\n", @code;
if (scalar @_ == 1) {
(ref($_[0]) eq 'HASH')
|| $class->meta->throw_error("Single parameters to new() must be a HASH ref");
+
return {%{$_[0]}};
}
else {
}
}
-sub DESTROY { shift->DEMOLISHALL }
+sub DESTROY {
+ my $self = shift;
+
+ $self->DEMOLISHALL();
+}
sub BUILDALL {
my $self = shift;
return unless $self->can('BUILD');
for my $class (reverse $self->meta->linearized_isa) {
- no strict 'refs';
- no warnings 'once';
- my $code = *{ $class . '::BUILD' }{CODE}
+ my $build = do{ no strict 'refs'; *{ $class . '::BUILD' }{CODE} }
or next;
- $code->($self, @_);
+
+ $self->$build(@_);
}
return;
}
# that time (at least tests suggest so ;)
foreach my $class (@{ Mouse::Util::get_linear_isa(ref $self) }) {
- my $demolish = do{ no strict 'refs'; *{"${class}::DEMOLISH"}{CODE} };
- $self->$demolish()
- if defined $demolish;
+ my $demolish = do{ no strict 'refs'; *{ $class . '::DEMOLISH'}{CODE} }
+ or next;
+
+ $self->$demolish();
}
return;
}
use base qw/Exporter/;
use Carp qw(confess);
-use B ();
our @EXPORT_OK = qw(
find_meta
my ($coderef) = @_;
ref($coderef) or return;
+ require B;
+
my $cv = B::svref_2object($coderef);
$cv->isa('B::CV') or return;
if ($i + 1 < $max && ref($_[$i + 1])) {
push @roles, [ $_[$i++] => $_[$i] ];
} else {
- push @roles, [ $_[$i] => {} ];
+ push @roles, [ $_[$i] => undef ];
}
my $role_name = $roles[-1][0];
load_class($role_name);
ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
-{
-local $TODO = 'definition_context is not yet implemented';
my $bar_attr = $foo_role->get_attribute('bar');
is($bar_attr->{is}, 'rw',
'bar attribute is rw');
is($bar_attr->{isa}, 'Foo',
'bar attribute isa Foo');
-is(ref($bar_attr->{definition_context}), 'HASH',
- 'bar\'s definition context is a hash');
-is($bar_attr->{definition_context}->{package}, 'FooRole',
- 'bar was defined in FooRole');
+{
+ local $TODO = 'definition_context is not yet implemented';
+ is(ref($bar_attr->{definition_context}), 'HASH',
+ 'bar\'s definition context is a hash');
+ is($bar_attr->{definition_context}->{package}, 'FooRole',
+ 'bar was defined in FooRole');
+}
ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
my $baz_attr = $foo_role->get_attribute('baz');
is($baz_attr->{is}, 'ro',
'baz attribute is ro');
-is(ref($baz_attr->{definition_context}), 'HASH',
- 'bar\'s definition context is a hash');
-is($baz_attr->{definition_context}->{package}, 'FooRole',
- 'baz was defined in FooRole');
-} # end of TODO (definition_context)
+
+{
+ local $TODO = 'definition_context is not yet implemented';
+ is(ref($baz_attr->{definition_context}), 'HASH',
+ 'bar\'s definition context is a hash');
+ is($baz_attr->{definition_context}->{package}, 'FooRole',
+ 'baz was defined in FooRole');
+}
# method modifiers
is( Foo->new->bazes, 'many bazes',
"correct value for 'bazes' before inlining constructor" );
lives_ok { $meta->make_immutable } "Foo is imutable";
- SKIP: {
- skip "Mouse doesn't supports ->identifier, add_role", 2;
- lives_ok { $meta->identifier } "->identifier on metaclass lives";
- dies_ok { $meta->add_role($foo_role) } "Add Role is locked";
- };
+
+ lives_ok { $meta->identifier } "->identifier on metaclass lives";
+ dies_ok { $meta->add_role($foo_role) } "Add Role is locked";
+
lives_ok { Foo->new } "Inlined constructor works with lazy_build";
is( Foo->new->foos, 'many foos',
"correct value for 'foos' after inlining constructor" );