Skip to content

Commit

Permalink
t/builder.t working again
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Mar 29, 2009
1 parent 5670a12 commit 80f71c5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions t/builder.t
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use strict;
use Test::More tests => 7;
use Test::More tests => 5;
use Test::Exception;
use MooseX::StrictAttributes ();

throws_ok {
package Some::Class;
use Moose;

has foo => (builder => '_build_foo', traits => [qw/ StrictBuilder /]);
has foo => (is => 'ro', builder => '_build_foo', traits => [qw/ StrictBuilder /]);
} qr/No _build_foo method defined for attribute foo/, 'Used as a trait on attributes';

lives_ok {
package Working::Class;
use Moose -traits => [qw/ StrictAttributeBuilders /];
has foo => ( is => 'ro', traits => [qw/ StrictBuilder /]);
use Moose;

has foo => (is => 'ro', builder => '_build_foo', traits => [qw/ StrictBuilder /]);
sub _build_foo { 'bar' }
} 'Ok when build method is present';
} 'StrictBuilder ok on class with build method';

my $i = Working::Class->new;
is($i->foo, 'bar', 'Attribute works as expected');
Expand All @@ -27,7 +28,19 @@ TODO: {
package Some::Class::Redux;
use Moose;

has foo => (builder => '_build_foo', traits => [qw/ StrictBuilder /]);
has foo => (is => 'ro', builder => '_build_foo', traits => [qw/ StrictBuilder /]);
} qr/No _build_foo method defined for attribute foo in class Some::Class::Redux/, 'Used as a trait on attributes';
}

TODO: {
local $TODO = 'Not implemented';
lives_ok {
package RuntimeMethods;
use Moose;
use Sub::Name;

has foo => (is => 'ro', builder => '_build_foo', traits => [qw/ StrictBuilder /]);
*_build_foo = subname _build_foo => sub { 'foo' };
} 'Defining methods at runtime after attribute works';
}

0 comments on commit 80f71c5

Please sign in to comment.