From 335df2b414da070c1937115acc58a76c93b96f42 Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 12 Apr 2019 22:00:26 -0400 Subject: [PATCH] Added documentation link to C::T::ConstrainedAccessor Fixes #27 --- lib/Class/Tiny.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Class/Tiny.pm b/lib/Class/Tiny.pm index 18b7ec1..dc31a91 100644 --- a/lib/Class/Tiny.pm +++ b/lib/Class/Tiny.pm @@ -31,7 +31,7 @@ sub prepare_class { sub create_attributes { my ( $class, $pkg, @spec ) = @_; my %defaults = map { ref $_ eq 'HASH' ? %$_ : ( $_ => undef ) } @spec; - my @attr = grep { + my @attr = grep { defined and !ref and /^[^\W\d]\w*$/s or Carp::croak "Invalid accessor name '$_'" } keys %defaults; @@ -140,7 +140,7 @@ my $_PRECACHE = sub { }; sub new { - my $class = shift; + my $class = shift; my $valid_attrs = $ATTR_CACHE{$class} || $_PRECACHE->($class); # handle hash ref or key/value arguments @@ -458,6 +458,18 @@ and various subroutine references are cached for speed. Ensure that all inheritance and methods are in place before creating objects. (You don't want to be changing that once you create objects anyway, right?) +=head2 Type constraints (C relationships) + +Class::Tiny does not natively apply type constraints to any attributes. +For example, there is no equivalent of the Moose C (e.g., +C<< has 'birth_date' => ( isa => 'DateTime'); >>). You can apply constraints +manually by providing custom accessors (see L). + +One shortcut is separately-distributed package +L. This package can create a custom accessor +that will apply a L, L, L, +L, or L type constraint. + =head1 RATIONALE =head2 Why this instead of Object::Tiny or Class::Accessor or something else?