r42362 - in /branches/upstream/libmoosex-types-structured-perl/current: Changes MANIFEST META.yml Makefile.PL README inc/Module/Install/AuthorRequires.pm lib/MooseX/Types/Structured.pm
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Fri Aug 21 21:50:45 UTC 2009
Author: jawnsy-guest
Date: Fri Aug 21 21:50:39 2009
New Revision: 42362
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=42362
Log:
[svn-upgrade] Integrating new upstream version, libmoosex-types-structured-perl (0.18)
Added:
branches/upstream/libmoosex-types-structured-perl/current/inc/Module/Install/AuthorRequires.pm
Modified:
branches/upstream/libmoosex-types-structured-perl/current/Changes
branches/upstream/libmoosex-types-structured-perl/current/MANIFEST
branches/upstream/libmoosex-types-structured-perl/current/META.yml
branches/upstream/libmoosex-types-structured-perl/current/Makefile.PL
branches/upstream/libmoosex-types-structured-perl/current/README
branches/upstream/libmoosex-types-structured-perl/current/lib/MooseX/Types/Structured.pm
Modified: branches/upstream/libmoosex-types-structured-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/Changes?rev=42362&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/Changes (original)
+++ branches/upstream/libmoosex-types-structured-perl/current/Changes Fri Aug 21 21:50:39 2009
@@ -1,4 +1,16 @@
Revision history for MooseX-Types-Structured
+
+0.18 17 August 2009
+ - Changed the Makefile.PL to reduce dependencies not needed by users
+ that are not authors. Bumped the revision and released to clear an
+ error with cpan permissions.
+
+0.17 12 August 2009
+ - No new functionality.
+ - Changed the way we specify dependencies in the Makefile.PL to reduce
+ the depth of the dependency chain in cases where we don't need to be
+ running the author quality tests.
+ - Some documentation tweaks.
0.16 28 May 2009
- Fix failing tests and test warnings on MooseX::Types 0.11.
Modified: branches/upstream/libmoosex-types-structured-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/MANIFEST?rev=42362&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/MANIFEST (original)
+++ branches/upstream/libmoosex-types-structured-perl/current/MANIFEST Fri Aug 21 21:50:39 2009
@@ -1,6 +1,7 @@
Changes
inc/Module/AutoInstall.pm
inc/Module/Install.pm
+inc/Module/Install/AuthorRequires.pm
inc/Module/Install/AutoInstall.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
Modified: branches/upstream/libmoosex-types-structured-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/META.yml?rev=42362&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/META.yml (original)
+++ branches/upstream/libmoosex-types-structured-perl/current/META.yml Fri Aug 21 21:50:39 2009
@@ -6,8 +6,6 @@
ExtUtils::MakeMaker: 6.42
Test::Exception: 0.27
Test::More: 0.70
- Test::Pod: 1.14
- Test::Pod::Coverage: 1.08
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
@@ -29,4 +27,4 @@
perl: 5.8.0
resources:
license: http://dev.perl.org/licenses/
-version: 0.16
+version: 0.18
Modified: branches/upstream/libmoosex-types-structured-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/Makefile.PL?rev=42362&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/Makefile.PL (original)
+++ branches/upstream/libmoosex-types-structured-perl/current/Makefile.PL Fri Aug 21 21:50:39 2009
@@ -16,8 +16,10 @@
## Testing dependencies
build_requires 'Test::More' => '0.70';
build_requires 'Test::Exception' => '0.27';
-build_requires 'Test::Pod' => '1.14';
-build_requires 'Test::Pod::Coverage' => '1.08';
+
+## Author tests dependencies
+author_requires 'Test::Pod' => '1.14';
+author_requires 'Test::Pod::Coverage' => '1.08';
## Build README
system 'pod2text lib/MooseX/Types/Structured.pm > README'
Modified: branches/upstream/libmoosex-types-structured-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/README?rev=42362&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/README (original)
+++ branches/upstream/libmoosex-types-structured-perl/current/README Fri Aug 21 21:50:39 2009
@@ -26,6 +26,8 @@
Optional[HashRef],
],
);
+
+ ## Remainder of your class attributes and methods
Then you can instantiate this class with something like:
@@ -75,7 +77,7 @@
first => 'Vanessa',
middle => [1,2],
last => 'Li',
- });
+ });
And these would cause a constraint error for the 'description'
attribute:
@@ -121,22 +123,28 @@
subtype StringFollowedByInt,
as Tuple[Str,Int];
-
+
would constrain it's value to things like ['hello', 111] but ['hello',
'world'] would fail, as well as ['hello', 111, 'world'] and so on.
Here's another example:
+
+ package MyApp::Types;
+
+ use MooseX::Types -declare [qw(StringIntOptionalHashRef)];
+ use MooseX::Types::Moose qw(Str Int);
+ use MooseX::Types::Structured qw(Tuple Optional);
subtype StringIntOptionalHashRef,
as Tuple[
Str, Int,
Optional[HashRef]
];
-
+
This defines a type constraint that validates values like:
['Hello', 100, {key1 => 'value1', key2 => 'value2'}];
['World', 200];
-
+
Notice that the last type constraint in the structure is optional. This
is enabled via the helper Optional type constraint, which is a variation
of the core Moose type constraint 'Maybe'. The main difference is that
@@ -145,13 +153,15 @@
validate:
StringIntOptionalHashRef->validate(['Hello Undefined', 1000, undef]);
-
+
Please note the subtle difference between undefined and null. If you
wish to allow both null and undefined, you should use the core Moose
'Maybe' type constraint instead:
+ package MyApp::Types;
+
use MooseX::Types -declare [qw(StringIntMaybeHashRef)];
- use MooseX::Types::Moose qw(Maybe);
+ use MooseX::Types::Moose qw(Str Int Maybe);
use MooseX::Types::Structured qw(Tuple);
subtype StringIntMaybeHashRef,
@@ -166,7 +176,8 @@
['World', 200];
Structured constraints are not limited to arrays. You can define a
- structure against a HashRef with 'Dict' as in this example:
+ structure against a HashRef with the 'Dict' type constaint as in this
+ example:
subtype FirstNameLastName,
as Dict[
@@ -174,10 +185,10 @@
lastname => Str,
];
- This would constrain a HashRef to something like:
-
- {firstname => 'Christopher', lastname= > 'Parsons'};
-
+ This would constrain a HashRef that validates something like:
+
+ {firstname => 'Christopher', lastname => 'Parsons'};
+
but all the following would fail validation:
## Incorrect keys
@@ -187,7 +198,7 @@
{firstname => 'Christopher', lastname => 'Parsons', middlename => 'Allen'};
## Not a HashRef
- ['Christopher', 'Christopher'];
+ ['Christopher', 'Parsons'];
These structures can be as simple or elaborate as you wish. You can even
combine various structured, parameterized and simple constraints all
@@ -199,11 +210,31 @@
Dict[name=>Str, age=>Int],
ArrayRef[Int]
];
-
- Which would match "[1, {name=>'John', age=>25},[10,11,12]]". Please
- notice how the type parameters can be visually arranged to your liking
- and to improve the clarity of your meaning. You don't need to run then
- altogether onto a single line.
+
+ Which would match:
+
+ [1, {name=>'John', age=>25},[10,11,12]];
+
+ Please notice how the type parameters can be visually arranged to your
+ liking and to improve the clarity of your meaning. You don't need to run
+ then altogether onto a single line. Additionally, since the 'Dict' type
+ constraint defines a hash constraint, the key order is not meaningful.
+ For example:
+
+ subtype AnyKeyOrder,
+ as Dict[
+ key1=>Int,
+ key2=>Str,
+ key3=>Int,
+ ];
+
+ Would validate both:
+
+ {key1 => 1, key2 => "Hi!", key3 => 2};
+ {key2 => "Hi!", key1 => 100, key3 => 300};
+
+ As you would expect, since underneath its just a plain old Perl hash at
+ work.
Alternatives
You should exercise some care as to whether or not your complex
@@ -227,7 +258,7 @@
age_in_years => 39,
),
);
-
+
This method may take some additional time to setup but will give you
more flexibility. However, structured constraints are highly compatible
with this method, granting some interesting possibilities for coercion.
@@ -276,15 +307,15 @@
);
};
- has person => (isa=>MyStruct);
-
+ has person => (isa=>MyStruct);
+
This would allow you to instantiate with something like:
my $obj = MyApp::MyClass->new( person => {
full_name=>'John Napiorkowski',
age_in_years=>39,
});
-
+
Or even:
my $obj = MyApp::MyClass->new( person => {
@@ -309,7 +340,7 @@
name => Str,
total_friends => Int,
];
-
+
This will actually work BUT you have to take care that the subtype has a
structure that does not contradict the structure of it's parent. For now
the above works, but I will clarify the syntax for this at a future
@@ -359,7 +390,7 @@
age =>$age->years
}
};
-
+
And that should just work as expected. However, if there are any 'inner'
coercions, such as a coercion on 'Fullname' or on 'DateTime', that
coercion won't currently get activated.
@@ -380,7 +411,7 @@
ArrayRef[Person]
],
];
-
+
This would declare a Person subtype that contains a name and an optional
ArrayRef of Persons who are friends as in:
@@ -407,7 +438,7 @@
Str,
Str|Tuple,
];
-
+
Which validates:
[
@@ -436,15 +467,26 @@
Tuple[Int,Str]; ## Validates [1,'hello']
Tuple[Str|Object, Int]; ## Validates ['hello', 1] or [$object, 2]
+ The Values of @constraints should ideally be MooseX::Types declared type
+ constraints. We do support 'old style' Moose string based constraints to
+ a limited degree but these string type constraints are considered
+ deprecated. There will be limited support for bugs resulting from mixing
+ string and MooseX::Types in your structures. If you encounter such a bug
+ and really need it fixed, we will required a detailed test case at the
+ minimum.
+
Dict[%constraints]
This defines a HashRef based constraint which allowed you to validate a
specific hashref. For example:
Dict[name=>Str, age=>Int]; ## Validates {name=>'John', age=>39}
+ The keys in %constraints follow the same rules as @constraints in the
+ above section.
+
Optional[$constraint]
This is primarily a helper constraint for Dict and Tuple type
- constraints. What this allows if for you to assert that a given type
+ constraints. What this allows is for you to assert that a given type
constraint is allowed to be null (but NOT undefined). If the value is
null, then the type constraint passes but if the value is defined it
must validate against the type constraint. This makes it easy to make a
@@ -456,7 +498,7 @@
last=>Str,
middle=>Optional[Str],
];
-
+
Creates a constraint that validates against a hashref with the keys
'first' and 'last' being strings and required while an optional key
'middle' is must be a string if it appears but doesn't have to appear.
@@ -464,6 +506,9 @@
{first=>'John', middle=>'James', last=>'Napiorkowski'}
{first=>'Vanessa', last=>'Li'}
+
+ If you use the 'Maybe' type constraint instead, your values will also
+ validate against 'undef', which may be incorrect for you.
EXPORTABLE SUBROUTINES
This type library makes available for export the following subroutines
@@ -506,7 +551,7 @@
This will now work as expected, validating ArrayRef structures such as:
[1,"hello", $obj, 2,3,4,5,6,...]
-
+
A few caveats apply. First, the slurpy type constraint must be the last
one in the list of type constraint parameters. Second, the parent type
of the slurpy type constraint must match that of the containing type
@@ -590,7 +635,7 @@
}};
has person => (is=>'rw', isa=>Person, coerce=>1);
-
+
And now you can instantiate with all the following:
__PACKAGE__->new(
@@ -621,7 +666,7 @@
),
},
);
-
+
This technique is a way to support various ways to instantiate your
class in a clean and declarative way.
@@ -634,18 +679,17 @@
TODO
Here's a list of stuff I would be happy to get volunteers helping with:
- All POD examples need test cases in t/documentation/*.t Want to break
- out the examples section to a separate cookbook style POD. Want more
- examples and best practice / usage guidance for authors Need to clarify
- deep coercions,
+ * All POD examples need test cases in t/documentation/*.t
+ * Want to break out the examples section to a separate cookbook style POD.
+ * Want more examples and best practice / usage guidance for authors
+ * Need to clarify deep coercions,
AUTHOR
- Copyright 2008-2009, John Napiorkowski <jjnapiork at cpan.org>
-
- John Napiorkowski, "<jjnapiork at cpan.org>"
+ John Napiorkowski "<jjnapiork at cpan.org>"
CONTRIBUTORS
- The Following people have contributed to this module:
+ The following people have contributed to this module and agree with the
+ listed Copyright & license information included below:
Florian Ragwitz, C<< <rafl at debian.org> >>
Yuval Kogman, C<< <nothingmuch at woobling.org> >>
Added: branches/upstream/libmoosex-types-structured-perl/current/inc/Module/Install/AuthorRequires.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/inc/Module/Install/AuthorRequires.pm?rev=42362&op=file
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/inc/Module/Install/AuthorRequires.pm (added)
+++ branches/upstream/libmoosex-types-structured-perl/current/inc/Module/Install/AuthorRequires.pm Fri Aug 21 21:50:39 2009
@@ -1,0 +1,38 @@
+#line 1
+use strict;
+use warnings;
+
+package Module::Install::AuthorRequires;
+
+use base 'Module::Install::Base';
+
+# cargo cult
+BEGIN {
+ our $VERSION = '0.02';
+ our $ISCORE = 1;
+}
+
+sub author_requires {
+ my $self = shift;
+
+ return $self->{values}->{author_requires}
+ unless @_;
+
+ my @added;
+ while (@_) {
+ my $mod = shift or last;
+ my $version = shift || 0;
+ push @added, [$mod => $version];
+ }
+
+ push @{ $self->{values}->{author_requires} }, @added;
+ $self->admin->author_requires(@added);
+
+ return map { @$_ } @added;
+}
+
+1;
+
+__END__
+
+#line 92
Modified: branches/upstream/libmoosex-types-structured-perl/current/lib/MooseX/Types/Structured.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-structured-perl/current/lib/MooseX/Types/Structured.pm?rev=42362&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-structured-perl/current/lib/MooseX/Types/Structured.pm (original)
+++ branches/upstream/libmoosex-types-structured-perl/current/lib/MooseX/Types/Structured.pm Fri Aug 21 21:50:39 2009
@@ -10,7 +10,7 @@
use Devel::PartialDump;
use Scalar::Util qw(blessed);
-our $VERSION = '0.16';
+our $VERSION = '0.18';
our $AUTHORITY = 'cpan:JJNAPIORK';
=head1 NAME
@@ -43,6 +43,8 @@
Optional[HashRef],
],
);
+
+ ## Remainder of your class attributes and methods
Then you can instantiate this class with something like:
@@ -143,6 +145,12 @@
would fail, as well as ['hello', 111, 'world'] and so on. Here's another
example:
+ package MyApp::Types;
+
+ use MooseX::Types -declare [qw(StringIntOptionalHashRef)];
+ use MooseX::Types::Moose qw(Str Int);
+ use MooseX::Types::Structured qw(Tuple Optional);
+
subtype StringIntOptionalHashRef,
as Tuple[
Str, Int,
@@ -166,8 +174,10 @@
allow both null and undefined, you should use the core Moose 'Maybe' type
constraint instead:
+ package MyApp::Types;
+
use MooseX::Types -declare [qw(StringIntMaybeHashRef)];
- use MooseX::Types::Moose qw(Maybe);
+ use MooseX::Types::Moose qw(Str Int Maybe);
use MooseX::Types::Structured qw(Tuple);
subtype StringIntMaybeHashRef,
@@ -182,7 +192,7 @@
['World', 200];
Structured constraints are not limited to arrays. You can define a structure
-against a HashRef with 'Dict' as in this example:
+against a HashRef with the 'Dict' type constaint as in this example:
subtype FirstNameLastName,
as Dict[
@@ -190,9 +200,9 @@
lastname => Str,
];
-This would constrain a HashRef to something like:
-
- {firstname => 'Christopher', lastname= > 'Parsons'};
+This would constrain a HashRef that validates something like:
+
+ {firstname => 'Christopher', lastname => 'Parsons'};
but all the following would fail validation:
@@ -203,7 +213,7 @@
{firstname => 'Christopher', lastname => 'Parsons', middlename => 'Allen'};
## Not a HashRef
- ['Christopher', 'Christopher'];
+ ['Christopher', 'Parsons'];
These structures can be as simple or elaborate as you wish. You can even
combine various structured, parameterized and simple constraints all together:
@@ -215,10 +225,28 @@
ArrayRef[Int]
];
-Which would match "[1, {name=>'John', age=>25},[10,11,12]]". Please notice how
-the type parameters can be visually arranged to your liking and to improve the
-clarity of your meaning. You don't need to run then altogether onto a single
-line.
+Which would match:
+
+ [1, {name=>'John', age=>25},[10,11,12]];
+
+Please notice how the type parameters can be visually arranged to your liking
+and to improve the clarity of your meaning. You don't need to run then
+altogether onto a single line. Additionally, since the 'Dict' type constraint
+defines a hash constraint, the key order is not meaningful. For example:
+
+ subtype AnyKeyOrder,
+ as Dict[
+ key1=>Int,
+ key2=>Str,
+ key3=>Int,
+ ];
+
+Would validate both:
+
+ {key1 => 1, key2 => "Hi!", key3 => 2};
+ {key2 => "Hi!", key1 => 100, key3 => 300};
+
+As you would expect, since underneath its just a plain old Perl hash at work.
=head2 Alternatives
@@ -455,6 +483,13 @@
Tuple[Int,Str]; ## Validates [1,'hello']
Tuple[Str|Object, Int]; ## Validates ['hello', 1] or [$object, 2]
+The Values of @constraints should ideally be L<MooseX::Types> declared type
+constraints. We do support 'old style' L<Moose> string based constraints to a
+limited degree but these string type constraints are considered deprecated.
+There will be limited support for bugs resulting from mixing string and
+L<MooseX::Types> in your structures. If you encounter such a bug and really
+need it fixed, we will required a detailed test case at the minimum.
+
=head2 Dict[%constraints]
This defines a HashRef based constraint which allowed you to validate a specific
@@ -462,10 +497,13 @@
Dict[name=>Str, age=>Int]; ## Validates {name=>'John', age=>39}
+The keys in %constraints follow the same rules as @constraints in the above
+section.
+
=head2 Optional[$constraint]
This is primarily a helper constraint for Dict and Tuple type constraints. What
-this allows if for you to assert that a given type constraint is allowed to be
+this allows is for you to assert that a given type constraint is allowed to be
null (but NOT undefined). If the value is null, then the type constraint passes
but if the value is defined it must validate against the type constraint. This
makes it easy to make a Dict where one or more of the keys doesn't have to exist
@@ -484,6 +522,9 @@
{first=>'John', middle=>'James', last=>'Napiorkowski'}
{first=>'Vanessa', last=>'Li'}
+
+If you use the 'Maybe' type constraint instead, your values will also validate
+against 'undef', which may be incorrect for you.
=head1 EXPORTABLE SUBROUTINES
@@ -810,20 +851,19 @@
Here's a list of stuff I would be happy to get volunteers helping with:
-All POD examples need test cases in t/documentation/*.t
-Want to break out the examples section to a separate cookbook style POD.
-Want more examples and best practice / usage guidance for authors
-Need to clarify deep coercions,
+ * All POD examples need test cases in t/documentation/*.t
+ * Want to break out the examples section to a separate cookbook style POD.
+ * Want more examples and best practice / usage guidance for authors
+ * Need to clarify deep coercions,
=head1 AUTHOR
-Copyright 2008-2009, John Napiorkowski <jjnapiork at cpan.org>
-
-John Napiorkowski, C<< <jjnapiork at cpan.org> >>
+John Napiorkowski C<< <jjnapiork at cpan.org> >>
=head1 CONTRIBUTORS
-The Following people have contributed to this module:
+The following people have contributed to this module and agree with the listed
+Copyright & license information included below:
Florian Ragwitz, C<< <rafl at debian.org> >>
Yuval Kogman, C<< <nothingmuch at woobling.org> >>
@@ -832,8 +872,8 @@
Copyright 2008-2009, John Napiorkowski <jjnapiork at cpan.org>
-This program is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+This program is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
=cut
More information about the Pkg-perl-cvs-commits
mailing list