File Coverage

blib/lib/Error/TypeTiny/WrongNumberOfParameters.pm
Criterion Covered Total %
statement 21 21 100.0
branch 6 6 100.0
condition 12 12 100.0
subroutine 10 10 100.0
pod 5 5 100.0
total 54 54 100.0


line stmt bran cond sub pod time code
1             package Error::TypeTiny::WrongNumberOfParameters;
2              
3 57     57   1926 use 5.008001;
  57         213  
4 57     57   365 use strict;
  57         129  
  57         1309  
5 57     57   344 use warnings;
  57         145  
  57         2733  
6              
7             BEGIN {
8 57     57   235 $Error::TypeTiny::WrongNumberOfParameters::AUTHORITY = 'cpan:TOBYINK';
9 57         17346 $Error::TypeTiny::WrongNumberOfParameters::VERSION = '2.003_000';
10             }
11              
12             $Error::TypeTiny::WrongNumberOfParameters::VERSION =~ tr/_//d;
13              
14             require Error::TypeTiny;
15             our @ISA = 'Error::TypeTiny';
16              
17 83     83 1 323 sub minimum { $_[0]{minimum} }
18 61     61 1 273 sub maximum { $_[0]{maximum} }
19 64     64 1 310 sub got { $_[0]{got} }
20              
21 134     134 1 634 sub has_minimum { exists $_[0]{minimum} }
22 55     55 1 291 sub has_maximum { exists $_[0]{maximum} }
23              
24             sub _build_message {
25 59     59   124 my $e = shift;
26 59 100 100     154 if ( $e->has_minimum and $e->has_maximum and $e->minimum == $e->maximum ) {
    100 100        
    100 100        
      100        
27 18         63 return sprintf(
28             "Wrong number of parameters; got %d; expected %d",
29             $e->got,
30             $e->minimum,
31             );
32             }
33             elsif ( $e->has_minimum and $e->has_maximum and $e->minimum < $e->maximum ) {
34 12         30 return sprintf(
35             "Wrong number of parameters; got %d; expected %d to %d",
36             $e->got,
37             $e->minimum,
38             $e->maximum,
39             );
40             }
41             elsif ( $e->has_minimum ) {
42 4         14 return sprintf(
43             "Wrong number of parameters; got %d; expected at least %d",
44             $e->got,
45             $e->minimum,
46             );
47             }
48             else {
49 25         68 return sprintf(
50             "Wrong number of parameters; got %d",
51             $e->got,
52             );
53             }
54             } #/ sub _build_message
55              
56             1;
57              
58             __END__
59              
60             =pod
61              
62             =encoding utf-8
63              
64             =head1 NAME
65              
66             Error::TypeTiny::WrongNumberOfParameters - exception for Type::Params
67              
68             =head1 STATUS
69              
70             This module is covered by the
71             L<Type-Tiny stability policy|Type::Tiny::Manual::Policies/"STABILITY">.
72              
73             =head1 DESCRIPTION
74              
75             Thrown when a Type::Params compiled check is called with the wrong number
76             of parameters.
77              
78             This package inherits from L<Error::TypeTiny>; see that for most
79             documentation. Major differences are listed below:
80              
81             =head2 Attributes
82              
83             =over
84              
85             =item C<minimum>
86              
87             The minimum expected number of parameters.
88              
89             =item C<maximum>
90              
91             The maximum expected number of parameters.
92              
93             =item C<got>
94              
95             The number of parameters actually passed to the compiled check.
96              
97             =back
98              
99             =head2 Methods
100              
101             =over
102              
103             =item C<has_minimum>, C<has_maximum>
104              
105             Predicate methods.
106              
107             =back
108              
109             =head1 BUGS
110              
111             Please report any bugs to
112             L<https://github.com/tobyink/p5-type-tiny/issues>.
113              
114             =head1 SEE ALSO
115              
116             L<Error::TypeTiny>.
117              
118             =head1 AUTHOR
119              
120             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
121              
122             =head1 COPYRIGHT AND LICENCE
123              
124             This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =head1 DISCLAIMER OF WARRANTIES
130              
131             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
132             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
133             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.