Revision history for Mouse
-0.37_02 Sat Oct 3 15:57:15 2009
+0.37_02
* Mouse::Meta::Attribute
- Add get_read_method_ref() and get_write_method_ref()
}
if (@traits) {
+ warn "traits [@traits] for $class\n";
$class = Mouse::Meta::Class->create_anon_class(
superclasses => [ $class ],
roles => \@traits,
my $accessor =
'#line ' . __LINE__ . ' "' . __FILE__ . "\"\n" .
- sprintf("sub %s {\n", defined($method_name) ? $class->name . '::' . $method_name : '');
+ "sub {\n";
if ($type eq 'accessor' || $type eq 'writer') {
if($type eq 'accessor'){
};
die $e if $e;
- return $code; # returns a CODE ref unless $method_name is passed
+ if(defined $method_name){
+ $class->add_method($method_name => $code);
+ }
+
+ return $code;
}
sub _generate_reader{
my @compiled_constraints = map { $_ ? $_->_compiled_type_constraint : undef }
map { $_->type_constraint } @attrs;
- my $constructor_name = defined($args->{constructor_name})
- ? $associated_metaclass_name . '::' . $args->{constructor_name}
- : '';
- my $code = sprintf("#line %d %s\n", __LINE__, __FILE__).<<"...";
- sub $constructor_name \{
+
+ my $source = sprintf("#line %d %s\n", __LINE__, __FILE__).<<"...";
+ sub \{
my \$class = shift;
return \$class->Mouse::Object::new(\@_)
if \$class ne q{$associated_metaclass_name};
}
...
- local $@;
- my $res = eval $code;
- die $@ if $@;
- $res;
+ my $code;
+ my $e = do{
+ local $@;
+ $code = eval $source;
+ $@;
+ };
+ die $e if $e;
+
+ $metaclass->add_method($args->{constructor_name} => $code);
+ return;
}
sub _generate_processattrs {
};
my $destructor_name = $metaclass->name . '::DESTROY';
- my $code = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"...";
+ my $source = sprintf("#line %d %s\n", __LINE__, __FILE__) . <<"...";
sub $destructor_name \{
my \$self = shift;
$demolishall;
my $e = do{
local $@;
- eval $code;
+ eval $source;
$@;
};
- die $@ if $@;
+ die $e if $e;
return;
}
use Test::More tests => 23;
use Test::Exception;
-use Test::Moose;
-
+use lib 't/lib';
+use Test::Mouse;
{
package My::Attribute::Trait;
- use Moose::Role;
+ use Mouse::Role;
has 'alias_to' => (is => 'ro', isa => 'Str');
);
};
- package Moose::Meta::Attribute::Custom::Trait::Aliased;
+ package Mouse::Meta::Attribute::Custom::Trait::Aliased;
sub register_implementation { 'My::Attribute::Trait' }
}
{
package My::Other::Attribute::Trait;
- use Moose::Role;
+ use Mouse::Role;
my $method = sub {
42;
);
};
- package Moose::Meta::Attribute::Custom::Trait::Other;
+ package Mouse::Meta::Attribute::Custom::Trait::Other;
sub register_implementation { 'My::Other::Attribute::Trait' }
}
{
package My::Class;
- use Moose;
+ use Mouse;
has 'bar' => (
traits => [qw/Aliased/],
{
package My::Derived::Class;
- use Moose;
+ use Mouse;
extends 'My::Class';