/usr/share/perl5/Type/Tiny/Manual/UsingWithMoose.pod is in libtype-tiny-perl 1.000005-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | =pod
=encoding utf-8
=head1 NAME
Type::Tiny::Manual::UsingWithMoose - how to use Type::Tiny and Type::Library with Moose
=head1 SYNOPSIS
{
package Person;
use Moose;
use Types::Standard qw( Str Int );
use Type::Utils qw( declare as where inline_as coerce from );
has name => (
is => "ro",
isa => Str,
);
my $PositiveInt = declare
as Int,
where { $_ > 0 },
inline_as { "$_ =~ /^[0-9]+\$/ and $_ > 0" };
coerce $PositiveInt, from Int, q{ abs $_ };
has age => (
is => "ro",
isa => $PositiveInt,
coerce => 1,
writer => "_set_age",
);
sub get_older {
my $self = shift;
my ($years) = @_;
$PositiveInt->assert_valid($years);
$self->_set_age($self->age + $years);
}
}
=head1 DESCRIPTION
L<Type::Tiny> type constraints have an API almost identical to that of
L<Moose::Meta::TypeConstraint>. It is also able to build a
Moose::Meta::TypeConstraint constraint from a Type::Tiny constraint, and
will do so automatically when needed. When Moose.pm is loaded, Type::Tiny
will use Perl's C<AUTOLOAD> feature to proxy method calls through to the
Moose::Meta::TypeConstraint object. In short, you can use a Type::Tiny
object pretty much anywhere you'd use a Moose::Meta::TypeConstraint and
you are unlikely to notice the difference.
=head2 Per-Attribute Coercions
Type::Tiny offers convenience methods to alter the list of coercions
associated with a type constraint. Let's imagine we wish to allow our
C<name> attribute to be coerced from an arrayref of strings.
has name => (
is => "ro",
isa => Str->plus_coercions(
ArrayRef[Str], sub { join " ", @{$_} },
),
coerce => 1,
);
This coercion will apply to the C<name> attribute only; other attributes
using the C<Str> type constraint will be unaffected.
See the documentation for C<plus_coercions>, C<minus_coercions> and
C<no_coercions> in L<Type::Tiny>.
=head2 Optimization
The usual advice for optimizing type constraints applies: use type constraints
which can be inlined whenever possible.
Defining coercions as strings rather than coderefs won't give you as much of
a boost with Moose as it does with Moo, because Moose doesn't inline coercion
code. However, it should still improve performance somewhat because it allows
L<Type::Coercion> to do some internal inlining.
See also L<Type::Tiny::Manual::Optimization>.
=head2 Interactions with MooseX-Types
Type::Tiny and MooseX::Types type constraints should "play nice". If, for
example, C<ArrayRef> is taken from L<Types::Standard> (i.e. a Type::Tiny-based
type library), and C<PositiveInt> is taken from L<MooseX::Types::Common::Numeric>,
then the following should "just work":
isa => ArrayRef[ PositiveInt ]
isa => PositiveInt | ArrayRef
=head1 SEE ALSO
For examples using Type::Tiny with L<Moose> see the SYNOPSIS sections of
L<Type::Tiny> and L<Type::Library>, and the
L<Moose integration tests|https://github.com/tobyink/p5-type-tiny/tree/master/t/30-integration/Moose>,
and
L<MooseX-Types integration tests|https://github.com/tobyink/p5-type-tiny/tree/master/t/30-integration/MooseX-Types>
in the test suite.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
This software is copyright (c) 2013-2014 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.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut
|