From: Dave Rolsky Date: Wed, 20 Jan 2010 21:57:45 +0000 (-0600) Subject: Move attribute definition to a public var so we can re-use this for tests X-Git-Tag: 0.11~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-ClassAttribute.git;a=commitdiff_plain;h=963254e04217abd070331648fec46af0e15e44c1 Move attribute definition to a public var so we can re-use this for tests --- diff --git a/t/lib/SharedTests.pm b/t/lib/SharedTests.pm index efedc60..c0da1c5 100644 --- a/t/lib/SharedTests.pm +++ b/t/lib/SharedTests.pm @@ -6,92 +6,86 @@ use warnings; use Scalar::Util qw( isweak ); use Test::More; -{ - package HasClassAttribute; - - use Moose qw( has ); - use MooseX::ClassAttribute; - use MooseX::AttributeHelpers; +use vars qw($Lazy); +$Lazy = 0; - use vars qw($Lazy); - $Lazy = 0; - - class_has 'ObjectCount' => ( +our %Attrs = ( + ObjectCount => { is => 'rw', isa => 'Int', default => 0, - ); - - class_has 'WeakAttribute' => ( + }, + WeakAttribute => { is => 'rw', isa => 'Object', weak_ref => 1, - ); - - class_has 'LazyAttribute' => ( + }, + LazyAttribute => { is => 'rw', isa => 'Int', lazy => 1, - # The side effect is used to test that this was called # lazily. default => sub { $Lazy = 1 }, - ); - - class_has 'ReadOnlyAttribute' => ( + }, + ReadOnlyAttribute => { is => 'ro', isa => 'Int', default => 10, - ); - - class_has 'ManyNames' => ( + }, + ManyNames => { is => 'rw', isa => 'Int', reader => 'M', writer => 'SetM', clearer => 'ClearM', predicate => 'HasM', - ); - - class_has 'Delegatee' => ( + }, + Delegatee => { is => 'rw', isa => 'Delegatee', handles => [ 'units', 'color' ], - # if it's not lazy it makes a new object before we define # Delegatee's attributes. lazy => 1, default => sub { Delegatee->new() }, - ); - - class_has 'Mapping' => ( - metaclass => 'Collection::Hash', - is => 'rw', - isa => 'HashRef[Str]', - default => sub { {} }, - provides => { - exists => 'ExistsInMapping', - keys => 'IdsInMapping', - get => 'GetMapping', - set => 'SetMapping', + }, + Mapping => { + traits => ['Hash'], + is => 'rw', + isa => 'HashRef[Str]', + default => sub { {} }, + handles => { + 'ExistsInMapping' => 'exists', + 'IdsInMapping' => 'keys', + 'GetMapping' => 'get', + 'SetMapping' => 'set', }, - ); - - class_has 'Built' => ( + }, + Built => { is => 'ro', builder => '_BuildIt', - ); - - class_has 'LazyBuilt' => ( + }, + LazyBuilt => { is => 'ro', lazy => 1, builder => '_BuildIt', - ); - - class_has 'Triggerish' => ( + }, + Triggerish => { is => 'rw', trigger => sub { shift->_CallTrigger(@_) }, - ); + }, +); + +{ + package HasClassAttribute; + + use Moose qw( has ); + use MooseX::ClassAttribute; + + while ( my ( $name, $def ) = each %SharedTests::Attrs ) { + class_has $name => %{$def}; + } has 'size' => ( is => 'rw', @@ -220,8 +214,8 @@ sub run_tests { { is( - $HasClassAttribute::Lazy, 0, - '$HasClassAttribute::Lazy is 0' + $SharedTests::Lazy, 0, + '$SharedTests::Lazy is 0' ); is( @@ -230,8 +224,8 @@ sub run_tests { ); is( - $HasClassAttribute::Lazy, 1, - '$HasClassAttribute::Lazy is 1 after calling LazyAttribute' + $SharedTests::Lazy, 1, + '$SharedTests::Lazy is 1 after calling LazyAttribute' ); }