From: John Napiorkowski Date: Thu, 21 Aug 2008 15:20:02 +0000 (+0000) Subject: cleaned up and clarified docs, made the load teset work again, fixed Makefile.PL... X-Git-Tag: 0.01~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types-Structured.git;a=commitdiff_plain;h=309c8a6c87e4d72793a68c005a5347edcccc3bde cleaned up and clarified docs, made the load teset work again, fixed Makefile.PL, updated the Changes doc --- diff --git a/Changes b/Changes index 2ec2bb0..293efdc 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ Revision history for MooseX-Meta-TypeContraint-Structured -0.01 01 August 2008 - First version, released on an unsuspecting world. +0.01 22 August 2008 + Completed basic requirements, documentation and tests. diff --git a/Makefile.PL b/Makefile.PL index f1fcac9..c8669ed 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,7 +1,11 @@ use inc::Module::Install; ## All the required meta information -all_from 'lib/MooseX/Meta/TypeConstraint/Structured.pm'; +abstract 'Supporting structured type contraints'; +author 'John Napiorkowski '; +version '0.01'; +license 'perl'; +perl_version '5.8.8'; ## Module dependencies requires 'Moose' => '0.54'; diff --git a/lib/MooseX/Meta/TypeConstraint/Role/Structured.pm b/lib/MooseX/Meta/TypeConstraint/Role/Structured.pm index d3beb38..6f2afff 100644 --- a/lib/MooseX/Meta/TypeConstraint/Role/Structured.pm +++ b/lib/MooseX/Meta/TypeConstraint/Role/Structured.pm @@ -12,6 +12,23 @@ MooseX::Meta::TypeConstraint::Role::Structured - Structured Type Constraints This Role defines the interface and basic behavior of Structured Type Constraints. +Structured type constraints let you assign an internal pattern of type +constraints to a 'container' constraint. The goal is to make it easier to +declare constraints like "ArrayRef[Int, Int, Str]" where the constraint is an +ArrayRef of three elements and the internal constraint on the three is Int, Int +and Str. + +To accomplish this, we add an attribute to the base L +to hold a L, which is a reference to a pattern of type constraints. +We then override L to check our incoming value to the attribute +against this signature pattern. Additionally we allow L to +hold any optional type constraints. The overall goal is to support something +like: + + has 'attr' => (isa=>'Tuple[Int, Str, Optional[Int, Int]]'); + +These classes define how the underlying support for this works. + =head1 TYPES The following types are defined in this class. diff --git a/lib/MooseX/Meta/TypeConstraint/Structured/Named.pm b/lib/MooseX/Meta/TypeConstraint/Structured/Named.pm index 1bbfa83..ee4b195 100644 --- a/lib/MooseX/Meta/TypeConstraint/Structured/Named.pm +++ b/lib/MooseX/Meta/TypeConstraint/Structured/Named.pm @@ -10,21 +10,34 @@ with 'MooseX::Meta::TypeConstraint::Role::Structured'; MooseX::Meta::TypeConstraint::Structured::Named - Structured Type Constraints -=head1 DESCRIPTION +=head1 SYNOPSIS -Structured type constraints let you assign an internal pattern of type -constraints to a 'container' constraint. The goal is to make it easier to -declare constraints like "ArrayRef[Int, Int, Str]" where the constraint is an -ArrayRef of three elements and the internal constraint on the three is Int, Int -and Str. +The follow is example usage: -To accomplish this, we add an attribute to the base L -to hold a L, which is a reference to a pattern of type constraints. -We then override L to check our incoming value to the attribute -against this signature pattern. + use Moose::Util::TypeConstraints; + use MooseX::Meta::TypeConstraint::Structured::Named; + + my %required = (key1='Str', key2=>'Int'); + my %optional = (key3=>'Object'); + + my $tc = MooseX::Meta::TypeConstraint::Structured::Named->new( + name => 'Dict', + parent => find_type_constraint('HashRef'), + package_defined_in => __PACKAGE__, + signature => {map { + $_ => find_type_constraint($required{$_}); + } keys %required}, + optional_signature => {map { + $_ => find_type_constraint($optional{$_}); + } keys %optional}, + ); + +=head1 DESCRIPTION Named structured Constraints expect the internal constraints to be in keys or -fields similar to what we expect in a HashRef. +fields similar to what we expect in a HashRef. Basically, this allows you to +easily add type constraint checks against values in the wrapping HashRef +identified by the key name. =head1 ATTRIBUTES diff --git a/lib/MooseX/Meta/TypeConstraint/Structured/Positional.pm b/lib/MooseX/Meta/TypeConstraint/Structured/Positional.pm index 83d16af..f51a9d6 100644 --- a/lib/MooseX/Meta/TypeConstraint/Structured/Positional.pm +++ b/lib/MooseX/Meta/TypeConstraint/Structured/Positional.pm @@ -10,21 +10,32 @@ with 'MooseX::Meta::TypeConstraint::Role::Structured'; MooseX::Meta::TypeConstraint::Structured::Positional - Structured Type Constraints -=head1 DESCRIPTION +=head1 SYNOPSIS -Structured type constraints let you assign an internal pattern of type -constraints to a 'container' constraint. The goal is to make it easier to -declare constraints like "ArrayRef[Int, Int, Str]" where the constraint is an -ArrayRef of three elements and the internal constraint on the three is Int, Int -and Str. +The follow is example usage: -To accomplish this, we add an attribute to the base L -to hold a L, which is a reference to a pattern of type constraints. -We then override L to check our incoming value to the attribute -against this signature pattern. + use Moose::Util::TypeConstraints; + use MooseX::Meta::TypeConstraint::Structured::Positional; + + my @required = ('Str', 'Int'); + my @optional = ('Object'); + + my $tc = MooseX::Meta::TypeConstraint::Structured::Positional->new( + name => 'Dict', + parent => find_type_constraint('ArrayRef'), + signature => [map { + find_type_constraint($_); + } @required], + optional_signature => [map { + find_type_constraint($_); + } @optional], + ); + +=head1 DESCRIPTION Positionally structured Constraints expect the internal constraints to be in -'positioned' or ArrayRef style order. +'positioned' or ArrayRef style order. This allows you to add type constraints +to the internal values of the Arrayref. =head1 ATTRIBUTES diff --git a/t/00-load.t b/t/00-load.t index 9c2696b..8e867b2 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -1,9 +1,9 @@ use strict; use warnings; -use Test::More tests=>1; +use Test::More tests=>2; ## List all the modules we want to make sure can at least compile -use_ok 'MooseX::Meta::TypeConstraint::Structured'; - +use_ok 'MooseX::Meta::TypeConstraint::Structured::Named'; +use_ok 'MooseX::Meta::TypeConstraint::Structured::Positional';