From: Stevan Little Date: Mon, 7 Apr 2008 13:27:27 +0000 (+0000) Subject: adding more test and such X-Git-Tag: 0.04~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=91297cb4d55bab5d38c404df82637282a5450661;p=gitmo%2FMooseX-MetaDescription.git adding more test and such --- diff --git a/lib/MooseX/MetaDescription.pm b/lib/MooseX/MetaDescription.pm index 5e35667..dc4a2b0 100644 --- a/lib/MooseX/MetaDescription.pm +++ b/lib/MooseX/MetaDescription.pm @@ -1,13 +1,13 @@ package MooseX::MetaDescription; use Moose; +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; + use MooseX::MetaDescription::Meta::Class; use MooseX::MetaDescription::Meta::Attribute; use MooseX::MetaDescription::Description; -our $VERSION = '0.01'; -our $AUTHORITY = 'cpan:STEVAN'; - no Moose; 1; __END__ diff --git a/lib/MooseX/MetaDescription/Meta/Trait.pm b/lib/MooseX/MetaDescription/Meta/Trait.pm index 1c92218..fd1decb 100644 --- a/lib/MooseX/MetaDescription/Meta/Trait.pm +++ b/lib/MooseX/MetaDescription/Meta/Trait.pm @@ -14,6 +14,7 @@ has 'description' => ( has 'metadescription_classname' => ( is => 'ro', isa => 'Str', + lazy => 1, default => sub { 'MooseX::MetaDescription::Description' } @@ -28,7 +29,7 @@ has 'metadescription' => ( $self->metadescription_classname->new( %{ $self->description }, descriptor => $self, - ) + ); }, ); diff --git a/t/002_custom_description.t b/t/002_custom_description.t new file mode 100644 index 0000000..59c328e --- /dev/null +++ b/t/002_custom_description.t @@ -0,0 +1,112 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More no_plan => 1; +use Test::Exception; + +BEGIN { + use_ok('MooseX::MetaDescription'); +} + +{ + package Foo::Description; + use Moose; + + extends 'MooseX::MetaDescription::Description'; + + has 'bar' => (is => 'ro', isa => 'Str'); + has 'baz' => (is => 'ro', isa => 'Str'); + has 'gorch' => (is => 'ro', isa => 'Str'); + + package Foo::MetaDescription::Trait; + use Moose::Role; + + with 'MooseX::MetaDescription::Meta::Trait'; + + has '+metadescription_classname' => ( + default => 'Foo::Description' + ); + + package Foo::MetaDescription::Attribute; + use Moose; + + extends 'MooseX::MetaDescription::Meta::Attribute'; + with 'Foo::MetaDescription::Trait'; + + has '+metadescription_classname' => ( + default => 'Foo::Description' + ); +} + +{ + package Foo; + use Moose; + + has 'bar' => ( + metaclass => 'Foo::MetaDescription::Attribute', + is => 'ro', + isa => 'Str', + default => sub { 'Foo::bar' }, + description => { + baz => 'Foo::bar::baz', + gorch => 'Foo::bar::gorch', + } + ); + + has 'baz' => ( + traits => [ 'Foo::MetaDescription::Trait' ], + is => 'ro', + isa => 'Str', + default => sub { 'Foo::baz' }, + description => { + bar => 'Foo::baz::bar', + gorch => 'Foo::baz::gorch', + } + ); +} + +# check the meta-desc + +my $bar_attr = Foo->meta->get_attribute('bar'); +isa_ok($bar_attr->metadescription, 'MooseX::MetaDescription::Description'); +isa_ok($bar_attr->metadescription, 'Foo::Description'); +is($bar_attr->metadescription->descriptor, $bar_attr, '... got the circular ref'); + +my $baz_attr = Foo->meta->get_attribute('baz'); +isa_ok($baz_attr->metadescription, 'MooseX::MetaDescription::Description'); +isa_ok($baz_attr->metadescription, 'Foo::Description'); +is($baz_attr->metadescription->descriptor, $baz_attr, '... got the circular ref'); + +# check the actual descs + +foreach my $foo ('Foo', Foo->new) { + + is_deeply( + $foo->meta->get_attribute('bar')->description, + { + baz => 'Foo::bar::baz', + gorch => 'Foo::bar::gorch', + }, + '... got the right class description' + ); + + my $bar_meta_desc = $foo->meta->get_attribute('bar')->metadescription; + is($bar_meta_desc->baz, 'Foo::bar::baz', '... we have methods'); + is($bar_meta_desc->gorch, 'Foo::bar::gorch', '... we have methods'); + + is_deeply( + $foo->meta->get_attribute('baz')->description, + { + bar => 'Foo::baz::bar', + gorch => 'Foo::baz::gorch', + }, + '... got the right class description' + ); + + my $baz_meta_desc = $foo->meta->get_attribute('baz')->metadescription; + is($baz_meta_desc->bar, 'Foo::baz::bar', '... we have methods'); + is($baz_meta_desc->gorch, 'Foo::baz::gorch', '... we have methods'); +} +