| 1 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package Gentoo::PerlMod::Version::Error; | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.8.0'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Various error message and diagnostic bits. | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 4 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | BEGIN { | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | for my $env (qw( opts hasopt getopt )) { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 16 | my $code = sub { | ||||||||||||||||||||||||||||||||
| 17 | 18 | ▶ | require Gentoo::PerlMod::Version::Env; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 18 | my $sub = Gentoo::PerlMod::Version::Env->can($env); | |||||||||||||||||||||||||||||||
| 19 | 18 | goto $sub; | |||||||||||||||||||||||||||||||
| 20 | 12 | }; | |||||||||||||||||||||||||||||||
| 21 | ## no critic ( ProhibitNoStrict ) | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 12 | *{ __PACKAGE__ . '::_env_' . $env } = $code; | |||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | sub perlver_undefined { | ||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | my ($config) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
perlver_undefined: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 39 | ## no critic ( RequireInterpolationOfMetachars ) | ||||||||||||||||||||||||||||||||
| 40 | 2 | 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 | 3 | ▶ | my ( $perlver, $config, ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
matches_trial_regex_nonlax: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 3 | 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 | 3 | ▶ | my ( $perlver, $config ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
not_decimal_or_trial: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 77 | 3 | 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 | 2 | ▶ | my ( $char, $char_ord ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
bad_char: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 97 | 2 | 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 | 2 | ▶ | my ($version) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
lax_multi_underscore: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 114 | 2 | 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 | 9 | ▶ | my ($conf) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_format_error: called CC=11 SCAR=27.8
| |||||||||||||||||||||||||||||||||
| 134 | 9 | my $message = $conf->{message}; | |||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | if ( exists $conf->{want_lax} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | 4 | my $lax = $conf->{want_lax}; | |||||||||||||||||||||||||||||||
| 137 | 4 | $message .= qq{\n Set { lax => $lax } for more permissive behaviour. }; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | 9 | ▶ | if ( _env_hasopt('taint_safe') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 140 | 0 | return $message; | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | 9 | ▶ | if ( _env_hasopt('carp_debug') ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 0 | $conf->{env_config} = _env_opts; | |||||||||||||||||||||||||||||||
| 144 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||
| 145 | 0 | local $Data::Dumper::Indent = 2; | |||||||||||||||||||||||||||||||
| 146 | 0 | local $Data::Dumper::Purity = 0; | |||||||||||||||||||||||||||||||
| 147 | 0 | local $Data::Dumper::Useqq = 1; | |||||||||||||||||||||||||||||||
| 148 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||||||
| 149 | 0 | local $Data::Dumper::Quotekeys = 0; | |||||||||||||||||||||||||||||||
| 150 | 0 | return Data::Dumper::Dumper($conf); | |||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | 9 | ▶ | if ( exists $conf->{'message_extra_tainted'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 7 | $message .= $conf->{'message_extra_tainted'}; | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | 9 | ▶ | if ( exists $conf->{'stack'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 156 | 9 | for ( @{ $conf->{stack} } ) { | |||||||||||||||||||||||||||||||
| 157 | 28 | ▶ | if ( $_->[0] !~ /\AGentoo::PerlMod::Version(?:|::Error|::Env)\z/msx ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 158 | 9 | ▶ | $message .= sprintf qq[\n - From %s in %s at line %s\n], $_->[0] || q[], $_->[1] || q[], $_->[2] || q[]; | ||||||||||||||||||||||||||||||
|
Condition50%3/6
$_->[0] || ''
$_->[1] || ''
$_->[2] || ''
MC/DC0%0/1
$_->[0] || ''
$_->[0]
MC/DC0%0/1
$_->[1] || ''
$_->[1]
MC/DC0%0/1
$_->[2] || ''
$_->[2]
Truth table50%1/2
A
A= $_->[0]
Truth table50%1/2
A
A= $_->[1]
Truth table50%1/2
A
A= $_->[2]
| |||||||||||||||||||||||||||||||||
| 159 | 9 | last; | |||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | 9 | return $message; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 4 | ▶ | use overload q[""] => \&_format_error; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | sub _fatal { | ||||||||||||||||||||||||||||||||
| 169 | 7 | ▶ | my ($conf) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_fatal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 170 | 7 | require Carp; | |||||||||||||||||||||||||||||||
| 171 | $conf->{stack} = [ | ||||||||||||||||||||||||||||||||
| 172 | 77 | map { [ $_->[0], $_->[1], $_->[2], ] } | |||||||||||||||||||||||||||||||
| 173 | 7 | map { [ caller $_, ] } 0 .. 10, | |||||||||||||||||||||||||||||||
| 174 | ]; | ||||||||||||||||||||||||||||||||
| 175 | 7 | return Carp::croak( bless $conf, __PACKAGE__ ); | |||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 4 | 1; | |||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | __END__ | ||||||||||||||||||||||||||||||||