« blib/lib/Perl/Critic/Policy.pm
↑ Summary
blib/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitVoidGrep.pm »
| 1 | package Perl::Critic::Exception::AggregateConfiguration; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 40 | ▶ | use Carp qw{ confess }; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 40 | ▶ | use Readonly; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 40 | ▶ | use Perl::Critic::Utils qw{ :characters }; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 40 | our $VERSION = '1.150'; | |||||||||||||
| 13 | |||||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||||
| 15 | |||||||||||||||
| 16 | use Exception::Class ( | ||||||||||||||
| 17 | 40 | 'Perl::Critic::Exception::AggregateConfiguration' => { | |||||||||||||
| 18 | isa => 'Perl::Critic::Exception', | ||||||||||||||
| 19 | description => 'A collected set of configuration exceptions.', | ||||||||||||||
| 20 | fields => [ qw{ exceptions } ], | ||||||||||||||
| 21 | alias => 'throw_aggregate', | ||||||||||||||
| 22 | }, | ||||||||||||||
| 23 | 40 | ▶ | ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 40 | Readonly::Array our @EXPORT_OK => qw< throw_aggregate >; | |||||||||||||
| 28 | |||||||||||||||
| 29 | #----------------------------------------------------------------------------- | ||||||||||||||
| 30 | |||||||||||||||
| 31 | sub new { | ||||||||||||||
| 32 | 38729 | ▶ | my ($class, %options) = @_; | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 33 | |||||||||||||||
| 34 | 38729 | my $exceptions = $options{exceptions}; | |||||||||||||
| 35 | 38729 | ▶ | if (not $exceptions) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 38729 | $options{exceptions} = []; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 38729 | return $class->SUPER::new(%options); | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | #----------------------------------------------------------------------------- | ||||||||||||||
| 43 | |||||||||||||||
| 44 | sub add_exception { | ||||||||||||||
| 45 | 164 | ▶ | my ( $self, $exception ) = @_; | ||||||||||||
|
Subroutine
add_exception: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 46 | |||||||||||||||
| 47 | 164 | push @{ $self->exceptions() }, $exception; | |||||||||||||
| 48 | |||||||||||||||
| 49 | 164 | return; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | #----------------------------------------------------------------------------- | ||||||||||||||
| 53 | |||||||||||||||
| 54 | sub add_exceptions_from { | ||||||||||||||
| 55 | 1 | ▶ | my ( $self, $aggregate ) = @_; | ||||||||||||
|
Subroutine
add_exceptions_from: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | 1 | push @{ $self->exceptions() }, @{ $aggregate->exceptions() }; | |||||||||||||
| 58 | |||||||||||||||
| 59 | 1 | return; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | #----------------------------------------------------------------------------- | ||||||||||||||
| 63 | |||||||||||||||
| 64 | sub add_exception_or_rethrow { | ||||||||||||||
| 65 | 21744 | ▶ | my ( $self, $eval_error ) = @_; | ||||||||||||
|
Subroutine
add_exception_or_rethrow: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 21744 | ▶ | return if not $eval_error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 2 | ▶ | confess $eval_error if not ref $eval_error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | |||||||||||||||
| 70 | 2 | ▶ | if ( $eval_error->isa('Perl::Critic::Exception::Configuration') ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | 1 | $self->add_exception($eval_error); | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | elsif ( | ||||||||||||||
| 74 | $eval_error->isa('Perl::Critic::Exception::AggregateConfiguration') | ||||||||||||||
| 75 | ) { | ||||||||||||||
| 76 | 1 | $self->add_exceptions_from($eval_error); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | else { | ||||||||||||||
| 79 | 0 | die $eval_error; ## no critic (RequireCarping) | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 2 | return; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | #----------------------------------------------------------------------------- | ||||||||||||||
| 86 | |||||||||||||||
| 87 | sub has_exceptions { | ||||||||||||||
| 88 | 39336 | ▶ | my ( $self ) = @_; | ||||||||||||
|
Subroutine
has_exceptions: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 89 | |||||||||||||||
| 90 | 39336 | ▶ | return @{ $self->exceptions() } ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | #----------------------------------------------------------------------------- | ||||||||||||||
| 94 | |||||||||||||||
| 95 | 40 | Readonly::Scalar my $MESSAGE_PREFIX => $EMPTY; | |||||||||||||
| 96 | 40 | Readonly::Scalar my $MESSAGE_SUFFIX => "\n"; | |||||||||||||
| 97 | 40 | Readonly::Scalar my $MESSAGE_SEPARATOR => $MESSAGE_SUFFIX . $MESSAGE_PREFIX; | |||||||||||||
| 98 | |||||||||||||||
| 99 | sub full_message { | ||||||||||||||
| 100 | 150 | ▶ | my ( $self ) = @_; | ||||||||||||
|
Subroutine
full_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 101 | |||||||||||||||
| 102 | 150 | my $message = $MESSAGE_PREFIX; | |||||||||||||
| 103 | 150 | $message .= join $MESSAGE_SEPARATOR, @{ $self->exceptions() }; | |||||||||||||
| 104 | 150 | $message .= $MESSAGE_SUFFIX; | |||||||||||||
| 105 | |||||||||||||||
| 106 | 150 | return $message; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | |||||||||||||||
| 109 | 40 | 1; | |||||||||||||
| 110 | |||||||||||||||
| 111 | #----------------------------------------------------------------------------- | ||||||||||||||
| 112 | |||||||||||||||
| 113 | __END__ | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =pod | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =for stopwords | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head1 NAME | ||||||||||||||
| 120 | |||||||||||||||
| 121 | Perl::Critic::Exception::AggregateConfiguration - A collection of a set of problems found in the configuration and/or command-line options. | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =head1 DESCRIPTION | ||||||||||||||
| 124 | |||||||||||||||
| 125 | A set of configuration settings can have multiple problems. This is | ||||||||||||||
| 126 | an object for collecting all the problems found so that the user can | ||||||||||||||
| 127 | see them in one run. | ||||||||||||||
| 128 | |||||||||||||||
| 129 | |||||||||||||||
| 130 | =head1 INTERFACE SUPPORT | ||||||||||||||
| 131 | |||||||||||||||
| 132 | This is considered to be a public class. Any changes to its interface | ||||||||||||||
| 133 | will go through a deprecation cycle. | ||||||||||||||
| 134 | |||||||||||||||
| 135 | |||||||||||||||
| 136 | =head1 METHODS | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =over | ||||||||||||||
| 139 | |||||||||||||||
| 140 | =item C<add_exception( $exception )> | ||||||||||||||
| 141 | |||||||||||||||
| 142 | Accumulate the parameter with rest of the exceptions. | ||||||||||||||
| 143 | |||||||||||||||
| 144 | |||||||||||||||
| 145 | =item C<add_exceptions_from( $aggregate )> | ||||||||||||||
| 146 | |||||||||||||||
| 147 | Accumulate the exceptions from another instance of this class. | ||||||||||||||
| 148 | |||||||||||||||
| 149 | |||||||||||||||
| 150 | =item C<exceptions()> | ||||||||||||||
| 151 | |||||||||||||||
| 152 | Returns a reference to an array of the collected exceptions. | ||||||||||||||
| 153 | |||||||||||||||
| 154 | |||||||||||||||
| 155 | =item C<add_exception_or_rethrow( $eval_error )> | ||||||||||||||
| 156 | |||||||||||||||
| 157 | If the parameter is an instance of | ||||||||||||||
| 158 | L<Perl::Critic::Exception::Configuration|Perl::Critic::Exception::Configuration> | ||||||||||||||
| 159 | or | ||||||||||||||
| 160 | L<Perl::Critic::Exception::AggregateConfiguration|Perl::Critic::Exception::AggregateConfiguration>, | ||||||||||||||
| 161 | add it. Otherwise, C<die> with the parameter, if it is a reference, | ||||||||||||||
| 162 | or C<confess> with it. If the parameter is false, simply returns. | ||||||||||||||
| 163 | |||||||||||||||
| 164 | |||||||||||||||
| 165 | =item C<has_exceptions()> | ||||||||||||||
| 166 | |||||||||||||||
| 167 | Answer whether any configuration problems have been found. | ||||||||||||||
| 168 | |||||||||||||||
| 169 | |||||||||||||||
| 170 | =item C<full_message()> | ||||||||||||||
| 171 | |||||||||||||||
| 172 | Concatenate the exception messages. See | ||||||||||||||
| 173 | L<Exception::Class/"full_message">. | ||||||||||||||
| 174 | |||||||||||||||
| 175 | |||||||||||||||
| 176 | =back | ||||||||||||||
| 177 | |||||||||||||||
| 178 | |||||||||||||||
| 179 | =head1 AUTHOR | ||||||||||||||
| 180 | |||||||||||||||
| 181 | Elliot Shank <perl@galumph.com> | ||||||||||||||
| 182 | |||||||||||||||
| 183 | =head1 COPYRIGHT | ||||||||||||||
| 184 | |||||||||||||||
| 185 | Copyright (c) 2007-2023 Elliot Shank | ||||||||||||||
| 186 | |||||||||||||||
| 187 | This program is free software; you can redistribute it and/or modify | ||||||||||||||
| 188 | it under the same terms as Perl itself. The full text of this license | ||||||||||||||
| 189 | can be found in the LICENSE file included with this module. | ||||||||||||||
| 190 | |||||||||||||||
| 191 | =cut | ||||||||||||||
| 192 | |||||||||||||||
| 193 | ############################################################################## | ||||||||||||||
| 194 | # Local Variables: | ||||||||||||||
| 195 | # mode: cperl | ||||||||||||||
| 196 | # cperl-indent-level: 4 | ||||||||||||||
| 197 | # fill-column: 78 | ||||||||||||||
| 198 | # indent-tabs-mode: nil | ||||||||||||||
| 199 | # c-indentation-style: bsd | ||||||||||||||
| 200 | # End: | ||||||||||||||
| 201 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||||||