From: Stevan Little Date: Thu, 29 Mar 2007 01:00:21 +0000 (+0000) Subject: adding documentation slot to the attributes X-Git-Tag: 0_19^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ddbdc0cbd3483afc38ce175c9d5694a0a6ed0b8f;p=gitmo%2FMoose.git adding documentation slot to the attributes --- diff --git a/Changes b/Changes index c64a5b3..6304094 100644 --- a/Changes +++ b/Changes @@ -3,7 +3,7 @@ Revision history for Perl extension Moose 0.19 * Moose::Util::TypeConstraints - type now supports messages as well - (thanks to phaylon for finding this) + thanks to phaylon for finding this - added tests for this - added list_all_type_constraints and list_all_builtin_type_constraints @@ -13,7 +13,13 @@ Revision history for Perl extension Moose - fixed regexp 'handles' declarations to build the list of delegated methods correctly (and not override important - things like &new) + things like &new) thanks to ashleyb + for finding this + - added tests and docs for this + - added the "documentation" attributes + so that you can actually document your + attributes and inspect them through the + meta-object. - added tests and docs for this * Moose::Meta::TypeConstraint @@ -21,13 +27,20 @@ Revision history for Perl extension Moose - added test for this * misc. - - added test for working with Module::Refresh + - added tests to assure we work with Module::Refresh + - added stricter test skip logic in the Moose POOP + test, ask Rob Kinyon why. + - *cough* DBM::Deep 1.0 backwards compatability sucks *cough* ;) 0.18 Sat. March 10, 2007 ~~ Many, many documentation updates ~~ - - - We now use Class::MOP::load_class to - load all classes. + + * misc. + - We now use Class::MOP::load_class to + load all classes. + - added tests to show types and subtypes + working with Declare::Constraints::Simple + and Test::Deep as constraint engines. 0.18_001 !! You must have Class::MOP 0.37_001 !! diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index d00d6ff..a0d2469 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -39,6 +39,10 @@ __PACKAGE__->meta->add_attribute('handles' => ( reader => 'handles', predicate => 'has_handles', )); +__PACKAGE__->meta->add_attribute('documentation' => ( + reader => 'documentation', + predicate => 'has_documentation', +)); sub new { my ($class, $name, %options) = @_; @@ -48,9 +52,9 @@ sub new { sub clone_and_inherit_options { my ($self, %options) = @_; - # you can change default, required and coerce + # you can change default, required, coerce and documentation my %actual_options; - foreach my $legal_option (qw(default coerce required)) { + foreach my $legal_option (qw(default coerce required documentation)) { if (exists $options{$legal_option}) { $actual_options{$legal_option} = $options{$legal_option}; delete $options{$legal_option}; @@ -541,6 +545,16 @@ value of an attribute is assigned. The CODE ref will get two values, the invocant and the new value. This can be used to handle I bi-directional relations. +=item B + +This is a string which contains the documentation for this attribute. +It serves no direct purpose right now, but it might in the future +in some kind of automated documentation system perhaps. + +=item B + +Returns true if this meta-attribute has any documentation. + =back =head1 BUGS diff --git a/t/071_misc_attribute_tests.t b/t/071_misc_attribute_tests.t index c28b4a7..3849d64 100644 --- a/t/071_misc_attribute_tests.t +++ b/t/071_misc_attribute_tests.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 6; use Test::Exception; BEGIN { @@ -12,6 +12,30 @@ BEGIN { { { + package Test::Attribute::Inline::Documentation; + use Moose; + + has 'foo' => ( + documentation => q{ + The 'foo' attribute is my favorite + attribute in the whole wide world. + } + ); + } + + my $foo_attr = Test::Attribute::Inline::Documentation->meta->get_attribute('foo'); + + ok($foo_attr->has_documentation, '... the foo has docs'); + is($foo_attr->documentation, + q{ + The 'foo' attribute is my favorite + attribute in the whole wide world. + }, + '... got the foo docs'); +} + +{ + { package Test::For::Lazy::TypeConstraint; use Moose; use Moose::Util::TypeConstraints; diff --git a/t/202_example_Moose_POOP.t b/t/202_example_Moose_POOP.t index 20ab59e..bdd6f1a 100644 --- a/t/202_example_Moose_POOP.t +++ b/t/202_example_Moose_POOP.t @@ -7,7 +7,9 @@ use Test::More; BEGIN { eval "use DBM::Deep 0.983; use DateTime::Format::MySQL;"; - plan skip_all => "DBM::Deep and DateTime::Format::MySQL required for this test" if $@; + if ($@ && DBM::Deep->VERSION < 1.0) { + plan skip_all => "DBM::Deep (< 1.0) and DateTime::Format::MySQL required for this test"; + } plan tests => 89; }