blib/lib/Gentoo/PerlMod/Version/Error.pm untested

filter: Statementstmt 0.0% 0 / 80 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 122 SCAR 40.3
CC
7
Cov
0%
_format_error
56.0
BEGIN
2.0
perlver_undefined
2.0
CRAP 56.0
1 use 5.006;
2 use strict;
3 use warnings;
4  
5 package Gentoo::PerlMod::Version::Error;
6  
7 our $VERSION = '0.8.0';
8  
9 # ABSTRACT: Various error message and diagnostic bits.
10  
11 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 BEGIN {
14  
15 for my $env (qw( opts hasopt getopt )) {
16 my $code = sub {
17 require Gentoo::PerlMod::Version::Env;
18 my $sub = Gentoo::PerlMod::Version::Env->can($env);
19 goto $sub;
20 };
21 ## no critic ( ProhibitNoStrict )
22  
23 no strict 'refs';
24 *{ __PACKAGE__ . '::_env_' . $env } = $code;
25 }
26  
27 }
28  
29  
30  
31  
32  
33  
34  
35  
36  
37 sub perlver_undefined {
38 my ($config) = @_;
39 ## no critic ( RequireInterpolationOfMetachars )
40 return _fatal(
41 {
42 code => 'perlver_undefined',
43 config => $config,
44 message => 'Argument \'$perlver\' to gentooize_version was undefined',
45 },
46 );
47 }
48  
49  
50  
51  
52  
53  
54  
55 sub matches_trial_regex_nonlax {
56 my ( $perlver, $config, ) = @_;
57 return _fatal(
58 {
59 code => 'matches_trial_regex_nonlax',
60 config => $config,
61 want_lax => 1,
62 message => 'Invalid version format (non-numeric data, either _ or -TRIAL ).',
63 message_extra_tainted => qq{ Version: >$perlver< },
64 version => $perlver,
65 },
66 );
67 }
68  
69  
70  
71  
72  
73  
74  
75 sub not_decimal_or_trial {
76 my ( $perlver, $config ) = @_;
77 return _fatal(
78 {
79 code => 'not_decimal_or_trial',
80 config => $config,
81 want_lax => 2,
82 message => 'Invalid version format (non-numeric/ASCII data).',
83 message_extra_tainted => qq{ Version: >$perlver< },
84 version => $perlver,
85 },
86 );
87 }
88  
89  
90  
91  
92  
93  
94  
95 sub bad_char {
96 my ( $char, $char_ord ) = @_;
97 return _fatal(
98 {
99 code => 'bad_char',
100 message => 'A Character in the version is not in the ascii-to-int translation table.',
101 message_extra_tainted => qq{ Missing character: $char ( $char_ord )},
102 },
103 );
104 }
105  
106  
107  
108  
109  
110  
111  
112 sub lax_multi_underscore {
113 my ($version) = @_;
114 return _fatal(
115 {
116 code => 'lax_multi_underscore',
117 message => q{More than one _ in a version is not permitted},
118 message_extra_tainted => qq{ Version: >$version< },
119 version => $version,
120 },
121 );
122 }
123 #
124 # _format_error({
125 # code => "some_string",
126 # message => "Some message"
127 # message_extra_tainted => "And $tainted " # extra data for non-taint-safe envs.
128 # want_lax => n # optional
129 # })
130 #
131  
132 sub _format_error {
133 my ($conf) = @_;
134 my $message = $conf->{message};
135 if ( exists $conf->{want_lax} ) {
136 my $lax = $conf->{want_lax};
137 $message .= qq{\n Set { lax => $lax } for more permissive behaviour. };
138 }
139 if ( _env_hasopt('taint_safe') ) {
140 return $message;
141 }
142 if ( _env_hasopt('carp_debug') ) {
143 $conf->{env_config} = _env_opts;
144 require Data::Dumper;
145 local $Data::Dumper::Indent = 2;
146 local $Data::Dumper::Purity = 0;
147 local $Data::Dumper::Useqq = 1;
148 local $Data::Dumper::Terse = 1;
149 local $Data::Dumper::Quotekeys = 0;
150 return Data::Dumper::Dumper($conf);
151 }
152 if ( exists $conf->{'message_extra_tainted'} ) {
153 $message .= $conf->{'message_extra_tainted'};
154 }
155 if ( exists $conf->{'stack'} ) {
156 for ( @{ $conf->{stack} } ) {
157 if ( $_->[0] !~ /\AGentoo::PerlMod::Version(?:|::Error|::Env)\z/msx ) {
158 $message .= sprintf qq[\n - From %s in %s at line %s\n], $_->[0] || q[], $_->[1] || q[], $_->[2] || q[];
159 last;
160 }
161 }
162 }
163 return $message;
164 }
165  
166 use overload q[""] => \&_format_error;
167  
168 sub _fatal {
169 my ($conf) = @_;
170 require Carp;
171 $conf->{stack} = [
172 map { [ $_->[0], $_->[1], $_->[2], ] }
173 map { [ caller $_, ] } 0 .. 10,
174 ];
175 return Carp::croak( bless $conf, __PACKAGE__ );
176 }
177  
178 1;
179  
180 __END__