Skip to content

Commit

Permalink
improvements to Type::Tiny::Manual::Coercions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyink committed Jul 5, 2018
1 parent 954b810 commit 5861b35
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/Type/Tiny/Manual/Coercions.pod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Type::Tiny::Manual::Coercions - adding coercions to type constraints
B<< Stop! Don't do it! >>

OK, it's fairly common practice in L<Moose>/L<Mouse> code to define
coercions for type constraints. For example, suppose we have a type
constraint:
coercions for type constraints. For example, suppose we define a type
constraint in a type library:

class_type PathTiny, { class => "Path::Tiny" };

Expand Down Expand Up @@ -54,12 +54,12 @@ L<Type::Tiny> offers a method C<plus_coercions> which constructs a new
anonymous type constraint, but with additional coercions.

In our earlier example, we'd define the C<PathTiny> type constraint
as before:
in our type library as before:

class_type PathTiny, { class => "Path::Tiny" };

But then not define any coercions for it. Later, when using the
type constraint, we can add coercions:
type constraint in a class, we can add coercions:

my $ConfigFileType = PathTiny->plus_coercions(
Str, sub { "Path::Tiny"->new($_) },
Expand Down Expand Up @@ -181,6 +181,10 @@ C<Tuple>

=item *

C<CycleTuple>

=item *

C<Dict>

=item *
Expand Down Expand Up @@ -344,7 +348,7 @@ coercion. This makes the type's coercions immutable. If anybody wants
to define any additional coercions, they'll have to create a child type
to do it with.

A shortcut exists for this:
A shortcut exists to do this on all types in your library:

__PACKAGE__->meta->make_immutable;

Expand Down

0 comments on commit 5861b35

Please sign in to comment.