diff options
author | Toby Inkster <mail@tobyinkster.co.uk> | 2023-04-02 15:30:15 +0100 |
---|---|---|
committer | Toby Inkster <mail@tobyinkster.co.uk> | 2023-04-02 15:30:15 +0100 |
commit | afe6954d887f8619fa7de1cb76103a6bd21bfaff (patch) | |
tree | 319140c487c12951da5dc7a20e4d0ec541928ea6 /lib/Type | |
parent | 2e8b3a28794b98d125828a30eafa429a2171c265 (diff) |
Improve Type::Tiny::Role docs; relates to issue #134
Diffstat (limited to 'lib/Type')
-rw-r--r-- | lib/Type/Tiny/Role.pm | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/Type/Tiny/Role.pm b/lib/Type/Tiny/Role.pm index d502bc7a..da015716 100644 --- a/lib/Type/Tiny/Role.pm +++ b/lib/Type/Tiny/Role.pm @@ -120,6 +120,91 @@ __END__ Type::Tiny::Role - type constraints based on the "DOES" method +=head1 SYNOPSIS + +Using via L<Types::Standard>: + + package Local::Horse { + use Moo; + use Types::Standard qw( Str ConsumerOf ); + + has name => ( + is => 'ro', + isa => Str, + ); + + has owner => ( + is => 'ro', + isa => ConsumerOf[ 'Local::Traits::DoesOwnership' ], + default => sub { Local::Person->new }, + ); + } + +Using Type::Tiny::Class's export feature: + + package Local::Horse { + use Moo; + use Types::Standard qw( Str ); + use Type::Tiny::Role ( + Owner => { role => 'Local::Traits::DoesOwnership' }, + ); + + has name => ( + is => 'ro', + isa => Str, + ); + + has owner => ( + is => 'ro', + isa => Owner, + default => sub { Local::Person->new }, + ); + } + +Using Type::Tiny::Role's object-oriented interface: + + package Local::Horse { + use Moo; + use Types::Standard qw( Str ); + use Type::Tiny::Class; + + my $Owner = Type::Tiny::Role->new( + role => 'Local::Traits::DoesOwnership', + ); + + has name => ( + is => 'ro', + isa => Str, + ); + + has owner => ( + is => 'ro', + isa => $Owner, + default => sub { Local::Person->new }, + ); + } + +Using Type::Utils's functional interface: + + package Local::Horse { + use Moo; + use Types::Standard qw( Str ); + use Type::Utils; + + my $Owner = role_type 'Local::Traits::DoesOwnership'; + + has name => ( + is => 'ro', + isa => Str, + ); + + has owner => ( + is => 'ro', + isa => $Owner, + default => sub { Local::Person->new }, + ); + } + =head1 STATUS This module is covered by the |