From: gfx Date: Sat, 3 Oct 2009 03:26:06 +0000 (+0900) Subject: Fix tests X-Git-Tag: 0.37_02~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b6c42ac07e8d9c499b948b0f9015978242550336;p=gitmo%2FMouse.git Fix tests --- diff --git a/t/000-recipes/moose_cookbook_meta_recipe3.t b/t/000-recipes/moose_cookbook_meta_recipe3.t index 596fe35..053a4bf 100644 --- a/t/000-recipes/moose_cookbook_meta_recipe3.t +++ b/t/000-recipes/moose_cookbook_meta_recipe3.t @@ -54,7 +54,7 @@ $| = 1; } my $reader = $attribute->get_read_method_ref; - $dump .= ": " . $self->$reader . "\n"; + $dump .= ": " . $reader->($self) . "\n"; } return $dump; diff --git a/t/020_attributes/015_attribute_traits.t b/t/020_attributes/015_attribute_traits.t index 9d89cf5..01e9741 100644 --- a/t/020_attributes/015_attribute_traits.t +++ b/t/020_attributes/015_attribute_traits.t @@ -25,7 +25,7 @@ use Test::Mouse; $self->associated_class->add_method( $self->alias_to, - sub { shift->$reader(@_) }, + $reader, ); }; } diff --git a/t/044-attribute-metaclass.t b/t/044-attribute-metaclass.t index 2e05376..4c0c38d 100644 --- a/t/044-attribute-metaclass.t +++ b/t/044-attribute-metaclass.t @@ -5,7 +5,7 @@ use Test::More tests => 7; use lib 't/lib'; do { - # copied from MouseX::AttributeHelpers; + # copied from MooseX::AttributeHelpers; package MouseX::AttributeHelpers::Trait::Base; use Mouse::Role; use Mouse::Util::TypeConstraints; @@ -57,7 +57,7 @@ do { # extend the parents stuff to make sure # certain bits are now required ... #has 'default' => (required => 1); - has 'type_constraint' => (required => 1); + has 'type_constraint' => (is => 'rw', required => 1); ## Methods called prior to instantiation @@ -203,47 +203,48 @@ do { sub helper_type { 'Num' } - has 'method_constructors' => ( - is => 'ro', - isa => 'HashRef', - lazy => 1, - default => sub { - return +{ - set => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer($_[1]) }; - }, - get => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$reader() }; - }, - add => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer($_[0]->$reader() + $_[1]) }; - }, - sub => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer($_[0]->$reader() - $_[1]) }; + has 'method_constructors' => ( + is => 'ro', + isa => 'HashRef', + lazy => 1, + default => sub { + return +{ + set => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], $_[1] ) }; }, - mul => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer($_[0]->$reader() * $_[1]) }; + get => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $reader->( $_[0] ) }; }, - div => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer($_[0]->$reader() / $_[1]) }; - }, - mod => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer($_[0]->$reader() % $_[1]) }; - }, - abs => sub { - my ($attr, $reader, $writer) = @_; - return sub { $_[0]->$writer(abs($_[0]->$reader()) ) }; - }, - } - } - ); + add => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], $reader->( $_[0] ) + $_[1] ) }; + }, + sub => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], $reader->( $_[0] ) - $_[1] ) }; + }, + mul => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], $reader->( $_[0] ) * $_[1] ) }; + }, + div => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], $reader->( $_[0] ) / $_[1] ) }; + }, + mod => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], $reader->( $_[0] ) % $_[1] ) }; + }, + abs => sub { + my ( $attr, $reader, $writer ) = @_; + return sub { $writer->( $_[0], abs( $reader->( $_[0] ) ) ) }; + }, + }; + } + ); + package MouseX::AttributeHelpers::Number; use Mouse; @@ -278,6 +279,8 @@ do { has 'ii' => ( isa => 'Num', + predicate => 'has_ii', + provides => { sub => 'ii_minus', abs => 'ii_abs', @@ -299,9 +302,11 @@ can_ok 'MyClassWithTraits', qw(ii_minus ii_abs); $k = MyClassWithTraits->new(ii => 10); $k->ii_minus(100); is $k->get_ii, -90; -is $k->ii_abs, 90; +$k->ii_abs; +is $k->get_ii, 90; $k->set_ii(10); is $k->get_ii, 10; -is $k->ii_abs, 10; +$k->ii_abs; +is $k->get_ii, 10;