diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000..88d8d80 --- /dev/null +++ b/.mailmap @@ -0,0 +1,4 @@ +Ivan Butorin +Chris White +Chris White +Toby Inkster diff --git a/Changes b/Changes index a971165..bff3e41 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Class-Tiny-ConstrainedAccessor +0.000013 2019-10-02 + - Arguments can now be provided in a hashref (#7). + Thanks to FISHBONE for code. + 0.000012 2019-09-20 - Production release of 0.000011 @@ -31,16 +35,16 @@ Revision history for Class-Tiny-ConstrainedAccessor - Fix tests to run on <5.010 0.000004 2019-03-22 - - Check constructor parameters (GH-4) - - Add option to suppress BUILD generation (GH-5) + - Check constructor parameters (#4) + - Add option to suppress BUILD generation (#5) 0.000003 2019-03-19 - Updated documentation. First non-TRIAL release. 0.000002 2019-03-17 (TRIAL VERSION) - - Support other type systems (GH-1). Thanks to TOBYINK for code. - - Constraint-check default values (GH-3). - - Run as far back as 5.006 (GH-2). + - Support other type systems (#1). Thanks to TOBYINK for code. + - Constraint-check default values (#3). + - Run as far back as 5.006 (#2). 0.000001 2019-03-12 (TRIAL VERSION) - First version, released on an unsuspecting world. diff --git a/MANIFEST b/MANIFEST index 137ed6e..a9075d6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,6 +19,7 @@ t/08-custom-constraint.t t/10-moox-types-mooselike.t t/11-mousex-types.t t/12-specio.t +t/13-type-tiny-hashref.t t/MY/Class/CustomConstraint.pm t/MY/Class/MooseXTypes.pm t/MY/Class/MooXTypesMooseLike.pm @@ -27,6 +28,7 @@ t/MY/Class/Specio.pm t/MY/Class/TypeTiny.pm t/MY/Class/TypeTinyBadDefaults.pm t/MY/Class/TypeTinyBUILD.pm +t/MY/Class/TypeTinyHashref.pm t/MY/Class/TypeTinyNOBUILD.pm t/MY/Class/ValueIsValid.pm t/MY/Helpers.pm diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index cbfb515..1e7aada 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -1,6 +1,7 @@ # Files used only for development ^\.editorconfig ^\.[^\\\/]*\.yml +^\.mailmap # Miscellaneous \bfoo\b.* diff --git a/Makefile.PL b/Makefile.PL index c74f142..bab8588 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -202,7 +202,9 @@ my %opts = ( x_contributors => [ # Use CPAN emails so MetaCPAN will pick them up. + # In alphabetical order, except for the original author. 'Christopher White ', + 'Ivan Butorin ', 'Toby Inkster ', ], diff --git a/README b/README index 1794d24..797be40 100644 --- a/README +++ b/README @@ -55,11 +55,19 @@ CONSTRAINTS WITHOUT A TYPE SYSTEM SUBROUTINES import - Creates the accessors you have requested. Basic usage: + Creates the accessors you have requested. Constraints can be passed as a + list or hashref of variable/constraint pairs. Basic usage: + # Constraints are passed as a list of pairs use Class::Tiny::ConstrainedAccessor name => constraint - [, name => constraint ...]; # ... any number of name=>constraint pairs + [, name2 => constraint ...]; # ... any number of name=>constraint pairs + + # Constraints are passed as a hashref + use Class::Tiny::ConstrainedAccessor { + name => constraint, + [, name2 => constraint ...]; # ... any number of name=>constraint pairs + }; This also creates a BUILD() subroutine to check the constructor parameters, if a "BUILD()" doesn't already exist. @@ -71,8 +79,8 @@ SUBROUTINES OPTIONS To specify options, pass an arrayref as the first argument on the `use` - line. This is to leave room for someday carrying attributes and - constraints in a hashref. For example: + line. This is because a hashref carries attributes and constraints. For + example: use Class::Tiny::ConstrainedAccessor [ OPTION=>value ], name => constraint ...; @@ -92,7 +100,7 @@ OPTIONS AUTHORS Created by Christopher White, "". Thanks to - Toby Inkster for code contributions. + Toby Inkster (TOBYINK) and Ivan Butorin (FISHBONE) for code contributions. BUGS Please report any bugs or feature requests through the GitHub Issues @@ -112,12 +120,12 @@ SUPPORT - * Search CPAN + * MetaCPAN - + LICENSE - Copyright 2019 Christopher White. + Copyright 2019 Christopher White and contributors. This program is free software; you can redistribute it and/or modify it under the terms of the the Apache License (2.0). You may obtain a copy of diff --git a/README.md b/README.md index 377e98f..36fc094 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,19 @@ for optimization than general-purpose type systems. ## import -Creates the accessors you have requested. Basic usage: +Creates the accessors you have requested. Constraints can be passed as a list +or hashref of variable/constraint pairs. Basic usage: + # Constraints are passed as a list of pairs use Class::Tiny::ConstrainedAccessor name => constraint - [, name => constraint ...]; # ... any number of name=>constraint pairs + [, name2 => constraint ...]; # ... any number of name=>constraint pairs + + # Constraints are passed as a hashref + use Class::Tiny::ConstrainedAccessor { + name => constraint, + [, name2 => constraint ...]; # ... any number of name=>constraint pairs + }; This also creates a [BUILD()](https://metacpan.org/pod/Class::Tiny#BUILD) subroutine to check the constructor parameters, if a `BUILD()` doesn't already exist. @@ -77,8 +85,8 @@ own `BUILD()` if you want to. # OPTIONS To specify options, pass an **arrayref** as the first argument on the \`use\` -line. This is to leave room for someday carrying attributes and constraints in -a hashref. For example: +line. This is because a hashref carries attributes and constraints. +For example: use Class::Tiny::ConstrainedAccessor [ OPTION=>value ], name => constraint ...; @@ -100,7 +108,7 @@ Valid options are: # AUTHORS Created by Christopher White, ``. Thanks to -Toby Inkster for code contributions. +Toby Inkster (TOBYINK) and Ivan Butorin (FISHBONE) for code contributions. # BUGS @@ -121,13 +129,13 @@ You can also look for information at: [https://github.com/cxw42/Class-Tiny-ConstrainedAccessor](https://github.com/cxw42/Class-Tiny-ConstrainedAccessor) -- Search CPAN +- MetaCPAN - [https://metacpan.org/release/Class-Tiny-ConstrainedAccessor](https://metacpan.org/release/Class-Tiny-ConstrainedAccessor) + [https://metacpan.org/pod/Class::Tiny::ConstrainedAccessor](https://metacpan.org/pod/Class::Tiny::ConstrainedAccessor) # LICENSE -Copyright 2019 Christopher White. +Copyright 2019 Christopher White and contributors. This program is free software; you can redistribute it and/or modify it under the terms of the the Apache License (2.0). You may obtain a diff --git a/lib/Class/Tiny/ConstrainedAccessor.pm b/lib/Class/Tiny/ConstrainedAccessor.pm index 1efa16a..de0880f 100644 --- a/lib/Class/Tiny/ConstrainedAccessor.pm +++ b/lib/Class/Tiny/ConstrainedAccessor.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Class::Tiny; -our $VERSION = '0.000012'; +our $VERSION = '0.000013'; # Docs {{{1 @@ -23,7 +23,6 @@ can come from L, L, L, L, or L. Alternatively, constraints can be applied using the technique described in L<"Constraints without a type system"|/CONSTRAINTS WITHOUT A TYPE SYSTEM>. -Constraints can be passed as a B or a B. Example of a class using this package: @@ -72,17 +71,19 @@ for optimization than general-purpose type systems. =head2 import -Creates the accessors you have requested. Basic usage: +Creates the accessors you have requested. Constraints can be passed as a list +or hashref of variable/constraint pairs. Basic usage: - # constraints are passed as a hash + # Constraints are passed as a list of pairs use Class::Tiny::ConstrainedAccessor name => constraint - [, name => constraint ...]; # ... any number of name=>constraint pairs + [, name2 => constraint ...]; # ... any number of name=>constraint pairs - # constraints are passed as a hashref + # Constraints are passed as a hashref use Class::Tiny::ConstrainedAccessor { name => constraint, - } + [, name2 => constraint ...]; # ... any number of name=>constraint pairs + }; This also creates a L subroutine to check the constructor parameters, if a C doesn't already exist. @@ -95,8 +96,8 @@ own C if you want to. =head1 OPTIONS To specify options, pass an B as the first argument on the `use` -line. This is to leave room for someday carrying attributes and constraints in -a hashref. For example: +line. This is because a hashref carries attributes and constraints. +For example: use Class::Tiny::ConstrainedAccessor [ OPTION=>value ], name => constraint ...; @@ -131,7 +132,6 @@ sub import { %opts = @{+shift} if ref $_[0] eq 'ARRAY'; my %constraints; - # Both hashref and hash are supported for constraints if (ref $_[0] eq 'HASH' && scalar @_ == 1) { %constraints = %{$_[0]}; } else { @@ -292,7 +292,7 @@ __END__ =head1 AUTHORS Created by Christopher White, C<< >>. Thanks to -Toby Inkster for code contributions. +Toby Inkster (TOBYINK) and Ivan Butorin (FISHBONE) for code contributions. =head1 BUGS @@ -315,15 +315,15 @@ You can also look for information at: L -=item * Search CPAN +=item * MetaCPAN -L +L =back =head1 LICENSE -Copyright 2019 Christopher White. +Copyright 2019 Christopher White and contributors. This program is free software; you can redistribute it and/or modify it under the terms of the the Apache License (2.0). You may obtain a @@ -338,5 +338,6 @@ See the License for the specific language governing permissions and limitations under the License. =cut + # }}}1 # vi: set fdm=marker: diff --git a/t/MY/Class/TypeTinyHashref.pm b/t/MY/Class/TypeTinyHashref.pm index adfdf17..5f40557 100644 --- a/t/MY/Class/TypeTinyHashref.pm +++ b/t/MY/Class/TypeTinyHashref.pm @@ -12,7 +12,7 @@ use vars::i '$MediumInteger' => Type::Tiny->new( constraint => sub { looks_like_number($_) and $_ >= 10 and $_ < 20 } ); -# Pass constraints in form of a hashref +# Pass constraints in a hashref use Class::Tiny::ConstrainedAccessor { medint => $MediumInteger, # create accessor sub medint() med_with_default => $MediumInteger,