Skip to content

Commit

Permalink
documentation of recursive type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyink committed Feb 4, 2020
1 parent 9b49e9b commit c249761
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/Type/Tiny/Manual/Libraries.pod
Expand Up @@ -334,6 +334,27 @@ Even if you provide a coderef as a string, an inlining coderef has the
potential to generate more efficient code, so you should consider
providing one.

=head2 Pre-Declaring Types

use Type::Library -base,
-declare => qw( Foo Bar Baz );

This declares types B<Foo>, B<Bar>, and B<Baz> at compile time so they can
safely be used as barewords in your type library.

This also allows recursively defined types to (mostly) work!

use Type::Library -base,
-declare => qw( NumericArrayRef );
use Types::Standard qw( Num ArrayRef );

__PACKAGE__->add_type(
name => NumericArrayRef,
parent => ArrayRef->of( Int | NumericArrayRef ),
);

(Support for recursive type definitions added in Type::Library 1.009_000.)

=head2 Parameterizable Types

This is probably the most "meta" concept that is going to be covered.
Expand Down
21 changes: 21 additions & 0 deletions t/20-unit/Type-Library/recursive-type-definitions.t
@@ -1,3 +1,24 @@
=pod
=encoding utf-8
=head1 PURPOSE
Tests that types may be defined recursively.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2020 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

use strict;
use warnings;
use Test::More;
Expand Down

0 comments on commit c249761

Please sign in to comment.