• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tobyink / p5-type-tiny / 2ebf471f5

19 Mar 2025 06:41PM UTC coverage: 99.603% (-0.08%) from 99.682%
2ebf471f5

push

github

3764 of 3779 relevant lines covered (99.6%)

29352.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/lib/Error/TypeTiny/WrongNumberOfParameters.pm
1
package Error::TypeTiny::WrongNumberOfParameters;
2

3
use 5.008001;
680✔
4
use strict;
680✔
5
use warnings;
680✔
6

7
BEGIN {
8
        $Error::TypeTiny::WrongNumberOfParameters::AUTHORITY = 'cpan:TOBYINK';
696✔
9
        $Error::TypeTiny::WrongNumberOfParameters::VERSION   = '2.008002';
696✔
10
}
11

12
$Error::TypeTiny::WrongNumberOfParameters::VERSION =~ tr/_//d;
13

14
require Error::TypeTiny;
15
our @ISA = 'Error::TypeTiny';
16

17
sub minimum { $_[0]{minimum} }
664✔
18
sub maximum { $_[0]{maximum} }
488✔
19
sub got     { $_[0]{got} }
512✔
20
sub target  { $_[0]{target} }
200✔
21

22
sub has_minimum { exists $_[0]{minimum} }
1,072✔
23
sub has_maximum { exists $_[0]{maximum} }
640✔
24
sub has_target  { exists $_[0]{target} }
472✔
25

26
sub _build_message {
27
        my $e = shift;
472✔
28
        
29
        my $base = 'Wrong number of parameters';
472✔
30
        if ( $e->has_target ) {
472✔
31
                $base .= sprintf( ' to %s', $e->target );
200✔
32
        }
33
        
34
        if ( $e->has_minimum and $e->has_maximum and $e->minimum == $e->maximum ) {
472✔
35
                return sprintf(
144✔
36
                        "%s; got %d; expected %d",
37
                        $base,
38
                        $e->got,
39
                        $e->minimum,
40
                );
41
        }
42
        elsif ( $e->has_minimum and $e->has_maximum and $e->minimum < $e->maximum ) {
43
                return sprintf(
96✔
44
                        "%s; got %d; expected %d to %d",
45
                        $base,
46
                        $e->got,
47
                        $e->minimum,
48
                        $e->maximum,
49
                );
50
        }
51
        elsif ( $e->has_minimum ) {
52
                return sprintf(
32✔
53
                        "%s; got %d; expected at least %d",
54
                        $base,
55
                        $e->got,
56
                        $e->minimum,
57
                );
58
        }
59
        elsif ( $e->has_maximum ) {
60
                return sprintf(
×
61
                        "%s; got %d; expected at most %d",
62
                        $base,
63
                        $e->got,
64
                        $e->maximum,
65
                );
66
        }
67
        else {
68
                return sprintf(
200✔
69
                        "%s; got %d",
70
                        $base,
71
                        $e->got,
72
                );
73
        }
74
} #/ sub _build_message
75

76
1;
77

78
__END__
79

80
=pod
81

82
=encoding utf-8
83

84
=head1 NAME
85

86
Error::TypeTiny::WrongNumberOfParameters - exception for Type::Params
87

88
=head1 STATUS
89

90
This module is covered by the
91
L<Type-Tiny stability policy|Type::Tiny::Manual::Policies/"STABILITY">.
92

93
=head1 DESCRIPTION
94

95
Thrown when a Type::Params compiled check is called with the wrong number
96
of parameters.
97

98
Also thrown by various parameterizable type constraints under similar
99
circumstances. For example, the C<< HashRef[Int] >> makes sense, but
100
C<< HashRef[Int, {}] >> does not.
101

102
This package inherits from L<Error::TypeTiny>; see that for most
103
documentation. Major differences are listed below:
104

105
=head2 Attributes
106

107
=over
108

109
=item C<minimum>
110

111
The minimum expected number of parameters.
112

113
=item C<maximum>
114

115
The maximum expected number of parameters.
116

117
=item C<got>
118

119
The number of parameters actually passed to the compiled check.
120

121
=item C<target>
122

123
A short string describing what there was the wrong number of parameters for.
124

125
=back
126

127
=head2 Methods
128

129
=over
130

131
=item C<has_minimum>, C<has_maximum>, C<has_target>
132

133
Predicate methods.
134

135
=back
136

137
=head1 BUGS
138

139
Please report any bugs to
140
L<https://github.com/tobyink/p5-type-tiny/issues>.
141

142
=head1 SEE ALSO
143

144
L<Error::TypeTiny>.
145

146
=head1 AUTHOR
147

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

150
=head1 COPYRIGHT AND LICENCE
151

152
This software is copyright (c) 2013-2014, 2017-2025 by Toby Inkster.
153

154
This is free software; you can redistribute it and/or modify it under
155
the same terms as the Perl 5 programming language system itself.
156

157
=head1 DISCLAIMER OF WARRANTIES
158

159
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
160
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
161
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc