This file is indexed.

/usr/share/perl5/Type/Tiny/Manual/Params.pod is in libtype-tiny-perl 1.002001-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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
=pod

=encoding utf-8

=head1 NAME

Type::Tiny::Manual::Params - coerce and validate arguments to functions and methods

=head1 DESCRIPTION

There is a module called L<Type::Params> available to wrap up type coercion
and constraint checks into a single, simple and fast check. If you care
about speed, and your sub signatures are fairly simple, then this is the way
to go...

   use feature qw( state );
   use Types::Standard qw( Str );
   use Type::Utils;
   use Type::Params qw( compile );
   
   my $Invocant = class_type { class => __PACKAGE__ };
   
   sub set_name
   {
      state $check = compile($Invocant, Str);
      my ($self, $name) = $check->(@_);
      
      ...;
   }

See the COOKBOOK section of L<Type::Params> for further information.

=head2 The Somewhat More Manual Way...

In general, Type::Params should be sufficient to cover most needs, and
will probably run faster than almost anything you could cook up yourself.
However, sometimes you need to deal with unusual function signatures that
it does not support. For example, imagine function C<< format_string >>
takes an optional hashref of formatting instructions, followed by a
required string. You might expect to be able to handle it like this:

   sub format_string
   {
      state $check = compile(Optional[HashRef], Str);
      my ($instructions, $string) = $check->(@_);
      
      ...;
   }

However, this won't work, as Type::Params expects required parameters to
always precede optional ones. So there are times you need to handle
parameters more manually.

In these cases, bear in mind that for any type constraint object you
have several useful checking methods available:

  Str->check($var)            # returns a boolean
  is_Str($var)                # ditto
  Str->($var)                 # returns $var or dies
  assert_Str($var)            # ditto

Here's how you might handle the C<format_string> function:

   sub format_string
   {
      my $instructions;
      $instructions = shift if HashRef->check($_[0]);
      
      my $string = Str->(shift);
      
      ...;
   }

Alternatively, you could manipulate @_ before passing it to the compiled
check:

   sub format_string
   {
      state $check = compile(HashRef, Str);
      my ($instructions, $str) = $check->(@_==1 ? ({}, @_) : @_);
      
      ...;
   }

=head2 Signatures

Don't you wish your subs could look like this?

   sub set_name (Object $self, Str $name)
   {
      $self->{name} = $name;
   }

Well; here are a few solutions for sub signatures that work with
L<Type::Tiny>...

=head3 Kavorka

L<Kavorka> is a sub signatures implementation written to natively use
L<Type::Utils>' C<dwim_type> for type constraints, and take advantage
of Type::Tiny's features such as inlining, and coercions.

   method set_name (Str $name)
   {
      $self->{name} = $name;
   }

Kavorka's signatures provide a lot more flexibility, and slightly more
speed than Type::Params. (The speed comes from inlining almost all type
checks into the body of the sub being declared.)

Kavorka also includes support for type checking of the returned value.

Kavorka can also be used as part of L<Moops>, a larger framework for
object oriented programming in Perl.

=head3 Function::Parameters

The following should work with L<Function::Parameters> 1.0201 or above:

   use Type::Utils;
   use Function::Parameters {
      method => {
         strict     => 1,
         reify_type => sub { Type::Utils::dwim_type($_[0]) },
      },
   };
   
   method set_name (Str $name)
   {
      $self->{name} = $name;
   }

Note that by default, Function::Parameters uses Moose's type
constraints. The C<reify_type> option above (introduced in
Function::Parameters 1.0201) allows you to "divert" type constraint
lookups. Using Type::Tiny constraints will gain you about a 7%
speed-up in function signature checks.

An alternative way to use Function::Parameter with Type::Tiny is to
provide type constraint expressions in parentheses:

   use Types::Standard;
   use Function::Parameters ':strict';
   
   method set_name ((Str) $name)
   {
      $self->{name} = $name;
   }

=head3 Attribute::Contract

Both Kavorka and Function::Parameters require a relatively recent
version of Perl. L<Attribute::Contract> supports older versions by
using a lot less magic.

You want Attribute::Contract 0.03 or above.

   use Attribute::Contract -types => [qw/Object Str/];
   
   sub set_name :ContractRequires(Object, Str)
   {
      my ($self, $name) = @_;
      $self->{name} = $name;
   }

Attribute::Contract also includes support for type checking of the
returned value.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014, 2017 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